Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/modules/bpy_types.py
| Show First 20 Lines • Show All 760 Lines • ▼ Show 20 Lines | def _dyn_ui_initialize(cls): | ||||
| draw_funcs = getattr(cls.draw, "_draw_funcs", None) | draw_funcs = getattr(cls.draw, "_draw_funcs", None) | ||||
| if draw_funcs is None: | if draw_funcs is None: | ||||
| def draw_ls(self, context): | def draw_ls(self, context): | ||||
| # ensure menus always get default context | # ensure menus always get default context | ||||
| operator_context_default = self.layout.operator_context | operator_context_default = self.layout.operator_context | ||||
| # Support filtering out by origin | |||||
| workspace = context.workspace | |||||
| if workspace.use_filter_by_origin: | |||||
| bl_origin_names = {bl_origin.name for bl_origin in workspace.bl_origins} | |||||
| else: | |||||
| bl_origin_names = None | |||||
| for func in draw_ls._draw_funcs: | for func in draw_ls._draw_funcs: | ||||
| # Begin 'bl_origin' filter. | |||||
| if bl_origin_names is not None: | |||||
| bl_origin = getattr(func, "_bl_origin", None) | |||||
| if bl_origin is not None: | |||||
| if func._bl_origin not in bl_origin_names: | |||||
| continue | |||||
| # End 'bl_origin' filter. | |||||
| # so bad menu functions don't stop | # so bad menu functions don't stop | ||||
| # the entire menu from drawing | # the entire menu from drawing | ||||
| try: | try: | ||||
| func(self, context) | func(self, context) | ||||
| except: | except: | ||||
| import traceback | import traceback | ||||
| traceback.print_exc() | traceback.print_exc() | ||||
| self.layout.operator_context = operator_context_default | self.layout.operator_context = operator_context_default | ||||
| draw_funcs = draw_ls._draw_funcs = [cls.draw] | draw_funcs = draw_ls._draw_funcs = [cls.draw] | ||||
| cls.draw = draw_ls | cls.draw = draw_ls | ||||
| return draw_funcs | return draw_funcs | ||||
| @staticmethod | |||||
| def _dyn_bl_origin_apply(draw_func): | |||||
| from _bpy import _bl_origin_get | |||||
| bl_origin = _bl_origin_get() | |||||
| if bl_origin is not None: | |||||
| draw_func._bl_origin = bl_origin | |||||
| @classmethod | @classmethod | ||||
| def is_extended(cls): | def is_extended(cls): | ||||
| return bool(getattr(cls.draw, "_draw_funcs", None)) | return bool(getattr(cls.draw, "_draw_funcs", None)) | ||||
| @classmethod | @classmethod | ||||
| def append(cls, draw_func): | def append(cls, draw_func): | ||||
| """ | """ | ||||
| Append a draw function to this menu, | Append a draw function to this menu, | ||||
| takes the same arguments as the menus draw function | takes the same arguments as the menus draw function | ||||
| """ | """ | ||||
| draw_funcs = cls._dyn_ui_initialize() | draw_funcs = cls._dyn_ui_initialize() | ||||
| cls._dyn_bl_origin_apply(draw_func) | |||||
| draw_funcs.append(draw_func) | draw_funcs.append(draw_func) | ||||
| @classmethod | @classmethod | ||||
| def prepend(cls, draw_func): | def prepend(cls, draw_func): | ||||
| """ | """ | ||||
| Prepend a draw function to this menu, takes the same arguments as | Prepend a draw function to this menu, takes the same arguments as | ||||
| the menus draw function | the menus draw function | ||||
| """ | """ | ||||
| draw_funcs = cls._dyn_ui_initialize() | draw_funcs = cls._dyn_ui_initialize() | ||||
| cls._dyn_bl_origin_apply(draw_func) | |||||
| draw_funcs.insert(0, draw_func) | draw_funcs.insert(0, draw_func) | ||||
| @classmethod | @classmethod | ||||
| def remove(cls, draw_func): | def remove(cls, draw_func): | ||||
| """Remove a draw function that has been added to this menu""" | """Remove a draw function that has been added to this menu""" | ||||
| draw_funcs = cls._dyn_ui_initialize() | draw_funcs = cls._dyn_ui_initialize() | ||||
| try: | try: | ||||
| draw_funcs.remove(draw_func) | draw_funcs.remove(draw_func) | ||||
| ▲ Show 20 Lines • Show All 169 Lines • Show Last 20 Lines | |||||