From 844db32ac4e719a5ec84b028a12746fe062f3e74 Mon Sep 17 00:00:00 2001 From: lijenstina Date: Sun, 16 Apr 2017 04:37:34 +0200 Subject: Print3D: Update panel Rename As a part of the task T50726: Update the Panel rename code to more generic one update call was missing during register --- object_print3d_utils/__init__.py | 47 ++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'object_print3d_utils') diff --git a/object_print3d_utils/__init__.py b/object_print3d_utils/__init__.py index 5cf1ec53..f665f54c 100644 --- a/object_print3d_utils/__init__.py +++ b/object_print3d_utils/__init__.py @@ -16,7 +16,7 @@ # # ##### END GPL LICENSE BLOCK ##### -# +# bl_info = { "name": "3D Print Toolbox", @@ -25,7 +25,7 @@ bl_info = { "location": "3D View > Toolbox", "description": "Utilities for 3D printing", "warning": "", - "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/" + "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/" "Scripts/Modeling/PrintToolbox", "support": 'OFFICIAL', "category": "Mesh"} @@ -118,17 +118,29 @@ class Print3DSettings(PropertyGroup): ) -# Addons Preferences Update Panel +# Add-ons Preferences Update Panel + +# Define Panel classes for updating +panels = ( + ui.Print3DToolBarObject, + ui.Print3DToolBarMesh, + ) + + def update_panel(self, context): + message = "3D Print Toolbox: Updating Panel locations has failed" try: - bpy.utils.unregister_class(ui.Print3DToolBarObject) - bpy.utils.unregister_class(ui.Print3DToolBarMesh) - except: + for panel in panels: + if "bl_rna" in panel.__dict__: + bpy.utils.unregister_class(panel) + + for panel in panels: + panel.bl_category = context.user_preferences.addons[__name__].preferences.category + bpy.utils.register_class(panel) + + except Exception as e: + print("\n[{}]\n{}\n\nError:\n{}".format(__name__, message, e)) pass - ui.Print3DToolBarObject.bl_category = context.user_preferences.addons[__name__].preferences.category - bpy.utils.register_class(ui.Print3DToolBarObject) - ui.Print3DToolBarMesh.bl_category = context.user_preferences.addons[__name__].preferences.category - bpy.utils.register_class(ui.Print3DToolBarMesh) class printpreferences(AddonPreferences): @@ -136,17 +148,18 @@ class printpreferences(AddonPreferences): # when defining this in a submodule of a python package. bl_idname = __name__ - category = bpy.props.StringProperty( - name="Tab Category", - description="Choose a name for the category of the panel", - default="3D Printing", - update=update_panel) + category = StringProperty( + name="Tab Category", + description="Choose a name for the category of the panel", + default="3D Printing", + update=update_panel + ) def draw(self, context): - layout = self.layout row = layout.row() col = row.column() + col.label(text="Tab Category:") col.prop(self, "category", text="") @@ -190,6 +203,8 @@ def register(): bpy.types.Scene.print_3d = PointerProperty(type=Print3DSettings) + update_panel(None, bpy.context) + def unregister(): for cls in classes: -- cgit v1.2.3