diff --git a/src/Mod/FreeCADExchange/InitGui.py b/src/Mod/FreeCADExchange/InitGui.py index ed607e2..3b9785f 100644 --- a/src/Mod/FreeCADExchange/InitGui.py +++ b/src/Mod/FreeCADExchange/InitGui.py @@ -3,6 +3,8 @@ import os from pathlib import Path +import FreeCADGui as Gui + try: from PySide6 import QtCore except ImportError: @@ -18,6 +20,14 @@ import TemplateAuthoring import TemplateAuthoringPanel +COMMANDS = [ + TemplateAuthoringPanel.COMMAND_NAME, + "QET_Template_AddTerminal", + "QET_Template_ValidateTerminals", + "QET_Template_SaveAsFCStd", +] + + def _append_init_log(message): try: local_app_data = os.environ.get("LOCALAPPDATA", "").strip() @@ -34,30 +44,75 @@ def _append_init_log(message): _append_init_log("InitGui imported") -try: - ExchangeWriteBack.ensure_document_observer_installed() -except Exception: - pass +def _register_exchange_commands(): + try: + ExchangeWriteBack.ensure_document_observer_installed() + except Exception: + pass -try: - ExchangeWriteBack.register_commands() -except Exception: - pass + try: + ExchangeWriteBack.register_commands() + except Exception: + pass -try: - ManualWiring.register_commands() -except Exception: - pass + try: + ManualWiring.register_commands() + except Exception: + pass -try: - TemplateAuthoring.register_commands() -except Exception: - pass + try: + TemplateAuthoring.register_commands() + except Exception: + pass -try: - TemplateAuthoringPanel.register_commands() -except Exception: - pass + try: + TemplateAuthoringPanel.register_commands() + except Exception: + pass + + +class FreeCADExchangeWorkbench(Gui.Workbench): + MenuText = "QET模板" + ToolTip = "QET / FreeCAD 设备模板端子制作工具" + Icon = """ + /* XPM */ + static const char *qet_template_xpm[]={ + "16 16 3 1", + "a c #1f6feb", + "b c #ffffff", + ". c None", + "................", + "...aaaaaaaaaa...", + "..abbbbbbbbba..", + "..abaaaaaabba..", + "..ababbbaabba..", + "..ababbbaabba..", + "..abaaaaaabba..", + "..abbbbbbbbba..", + "..abbaaabbbba..", + "..abbaabababa..", + "..abbaabababa..", + "..abbaaabbbba..", + "..abbbbbbbbba..", + "...aaaaaaaaaa...", + "................", + "................"}; + """ + + def Initialize(self): + _register_exchange_commands() + self.appendToolbar("QET模板", COMMANDS) + self.appendMenu("QET模板", COMMANDS) + _append_init_log("FreeCADExchangeWorkbench initialized") + + def Activated(self): + _register_exchange_commands() + _append_init_log("FreeCADExchangeWorkbench activated") + + def Deactivated(self): + pass +_register_exchange_commands() +Gui.addWorkbench(FreeCADExchangeWorkbench()) QtCore.QTimer.singleShot(0, ExchangeBootstrap.bootstrap_if_requested)