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):
|
||||
#props = None
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
@property
|
||||
def props(self) :
|
||||
#print(getattr(bpy.context.window_manager.CustomShelf,self.prop))
|
||||
|
@ -31,12 +33,9 @@ class CSHELF_OT_shelf_popup(Types,Operator) :
|
|||
#props =
|
||||
return {k:v for k,v in self.args.items() if k in properties}
|
||||
|
||||
|
||||
|
||||
def set_props(self,prop,value):
|
||||
setattr(bpy.context.window_manager.CustomShelf,prop,value)
|
||||
|
||||
|
||||
def initialyse(self,label,info) :
|
||||
super().initialyse(CSHELF_OT_shelf_popup,label)
|
||||
|
||||
|
@ -119,8 +118,6 @@ class CSHELF_OT_shelf_popup(Types,Operator) :
|
|||
print(*args)
|
||||
|
||||
def execute(self,context):
|
||||
import tempfile
|
||||
|
||||
info, lines = read_info(self.script)
|
||||
|
||||
values = dict(info)
|
||||
|
@ -136,16 +133,11 @@ class CSHELF_OT_shelf_popup(Types,Operator) :
|
|||
else :
|
||||
values[arg] = value
|
||||
|
||||
|
||||
info_str = "info = %s\n\n"%values
|
||||
lines_str = '\n'.join(lines)
|
||||
script = f"{info_str}\n\n{lines_str}"
|
||||
|
||||
tmp_folder = tempfile.gettempdir()
|
||||
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})
|
||||
exec(script, {'info': values, 'print': self.bl_report})
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
|
39
__init__.py
39
__init__.py
|
@ -3,7 +3,7 @@ bl_info = {
|
|||
"author": "Christophe Seux",
|
||||
"description": "Adds buttons to launch custom python scripts in the User panel.",
|
||||
"version": (0, 3, 2),
|
||||
"blender": (2, 82, 0),
|
||||
"blender": (4, 0, 2),
|
||||
"location": "View3D > User Panel",
|
||||
"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",
|
||||
|
@ -22,16 +22,15 @@ if "bpy" in locals():
|
|||
from . utils import report
|
||||
from . functions import read_shelves
|
||||
from . import operators
|
||||
#from .import shelves
|
||||
from . import properties
|
||||
from .import panels
|
||||
from . import ui
|
||||
from .properties import CustomShelfSettings,CustomShelfProps
|
||||
|
||||
import bpy
|
||||
import os
|
||||
|
||||
|
||||
class_to_register = [
|
||||
bl_classes = [
|
||||
properties.AdditionnalShelves,
|
||||
properties.CustomShelfProps,
|
||||
properties.CustomShelfSettings,
|
||||
|
@ -42,16 +41,22 @@ operators.CSHELF_OT_remove_shelf_folder,
|
|||
operators.CSHELF_OT_open_shelf_folder,
|
||||
operators.CSHELF_OT_add_script,
|
||||
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():
|
||||
for bl_classes in class_to_register :
|
||||
bpy.utils.register_class(bl_classes)
|
||||
for bl_class in bl_classes :
|
||||
bpy.utils.register_class(bl_class)
|
||||
|
||||
bpy.types.Scene.CustomShelf = bpy.props.PointerProperty(type=CustomShelfSettings)
|
||||
bpy.types.WindowManager.CustomShelf = bpy.props.PointerProperty(type=CustomShelfProps)
|
||||
|
||||
bpy.types.TEXT_MT_editor_menus.append(draw_menu)
|
||||
|
||||
env_shelves = os.getenv("CUSTOM_SHELVES")
|
||||
if env_shelves:
|
||||
shelves = env_shelves.split(os.pathsep)
|
||||
|
@ -60,24 +65,24 @@ def register():
|
|||
|
||||
# prefs.additionnal_shelves.clear()
|
||||
for path in shelves:
|
||||
s = next((s for s in prefs.additionnal_shelves if s.path == path), None)
|
||||
if not s:
|
||||
s = prefs.additionnal_shelves.add()
|
||||
s.path = path
|
||||
shelf = next((s for s in prefs.additionnal_shelves if s.path == path), None)
|
||||
if not shelf:
|
||||
shelf = prefs.additionnal_shelves.add()
|
||||
shelf.path = path
|
||||
|
||||
read_shelves()
|
||||
|
||||
def unregister():
|
||||
# unregister panel :
|
||||
for p in CustomShelfSettings.panel_list :
|
||||
for panel in CustomShelfSettings.panel_list :
|
||||
try :
|
||||
bpy.utils.unregister_class(p)
|
||||
except :
|
||||
bpy.utils.unregister_class(panel)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
bpy.types.TEXT_MT_editor_menus.remove(draw_menu)
|
||||
del bpy.types.Scene.CustomShelf
|
||||
del bpy.types.WindowManager.CustomShelf
|
||||
|
||||
|
||||
for bl_classes in class_to_register :
|
||||
bpy.utils.unregister_class(bl_classes)
|
||||
for bl_class in bl_classes :
|
||||
bpy.utils.unregister_class(bl_class)
|
||||
|
|
23
functions.py
23
functions.py
|
@ -74,13 +74,14 @@ def read_shelves() :
|
|||
tag_filter_items = []
|
||||
|
||||
# unregister panel :
|
||||
for p in CustomShelfSettings.panel_list :
|
||||
if p.__name__ not in get_tabs() :
|
||||
for panel in CustomShelfSettings.panel_list:
|
||||
print(panel)
|
||||
if panel.__name__ not in get_tabs():
|
||||
try :
|
||||
bpy.utils.unregister_class(p)
|
||||
except :
|
||||
bpy.utils.unregister_class(panel)
|
||||
except Exception:
|
||||
pass
|
||||
CustomShelfSettings.panel_list.remove(p)
|
||||
CustomShelfSettings.panel_list.remove(panel)
|
||||
|
||||
|
||||
for cat in get_dirs(get_shelves_folder()) :
|
||||
|
@ -156,7 +157,10 @@ def read_shelves() :
|
|||
|
||||
scripts = []
|
||||
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]
|
||||
|
||||
|
@ -166,11 +170,12 @@ def read_shelves() :
|
|||
|
||||
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)
|
||||
bpy.utils.register_class(popup)
|
||||
|
||||
|
||||
scripts.append({"operator" : popup.bl_idname,"text" : script_name,"icon" : icon})
|
||||
|
||||
panel.scripts = sorted(scripts,key = lambda x :x['text'])
|
||||
|
|
|
@ -4,6 +4,7 @@ from bpy.types import Operator
|
|||
from bpy.props import *
|
||||
from .properties import CustomShelfSettings
|
||||
|
||||
|
||||
class CSHELF_OT_refresh(Operator):
|
||||
bl_idname = "customshelf.refresh"
|
||||
bl_label = 'Refresh Shelves'
|
||||
|
@ -85,6 +86,10 @@ class CSHELF_OT_add_script(Operator) :
|
|||
icon : StringProperty()
|
||||
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) :
|
||||
folder = self.folder.add()
|
||||
folder.name = self.name
|
||||
|
@ -258,7 +263,6 @@ class CSHELF_OT_add_script(Operator) :
|
|||
if self.info.get('description') :
|
||||
description = self.info["description"]
|
||||
|
||||
|
||||
self.icon = icon
|
||||
self.name = splitext(self.active_text.name)[0]
|
||||
self.show_icons = False
|
||||
|
@ -269,7 +273,7 @@ class CSHELF_OT_add_script(Operator) :
|
|||
self.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("remove_folder",{'execute':self.remove_folder})
|
||||
|
||||
|
|
|
@ -1,21 +1,14 @@
|
|||
from .utils import *
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
|
||||
class CSHELF_PT_text_editor(bpy.types.Panel):
|
||||
bl_space_type = "TEXT_EDITOR"
|
||||
bl_region_type = "UI"
|
||||
bl_category = "Dev"
|
||||
bl_label = "Custom Shelf"
|
||||
class CSHELF_MT_text_editor(bpy.types.Menu):
|
||||
bl_label = "Shelves"
|
||||
|
||||
def draw(self, context):
|
||||
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",
|
||||
"Object":"objects", "PaintCurve":"paint_curves", "Palette":"palettes", "ParticleSettings":"particles",
|
||||
"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
|
||||
args = collections.OrderedDict()
|
||||
|
||||
prop_type = {
|
||||
str: StringProperty,
|
||||
bool: BoolProperty,
|
||||
float: FloatProperty,
|
||||
int : IntProperty
|
||||
}
|
||||
|
||||
for k, v in dic.items() :
|
||||
if k in ('icon','description') or not isinstance(k,str):
|
||||
continue
|
||||
|
@ -92,6 +99,9 @@ def dic_to_args(dic):
|
|||
#args[k] = PointerProperty(type = getattr(bpy.types,v["collection"]))
|
||||
else :
|
||||
args[k] = PointerProperty(type = getattr(bpy.types,v["collection"]),poll = v.get('poll'))
|
||||
else:
|
||||
args[k] = prop_type[type(v['default'])](**v)
|
||||
|
||||
|
||||
|
||||
return args
|
||||
|
|
Loading…
Reference in New Issue