diff --git a/ui/replace_ui.py b/ui/replace_ui.py index d5ea4e0..34947be 100644 --- a/ui/replace_ui.py +++ b/ui/replace_ui.py @@ -1,11 +1,10 @@ -import inspect from functools import cache import bpy from ..utils.public import all_operator_listen, PublicClass -G_UiReplaceDit = {} +UiReplaceFunc = None @cache @@ -56,55 +55,17 @@ def append_top_editor_menus(self, context): ) -def __set_menu_fun(origin_menu_class, origin_menu_class_path, replace, - replace_func, replace_func_path, menu_key): - tmp_draw_funcs_list = [] - for i in origin_menu_class.draw._draw_funcs: - func_path_ = inspect.getfile(i) - if func_path_ == origin_menu_class_path and replace: - G_UiReplaceDit[func_path_ + ' draw' + - origin_menu_class.__name__] = i - tmp_draw_funcs_list.append(replace_func) - elif func_path_ == replace_func_path and (not replace): - tmp_draw_funcs_list.append(G_UiReplaceDit[menu_key]) - else: - tmp_draw_funcs_list.append(i) - origin_menu_class.draw._draw_funcs = tmp_draw_funcs_list - del tmp_draw_funcs_list - - -def menu_item_replace(origin_menu_class, replace_func, replace): - """ - :Menu_class 需要被替换的菜单类 - :replace_func 替换的菜单绘制方法 - :replace 替换的布尔值,真则替换,反之还原 - """ - - global G_UiReplaceDit - origin_menu_class_path = inspect.getfile(origin_menu_class) - replace_func_path = inspect.getfile(replace_func) - - menu_key = origin_menu_class_path + ' draw' + origin_menu_class.__name__ - - if getattr(origin_menu_class, 'draw', False) and (menu_key - not in G_UiReplaceDit): - G_UiReplaceDit[menu_key] = origin_menu_class.draw - - if bpy.types.Header in origin_menu_class.__bases__: - - if replace: - origin_menu_class.draw = replace_func - else: - if menu_key in G_UiReplaceDit: - origin_menu_class.draw = G_UiReplaceDit[menu_key] - elif getattr(origin_menu_class.draw, '_draw_funcs', False): # 面板类的 - __set_menu_fun(origin_menu_class, origin_menu_class_path, replace, - replace_func, replace_func_path, menu_key) +def replace_top_bar(replace: bool): + global UiReplaceFunc + cls = bpy.types.TOPBAR_HT_upper_bar + if UiReplaceFunc is None: + UiReplaceFunc = cls.draw -def replace_top_bar(replace: bool): - menu_item_replace(bpy.types.TOPBAR_HT_upper_bar, - append_top_editor_menus, replace) + if replace: + cls.draw = append_top_editor_menus + else: + cls.draw = UiReplaceFunc def update_top_bar(): diff --git a/utils/reg.py b/utils/reg.py index 1d37dff..be4af5e 100644 --- a/utils/reg.py +++ b/utils/reg.py @@ -1,7 +1,9 @@ +import bpy + from . import preferences, update, bbrush_toolbar from .bbrush_toolbar import BrushTool -from .. import ops, ui from .public import register_submodule_factory, PublicClass +from .. import ops, ui model_tuple = ( ui, @@ -14,10 +16,14 @@ register_module, unregister_module = register_submodule_factory(model_tuple) +def update_sculpt(): + PublicClass.pref_().sculpt = False + + def register(): register_module() PublicClass.cache_clear() - PublicClass.pref_().sculpt = False + bpy.app.timers.register(update_sculpt, first_interval=2) def unregister():