diff options
author | lijenstina <lijenstina@gmail.com> | 2017-07-08 22:48:15 +0300 |
---|---|---|
committer | lijenstina <lijenstina@gmail.com> | 2017-07-08 22:48:15 +0300 |
commit | 9bde6ff5aca89f7a713aa4eb141c81783d72d01d (patch) | |
tree | f1e264c8f9f2b950bda96873648345d06186a240 /io_online_sketchfab/__init__.py | |
parent | e0bc0e758b43c57407c3f2c747656e62681603cc (diff) |
Sketchfab Exporter: Update panel Rename
Bumped version to 1.2.3
As a part of the task T50726:
Update the Panel rename code to more generic one
Use tuple imports for bpy.types
No other functional changes
Diffstat (limited to 'io_online_sketchfab/__init__.py')
-rw-r--r-- | io_online_sketchfab/__init__.py | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/io_online_sketchfab/__init__.py b/io_online_sketchfab/__init__.py index 8f0d97e5..bad00e82 100644 --- a/io_online_sketchfab/__init__.py +++ b/io_online_sketchfab/__init__.py @@ -19,7 +19,7 @@ bl_info = { "name": "Sketchfab Exporter", "author": "Bart Crouch", - "version": (1, 2, 2), + "version": (1, 2, 3), "blender": (2, 7, 0), "location": "Tools > File I/O tab", "description": "Upload your model to Sketchfab", @@ -41,6 +41,13 @@ from bpy.props import ( BoolProperty, PointerProperty, ) +from bpy.types import ( + Operator, + Panel, + AddonPreferences, + PropertyGroup, + ) + SKETCHFAB_API_URL = "https://api.sketchfab.com" SKETCHFAB_API_MODELS_URL = SKETCHFAB_API_URL + "/v1/models" @@ -76,6 +83,7 @@ class _SketchfabState: self.report_message = "" self.report_type = '' + sf_state = _SketchfabState() del _SketchfabState @@ -178,7 +186,7 @@ def upload(filepath, filename): # operator to export model to sketchfab -class ExportSketchfab(bpy.types.Operator): +class ExportSketchfab(Operator): """Upload your model to Sketchfab""" bl_idname = "export.sketchfab" bl_label = "Upload" @@ -284,7 +292,7 @@ class ExportSketchfab(bpy.types.Operator): # user interface -class VIEW3D_PT_sketchfab(bpy.types.Panel): +class VIEW3D_PT_sketchfab(Panel): bl_space_type = 'VIEW_3D' bl_region_type = 'TOOLS' bl_category = "File I/O" @@ -331,7 +339,7 @@ class VIEW3D_PT_sketchfab(bpy.types.Panel): # property group containing all properties for the user interface -class SketchfabProps(bpy.types.PropertyGroup): +class SketchfabProps(PropertyGroup): description = StringProperty( name="Description", description="Description of the model (optional)", @@ -386,7 +394,7 @@ class SketchfabProps(bpy.types.PropertyGroup): ) -class SketchfabEmailToken(bpy.types.Operator): +class SketchfabEmailToken(Operator): bl_idname = "wm.sketchfab_email_token" bl_label = "Enter your email to get a sketchfab token" @@ -426,34 +434,51 @@ def terminate(filepath): os.rmdir(os.path.dirname(filepath)) -## Addons Preferences Update Panel +# Add-ons Preferences Update Panel + +# Define Panel classes for updating +panels = ( + VIEW3D_PT_sketchfab, + ) + + def update_panel(self, context): + message = "Sketchfab Exporter: Updating Panel locations has failed" try: - bpy.utils.unregister_class(VIEW3D_PT_sketchfab) - 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 - VIEW3D_PT_sketchfab.bl_category = context.user_preferences.addons[__name__].preferences.category - bpy.utils.register_class(VIEW3D_PT_sketchfab) -class SfabAddonPreferences(bpy.types.AddonPreferences): + +class SfabAddonPreferences(AddonPreferences): # this must match the addon name, use '__package__' # when defining this in a submodule of a python package. bl_idname = __name__ - category = bpy.props.StringProperty( + category = StringProperty( name="Tab Category", description="Choose a name for the category of the panel", default="File I/O", - update=update_panel) + 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="") + # registration classes = ( ExportSketchfab, @@ -475,6 +500,7 @@ def register(): bpy.app.handlers.load_post.append(load_token) update_panel(None, bpy.context) + def unregister(): for cls in classes: bpy.utils.unregister_class(cls) |