|
|
|
@ -25,6 +25,8 @@ import TemplateAuthoring
|
|
|
|
|
|
|
|
|
|
|
|
COMMAND_NAME = "QET_Template_OpenAuthoringPanel"
|
|
|
|
COMMAND_NAME = "QET_Template_OpenAuthoringPanel"
|
|
|
|
MENU_ACTION_OBJECT_NAME = "QET_Template_OpenAuthoringPanel_MenuAction"
|
|
|
|
MENU_ACTION_OBJECT_NAME = "QET_Template_OpenAuthoringPanel_MenuAction"
|
|
|
|
|
|
|
|
TOOLBAR_OBJECT_NAME = "QET_Template_Authoring_Toolbar"
|
|
|
|
|
|
|
|
TOOLBAR_ACTION_OBJECT_NAME = "QET_Template_OpenAuthoringPanel_ToolbarAction"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def next_slot_name(report):
|
|
|
|
def next_slot_name(report):
|
|
|
|
@ -211,6 +213,7 @@ class CommandOpenTemplateAuthoringPanel:
|
|
|
|
|
|
|
|
|
|
|
|
_COMMANDS_REGISTERED = False
|
|
|
|
_COMMANDS_REGISTERED = False
|
|
|
|
_MENU_ACTION_INSTALLED = False
|
|
|
|
_MENU_ACTION_INSTALLED = False
|
|
|
|
|
|
|
|
_TOOLBAR_ACTION_INSTALLED = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _tools_menu():
|
|
|
|
def _tools_menu():
|
|
|
|
@ -224,7 +227,8 @@ def _tools_menu():
|
|
|
|
menu_bar = main_window.menuBar()
|
|
|
|
menu_bar = main_window.menuBar()
|
|
|
|
for action in menu_bar.actions():
|
|
|
|
for action in menu_bar.actions():
|
|
|
|
menu = action.menu()
|
|
|
|
menu = action.menu()
|
|
|
|
if menu is not None and action.text().replace("&", "") in {"工具", "Tools"}:
|
|
|
|
text = action.text().replace("&", "").strip()
|
|
|
|
|
|
|
|
if menu is not None and (text.startswith("工具") or text.startswith("Tools")):
|
|
|
|
return menu
|
|
|
|
return menu
|
|
|
|
return menu_bar.addMenu("工具")
|
|
|
|
return menu_bar.addMenu("工具")
|
|
|
|
|
|
|
|
|
|
|
|
@ -247,6 +251,38 @@ def install_menu_action():
|
|
|
|
_MENU_ACTION_INSTALLED = True
|
|
|
|
_MENU_ACTION_INSTALLED = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def install_toolbar_action():
|
|
|
|
|
|
|
|
global _TOOLBAR_ACTION_INSTALLED
|
|
|
|
|
|
|
|
if _TOOLBAR_ACTION_INSTALLED:
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
if Gui is None or QtGui is None or QtWidgets is None or not hasattr(Gui, "getMainWindow"):
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
main_window = Gui.getMainWindow()
|
|
|
|
|
|
|
|
if main_window is None:
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toolbar = None
|
|
|
|
|
|
|
|
for candidate in main_window.findChildren(QtWidgets.QToolBar):
|
|
|
|
|
|
|
|
if candidate.objectName() == TOOLBAR_OBJECT_NAME:
|
|
|
|
|
|
|
|
toolbar = candidate
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
if toolbar is None:
|
|
|
|
|
|
|
|
toolbar = main_window.addToolBar("QET模板")
|
|
|
|
|
|
|
|
toolbar.setObjectName(TOOLBAR_OBJECT_NAME)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for action in toolbar.actions():
|
|
|
|
|
|
|
|
if action.objectName() == TOOLBAR_ACTION_OBJECT_NAME:
|
|
|
|
|
|
|
|
_TOOLBAR_ACTION_INSTALLED = True
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
action = QtGui.QAction("设备模板端子制作", toolbar)
|
|
|
|
|
|
|
|
action.setObjectName(TOOLBAR_ACTION_OBJECT_NAME)
|
|
|
|
|
|
|
|
action.setToolTip("打开设备模板端子制作面板")
|
|
|
|
|
|
|
|
action.triggered.connect(lambda: Gui.runCommand(COMMAND_NAME))
|
|
|
|
|
|
|
|
toolbar.addAction(action)
|
|
|
|
|
|
|
|
_TOOLBAR_ACTION_INSTALLED = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def register_commands():
|
|
|
|
def register_commands():
|
|
|
|
global _COMMANDS_REGISTERED
|
|
|
|
global _COMMANDS_REGISTERED
|
|
|
|
if Gui is None or not hasattr(Gui, "addCommand"):
|
|
|
|
if Gui is None or not hasattr(Gui, "addCommand"):
|
|
|
|
@ -255,6 +291,7 @@ def register_commands():
|
|
|
|
Gui.addCommand(COMMAND_NAME, CommandOpenTemplateAuthoringPanel())
|
|
|
|
Gui.addCommand(COMMAND_NAME, CommandOpenTemplateAuthoringPanel())
|
|
|
|
_COMMANDS_REGISTERED = True
|
|
|
|
_COMMANDS_REGISTERED = True
|
|
|
|
install_menu_action()
|
|
|
|
install_menu_action()
|
|
|
|
|
|
|
|
install_toolbar_action()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
register_commands()
|
|
|
|
register_commands()
|
|
|
|
|