Skip to content

Commit

Permalink
!1 Fix: TopBar Replace Interface Error
Browse files Browse the repository at this point in the history
Merge pull request !1 from 怪我咯/fix-topbar-replace-Interface-error
  • Loading branch information
xmx-emm authored and gitee-org committed Jan 3, 2024
2 parents 54ff010 + dc7ef13 commit 5d7d467
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 51 deletions.
59 changes: 10 additions & 49 deletions ui/replace_ui.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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():
Expand Down
10 changes: 8 additions & 2 deletions utils/reg.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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():
Expand Down

0 comments on commit 5d7d467

Please sign in to comment.