Commit: b401d0030a9b09b511f5ee191e0b73e7b57355bc Author: Campbell Barton Date: Wed Mar 22 11:28:15 2017 +1100 Branches: app-templates https://developer.blender.org/rBb401d0030a9b09b511f5ee191e0b73e7b57355bc
Split out override class into its own base class This means multiple templates can share a single base class, each templates class only needs to fill in the callbacks. =================================================================== M release/datafiles/app_templates/101/template/__init__.py M release/scripts/modules/bl_app_override.py =================================================================== diff --git a/release/datafiles/app_templates/101/template/__init__.py b/release/datafiles/app_templates/101/template/__init__.py index 6b01da07d5..8d511809ed 100644 --- a/release/datafiles/app_templates/101/template/__init__.py +++ b/release/datafiles/app_templates/101/template/__init__.py @@ -22,31 +22,15 @@ import bpy import bl_app_override -class AppStateStore: - # Utility class to encapsulate application state, backup and restore. - __slots__ = ( - # setup_classes - "class_store", - # setup_addons - "sys_path", - # setup_ui_filter - "ui_filter_store" - ) - - _template_addons = ( - "template_101_library", - ) - - def __init__(self): - self.class_store = [] - self.sys_path = [] - self.ui_filter_store = [] - - def setup_classes(self): - assert(len(self.class_store) == 0) - - # Classes - self.class_store.extend( +class AppStateStore(bl_app_override.AppOverrideState): + # Just provides data & callbacks for AppOverrideState + __slots__ = () + + @staticmethod + def class_ignore(): + classes = [] + + classes.extend( bl_app_override.class_filter( bpy.types.Panel, # match any of these values @@ -59,9 +43,9 @@ class AppStateStore: }, ), ) - # print(self.class_store) + # print(self.classes) - self.class_store.extend( + classes.extend( bl_app_override.class_filter( bpy.types.Panel, # match any of these values @@ -114,114 +98,81 @@ class AppStateStore: 'VIEW3D_PT_tools_meshedit', 'WORLD_PT_preview', 'WORLD_PT_world', - # '', }, ), ) - - unregister = bpy.utils.unregister_class - for cls in self.class_store: - unregister(cls) - - def teardown_classes(self): - assert(len(self.class_store) != 0) - - register = bpy.utils.register_class - for cls in self.class_store: - register(cls) - self.class_store.clear() - - def setup_ui_filter(self): - import bl_app_override - - def filter_operator(op_id): - return op_id not in { - "object.select_by_layer", - "object.select_mirror", - "object.select_pattern", - "sound.mixdown", - "transform.mirror", - "view3d.clear_render_border", - "view3d.clip_border", - "view3d.localview", - "view3d.render_border", - "view3d.zoom_border", - } - - def filter_property(ty, prop): - return (ty, prop) not in { - ("Material", "use_nodes"), - ("MaterialSlot", "link"), - ("Object", "pass_index"), - ("RenderSettings", "filter_size"), - ("RenderSettings", "frame_map_new"), - ("RenderSettings", "frame_map_old"), - ("RenderSettings", "pixel_aspect_x"), - ("RenderSettings", "pixel_aspect_y"), - ("RenderSettings", "pixel_filter_type"), - ("RenderSettings", "use_border"), - ("RenderSettings", "use_crop_to_border"), - ("RenderSettings", "use_placeholder"), - ("RenderSettings", "use_render_cache"), - ("Scene", "frame_step"), - ("Scene", "lock_frame_selection_to_range"), - ("Scene", "sync_mode"), - ("Scene", "use_preview_range"), - } - - def filter_menu(menu_id): - return menu_id not in { - "TIME_MT_marker", - "TIME_MT_playback", - } - - def filter_label(text): - # print(text) - return text not in { - "Aspect Ratio:", - "Time Remapping:", - } - - self.ui_filter_store = bl_app_override.ui_draw_filter_register( - filter_operator=filter_operator, - filter_property=filter_property, - filter_menu=filter_menu, - filter_label=filter_label, + return classes + + # ---------------- + # UI Filter/Ignore + + @staticmethod + def ui_ignore_operator(op_id): + return op_id in { + "object.select_by_layer", + "object.select_mirror", + "object.select_pattern", + "sound.mixdown", + "transform.mirror", + "view3d.clear_render_border", + "view3d.clip_border", + "view3d.localview", + "view3d.render_border", + "view3d.zoom_border", + } + + @staticmethod + def ui_ignore_property(ty, prop): + return (ty, prop) in { + ("Material", "use_nodes"), + ("MaterialSlot", "link"), + ("Object", "pass_index"), + ("RenderSettings", "filter_size"), + ("RenderSettings", "frame_map_new"), + ("RenderSettings", "frame_map_old"), + ("RenderSettings", "pixel_aspect_x"), + ("RenderSettings", "pixel_aspect_y"), + ("RenderSettings", "pixel_filter_type"), + ("RenderSettings", "use_border"), + ("RenderSettings", "use_crop_to_border"), + ("RenderSettings", "use_placeholder"), + ("RenderSettings", "use_render_cache"), + ("Scene", "frame_step"), + ("Scene", "lock_frame_selection_to_range"), + ("Scene", "sync_mode"), + ("Scene", "use_preview_range"), + } + + @staticmethod + def ui_ignore_menu(menu_id): + return menu_id in { + "TIME_MT_marker", + "TIME_MT_playback", + } + + @staticmethod + def ui_ignore_label(text): + # print(text) + return text in { + "Aspect Ratio:", + "Time Remapping:", + } + + # ------- + # Add-ons + + @staticmethod + def addon_paths(): + import os + return ( + os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "addons")), ) - def teardown_ui_filter(self): - import bl_app_override - bl_app_override.ui_draw_filter_unregister( - self.ui_filter_store + @staticmethod + def addons(): + return ( + "template_101_library", ) - self.ui_filter_store = None - - - def setup_addons(self): - import sys - import os - template_addons = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "addons")) - if template_addons not in sys.path: - sys.path.append(template_addons) - self.sys_path.append(template_addons) - - import addon_utils - for addon in self._template_addons: - addon_utils.enable(addon) - - def teardown_addons(self): - import sys - for path in self.sys_path: - # should always succeed, but if not its no problem - try: - sys.path.remove(path) - except: - pass - self.sys_path.clear() - - import addon_utils - for addon in self._template_addons: - addon_utils.disable(addon) app_state = AppStateStore() @@ -230,9 +181,8 @@ from . import ui def register(): print("Template Register", __file__) - app_state.setup_classes() - app_state.setup_addons() - app_state.setup_ui_filter() + + app_state.setup() ui.register() @@ -241,6 +191,4 @@ def unregister(): ui.unregister() - app_state.teardown_classes() - app_state.teardown_addons() - app_state.teardown_ui_filter() + app_state.teardown() diff --git a/release/scripts/modules/bl_app_override.py b/release/scripts/modules/bl_app_override.py index 3e79c1ed06..8c274478f6 100644 --- a/release/scripts/modules/bl_app_override.py +++ b/release/scripts/modules/bl_app_override.py @@ -45,10 +45,10 @@ def class_filter(cls_parent, **kw): def ui_draw_filter_register( *, classes=None, - filter_operator=None, - filter_property=None, - filter_menu=None, - filter_label=None, + ui_ignore_operator=None, + ui_ignore_property=None, + ui_ignore_menu=None, + ui_ignore_label=None, ): import bpy @@ -79,14 +79,14 @@ def ui_draw_filter_register( return dummy_func elif attr in {"operator", "operator_menu_enum", "operator_enum"}: - if filter_operator is None: + if ui_ignore_operator is None: return UILayout.__getattribute__(self, attr) real_func = UILayout.__getattribute__(self, attr) def dummy_func(*args, **kw): # print("wrapped", attr) - if filter_operator(args[0]): + if not ui_ignore_operator(args[0]): ret = real_func(*args, **kw) else: # UILayout.__getattribute__(self, "label")() @@ -96,14 +96,14 @@ def ui_draw_filter_register( return dummy_func elif attr in {"prop", "prop_enum"}: - if filter_property is None: + if ui_ignore_property is None: return UILayout.__getattribute__(self, attr) real_func = UILayout.__getattribute__(self, attr) def dummy_func(*args, **kw): # print("wrapped", attr) - if filter_property(args[0].__class__.__name__, args[1]): + if not ui_ignore_property(args[0].__class__.__name__, args[1]): ret = real_func(*args, **kw) else: ret = None @@ -111,14 +111,14 @@ def ui_draw_filter_register( return dummy_func elif attr == "menu": - if filter_menu is None: + if ui_ignore_menu is None: return UILayout.__getattribute__(self, at @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs