clean + add collection
parent
ed2063f705
commit
f1aaa1dfca
18
Types.py
18
Types.py
|
@ -21,6 +21,8 @@ class Types():
|
||||||
|
|
||||||
class CSHELF_OT_shelf_popup(Types, Operator):
|
class CSHELF_OT_shelf_popup(Types, Operator):
|
||||||
#props = None
|
#props = None
|
||||||
|
bl_options = {'REGISTER', 'UNDO'}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def props(self) :
|
def props(self) :
|
||||||
#print(getattr(bpy.context.window_manager.CustomShelf,self.prop))
|
#print(getattr(bpy.context.window_manager.CustomShelf,self.prop))
|
||||||
|
@ -31,12 +33,9 @@ class CSHELF_OT_shelf_popup(Types,Operator) :
|
||||||
#props =
|
#props =
|
||||||
return {k:v for k,v in self.args.items() if k in properties}
|
return {k:v for k,v in self.args.items() if k in properties}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def set_props(self,prop,value):
|
def set_props(self,prop,value):
|
||||||
setattr(bpy.context.window_manager.CustomShelf,prop,value)
|
setattr(bpy.context.window_manager.CustomShelf,prop,value)
|
||||||
|
|
||||||
|
|
||||||
def initialyse(self,label,info) :
|
def initialyse(self,label,info) :
|
||||||
super().initialyse(CSHELF_OT_shelf_popup,label)
|
super().initialyse(CSHELF_OT_shelf_popup,label)
|
||||||
|
|
||||||
|
@ -119,8 +118,6 @@ class CSHELF_OT_shelf_popup(Types,Operator) :
|
||||||
print(*args)
|
print(*args)
|
||||||
|
|
||||||
def execute(self,context):
|
def execute(self,context):
|
||||||
import tempfile
|
|
||||||
|
|
||||||
info, lines = read_info(self.script)
|
info, lines = read_info(self.script)
|
||||||
|
|
||||||
values = dict(info)
|
values = dict(info)
|
||||||
|
@ -136,16 +133,11 @@ class CSHELF_OT_shelf_popup(Types,Operator) :
|
||||||
else :
|
else :
|
||||||
values[arg] = value
|
values[arg] = value
|
||||||
|
|
||||||
|
|
||||||
info_str = "info = %s\n\n"%values
|
info_str = "info = %s\n\n"%values
|
||||||
|
lines_str = '\n'.join(lines)
|
||||||
|
script = f"{info_str}\n\n{lines_str}"
|
||||||
|
|
||||||
tmp_folder = tempfile.gettempdir()
|
exec(script, {'info': values, 'print': self.bl_report})
|
||||||
script_path = join(tmp_folder, "shelf.py")
|
|
||||||
|
|
||||||
with open(script_path,"w",encoding = 'utf-8') as f :
|
|
||||||
f.write(info_str+'\n'.join(lines))
|
|
||||||
|
|
||||||
exec(compile(open(script_path,encoding = 'utf-8').read(), script_path, 'exec'),{'info' : values,'print':self.bl_report})
|
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
39
__init__.py
39
__init__.py
|
@ -3,7 +3,7 @@ bl_info = {
|
||||||
"author": "Christophe Seux",
|
"author": "Christophe Seux",
|
||||||
"description": "Adds buttons to launch custom python scripts in the User panel.",
|
"description": "Adds buttons to launch custom python scripts in the User panel.",
|
||||||
"version": (0, 3, 2),
|
"version": (0, 3, 2),
|
||||||
"blender": (2, 82, 0),
|
"blender": (4, 0, 2),
|
||||||
"location": "View3D > User Panel",
|
"location": "View3D > User Panel",
|
||||||
"doc_url": "https://gitlab.com/autour-de-minuit/blender/custom_shelf/-/blob/main/README.md",
|
"doc_url": "https://gitlab.com/autour-de-minuit/blender/custom_shelf/-/blob/main/README.md",
|
||||||
"tracker_url": "https://gitlab.com/autour-de-minuit/blender/custom_shelf/-/issues",
|
"tracker_url": "https://gitlab.com/autour-de-minuit/blender/custom_shelf/-/issues",
|
||||||
|
@ -22,16 +22,15 @@ if "bpy" in locals():
|
||||||
from . utils import report
|
from . utils import report
|
||||||
from . functions import read_shelves
|
from . functions import read_shelves
|
||||||
from . import operators
|
from . import operators
|
||||||
#from .import shelves
|
|
||||||
from . import properties
|
from . import properties
|
||||||
from .import panels
|
from . import ui
|
||||||
from .properties import CustomShelfSettings,CustomShelfProps
|
from .properties import CustomShelfSettings,CustomShelfProps
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
class_to_register = [
|
bl_classes = [
|
||||||
properties.AdditionnalShelves,
|
properties.AdditionnalShelves,
|
||||||
properties.CustomShelfProps,
|
properties.CustomShelfProps,
|
||||||
properties.CustomShelfSettings,
|
properties.CustomShelfSettings,
|
||||||
|
@ -42,16 +41,22 @@ operators.CSHELF_OT_remove_shelf_folder,
|
||||||
operators.CSHELF_OT_open_shelf_folder,
|
operators.CSHELF_OT_open_shelf_folder,
|
||||||
operators.CSHELF_OT_add_script,
|
operators.CSHELF_OT_add_script,
|
||||||
operators.CSHELF_OT_set_tag_filter,
|
operators.CSHELF_OT_set_tag_filter,
|
||||||
panels.CSHELF_PT_text_editor
|
ui.CSHELF_MT_text_editor
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def draw_menu(self, context):
|
||||||
|
self.layout.menu('CSHELF_MT_text_editor')
|
||||||
|
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
for bl_classes in class_to_register :
|
for bl_class in bl_classes :
|
||||||
bpy.utils.register_class(bl_classes)
|
bpy.utils.register_class(bl_class)
|
||||||
|
|
||||||
bpy.types.Scene.CustomShelf = bpy.props.PointerProperty(type=CustomShelfSettings)
|
bpy.types.Scene.CustomShelf = bpy.props.PointerProperty(type=CustomShelfSettings)
|
||||||
bpy.types.WindowManager.CustomShelf = bpy.props.PointerProperty(type=CustomShelfProps)
|
bpy.types.WindowManager.CustomShelf = bpy.props.PointerProperty(type=CustomShelfProps)
|
||||||
|
|
||||||
|
bpy.types.TEXT_MT_editor_menus.append(draw_menu)
|
||||||
|
|
||||||
env_shelves = os.getenv("CUSTOM_SHELVES")
|
env_shelves = os.getenv("CUSTOM_SHELVES")
|
||||||
if env_shelves:
|
if env_shelves:
|
||||||
shelves = env_shelves.split(os.pathsep)
|
shelves = env_shelves.split(os.pathsep)
|
||||||
|
@ -60,24 +65,24 @@ def register():
|
||||||
|
|
||||||
# prefs.additionnal_shelves.clear()
|
# prefs.additionnal_shelves.clear()
|
||||||
for path in shelves:
|
for path in shelves:
|
||||||
s = next((s for s in prefs.additionnal_shelves if s.path == path), None)
|
shelf = next((s for s in prefs.additionnal_shelves if s.path == path), None)
|
||||||
if not s:
|
if not shelf:
|
||||||
s = prefs.additionnal_shelves.add()
|
shelf = prefs.additionnal_shelves.add()
|
||||||
s.path = path
|
shelf.path = path
|
||||||
|
|
||||||
read_shelves()
|
read_shelves()
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
# unregister panel :
|
# unregister panel :
|
||||||
for p in CustomShelfSettings.panel_list :
|
for panel in CustomShelfSettings.panel_list :
|
||||||
try :
|
try :
|
||||||
bpy.utils.unregister_class(p)
|
bpy.utils.unregister_class(panel)
|
||||||
except :
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
bpy.types.TEXT_MT_editor_menus.remove(draw_menu)
|
||||||
del bpy.types.Scene.CustomShelf
|
del bpy.types.Scene.CustomShelf
|
||||||
del bpy.types.WindowManager.CustomShelf
|
del bpy.types.WindowManager.CustomShelf
|
||||||
|
|
||||||
|
for bl_class in bl_classes :
|
||||||
for bl_classes in class_to_register :
|
bpy.utils.unregister_class(bl_class)
|
||||||
bpy.utils.unregister_class(bl_classes)
|
|
||||||
|
|
23
functions.py
23
functions.py
|
@ -74,13 +74,14 @@ def read_shelves() :
|
||||||
tag_filter_items = []
|
tag_filter_items = []
|
||||||
|
|
||||||
# unregister panel :
|
# unregister panel :
|
||||||
for p in CustomShelfSettings.panel_list :
|
for panel in CustomShelfSettings.panel_list:
|
||||||
if p.__name__ not in get_tabs() :
|
print(panel)
|
||||||
|
if panel.__name__ not in get_tabs():
|
||||||
try :
|
try :
|
||||||
bpy.utils.unregister_class(p)
|
bpy.utils.unregister_class(panel)
|
||||||
except :
|
except Exception:
|
||||||
pass
|
pass
|
||||||
CustomShelfSettings.panel_list.remove(p)
|
CustomShelfSettings.panel_list.remove(panel)
|
||||||
|
|
||||||
|
|
||||||
for cat in get_dirs(get_shelves_folder()) :
|
for cat in get_dirs(get_shelves_folder()) :
|
||||||
|
@ -156,7 +157,10 @@ def read_shelves() :
|
||||||
|
|
||||||
scripts = []
|
scripts = []
|
||||||
for script in scandir(tab.path) :
|
for script in scandir(tab.path) :
|
||||||
if not script.name.endswith('.py') : continue
|
if not script.name.endswith('.py'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(script.path)
|
||||||
|
|
||||||
script_name = splitext(script.name)[0]
|
script_name = splitext(script.name)[0]
|
||||||
|
|
||||||
|
@ -166,11 +170,12 @@ def read_shelves() :
|
||||||
|
|
||||||
icon = info.get('icon', "WORDWRAP_OFF")
|
icon = info.get('icon', "WORDWRAP_OFF")
|
||||||
|
|
||||||
popup = type(script_name,(CSHELF_OT_shelf_popup,),{"script":script.path,'bl_description':info["description"]})
|
popup = type(script_name, (CSHELF_OT_shelf_popup,),
|
||||||
|
{"script": script.path,
|
||||||
|
'bl_description': info["description"]
|
||||||
|
})
|
||||||
popup.initialyse(popup, script_name, info)
|
popup.initialyse(popup, script_name, info)
|
||||||
bpy.utils.register_class(popup)
|
bpy.utils.register_class(popup)
|
||||||
|
|
||||||
|
|
||||||
scripts.append({"operator" : popup.bl_idname,"text" : script_name,"icon" : icon})
|
scripts.append({"operator" : popup.bl_idname,"text" : script_name,"icon" : icon})
|
||||||
|
|
||||||
panel.scripts = sorted(scripts,key = lambda x :x['text'])
|
panel.scripts = sorted(scripts,key = lambda x :x['text'])
|
||||||
|
|
|
@ -4,6 +4,7 @@ from bpy.types import Operator
|
||||||
from bpy.props import *
|
from bpy.props import *
|
||||||
from .properties import CustomShelfSettings
|
from .properties import CustomShelfSettings
|
||||||
|
|
||||||
|
|
||||||
class CSHELF_OT_refresh(Operator):
|
class CSHELF_OT_refresh(Operator):
|
||||||
bl_idname = "customshelf.refresh"
|
bl_idname = "customshelf.refresh"
|
||||||
bl_label = 'Refresh Shelves'
|
bl_label = 'Refresh Shelves'
|
||||||
|
@ -85,6 +86,10 @@ class CSHELF_OT_add_script(Operator) :
|
||||||
icon : StringProperty()
|
icon : StringProperty()
|
||||||
show_icons : BoolProperty()
|
show_icons : BoolProperty()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
return context.area.type == 'TEXT_EDITOR' and context.space_data.text
|
||||||
|
|
||||||
def add_folder(self,context,op) :
|
def add_folder(self,context,op) :
|
||||||
folder = self.folder.add()
|
folder = self.folder.add()
|
||||||
folder.name = self.name
|
folder.name = self.name
|
||||||
|
@ -258,7 +263,6 @@ class CSHELF_OT_add_script(Operator) :
|
||||||
if self.info.get('description') :
|
if self.info.get('description') :
|
||||||
description = self.info["description"]
|
description = self.info["description"]
|
||||||
|
|
||||||
|
|
||||||
self.icon = icon
|
self.icon = icon
|
||||||
self.name = splitext(self.active_text.name)[0]
|
self.name = splitext(self.active_text.name)[0]
|
||||||
self.show_icons = False
|
self.show_icons = False
|
||||||
|
@ -269,7 +273,7 @@ class CSHELF_OT_add_script(Operator) :
|
||||||
self.icons = []
|
self.icons = []
|
||||||
|
|
||||||
operator("get_icons", {'execute': self.get_icons})
|
operator("get_icons", {'execute': self.get_icons})
|
||||||
operator("set_icon",{'execute':self.set_icon,'icon':StringProperty()})
|
operator("set_icon", {'execute': self.set_icon, '__annotations__': {'icon' : StringProperty()}})
|
||||||
operator("add_folder", {'execute': self.add_folder})
|
operator("add_folder", {'execute': self.add_folder})
|
||||||
#operator("remove_folder",{'execute':self.remove_folder})
|
#operator("remove_folder",{'execute':self.remove_folder})
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,14 @@
|
||||||
from .utils import *
|
|
||||||
|
import bpy
|
||||||
|
|
||||||
|
|
||||||
|
class CSHELF_MT_text_editor(bpy.types.Menu):
|
||||||
class CSHELF_PT_text_editor(bpy.types.Panel):
|
bl_label = "Shelves"
|
||||||
bl_space_type = "TEXT_EDITOR"
|
|
||||||
bl_region_type = "UI"
|
|
||||||
bl_category = "Dev"
|
|
||||||
bl_label = "Custom Shelf"
|
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
shelves = bpy.context.scene.CustomShelf
|
layout.operator("customshelf.add_script", text='Add Script', icon="FILE_NEW")
|
||||||
|
|
||||||
row = layout.row(align = True)
|
|
||||||
|
|
||||||
row.operator("customshelf.add_script", text='Add Script',emboss=True,icon= "LONGDISPLAY")
|
|
||||||
row.separator()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
12
utils.py
12
utils.py
|
@ -14,7 +14,7 @@ id_type = {"Action" : "actions", "Armature":"armatures", "Brush":"brushes", "Cac
|
||||||
"Material":"materials", "Mesh":"meshes", "MetaBall":"metaballs", "MovieClip":"movieclips", "NodeTree":"node_groups",
|
"Material":"materials", "Mesh":"meshes", "MetaBall":"metaballs", "MovieClip":"movieclips", "NodeTree":"node_groups",
|
||||||
"Object":"objects", "PaintCurve":"paint_curves", "Palette":"palettes", "ParticleSettings":"particles",
|
"Object":"objects", "PaintCurve":"paint_curves", "Palette":"palettes", "ParticleSettings":"particles",
|
||||||
"Scene":"scenes", "Screen":"screens", "Sound":"sounds", "Speaker":"speakers", "Text":"texts", "Texture":"textures",
|
"Scene":"scenes", "Screen":"screens", "Sound":"sounds", "Speaker":"speakers", "Text":"texts", "Texture":"textures",
|
||||||
"VectorFont":"fonts", "WindowManager":"window_managers", "World":"worlds"}
|
"Collection":"collections", "VectorFont":"fonts", "WindowManager":"window_managers", "World":"worlds"}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,6 +63,13 @@ def dic_to_args(dic):
|
||||||
import collections
|
import collections
|
||||||
args = collections.OrderedDict()
|
args = collections.OrderedDict()
|
||||||
|
|
||||||
|
prop_type = {
|
||||||
|
str: StringProperty,
|
||||||
|
bool: BoolProperty,
|
||||||
|
float: FloatProperty,
|
||||||
|
int : IntProperty
|
||||||
|
}
|
||||||
|
|
||||||
for k, v in dic.items() :
|
for k, v in dic.items() :
|
||||||
if k in ('icon','description') or not isinstance(k,str):
|
if k in ('icon','description') or not isinstance(k,str):
|
||||||
continue
|
continue
|
||||||
|
@ -92,6 +99,9 @@ def dic_to_args(dic):
|
||||||
#args[k] = PointerProperty(type = getattr(bpy.types,v["collection"]))
|
#args[k] = PointerProperty(type = getattr(bpy.types,v["collection"]))
|
||||||
else :
|
else :
|
||||||
args[k] = PointerProperty(type = getattr(bpy.types,v["collection"]),poll = v.get('poll'))
|
args[k] = PointerProperty(type = getattr(bpy.types,v["collection"]),poll = v.get('poll'))
|
||||||
|
else:
|
||||||
|
args[k] = prop_type[type(v['default'])](**v)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
Loading…
Reference in New Issue