diff --git a/freecad/kiconnect/init_gui.py b/freecad/kiconnect/init_gui.py index 493dc6f..8ea61c6 100644 --- a/freecad/kiconnect/init_gui.py +++ b/freecad/kiconnect/init_gui.py @@ -19,12 +19,18 @@ TRANSLATIONSPATH = os.path.join(os.path.dirname(__file__), "resources", "transla Gui.addLanguagePath(TRANSLATIONSPATH) Gui.updateLocale() +default_preferences = [ +('Bool', 'debug_reload', True), +('Bool', 'prefs_toolbar', True), +('Float', 'default_thickness', 1.6), +] + class KiConnect(Gui.Workbench): MenuText = translate("Workbench", "KiConnect") ToolTip = translate("Workbench", "KiConnect PCB Workbench") Icon = os.path.join(settings.ICONPATH, "kiconnect.svg") - toolbox = [ 'kiconn_new', 'kiconn_reload', 'kiconn_sync_to', 'kiconn_sync_from' ] + toolbox = [ 'kiconn_new', 'kiconn_sync_to', 'kiconn_sync_from' ] def GetClassName(self): return "Gui::PythonWorkbench" @@ -35,11 +41,24 @@ class KiConnect(Gui.Workbench): here is the place to import all the commands """ + # setup default preferences on first load + if settings.preferences.IsEmpty(): + for pref in default_preferences: + print('setting pref: ', f'Set{pref[0]}', pref[1], pref[2]) + getattr(settings.preferences, f'Set{pref[0]}')(pref[1], pref[2]) + + # add debug reload button if enabled + if settings.preferences.GetBool('debug_reload'): + self.toolbox.append('kiconn_reload') + print('setting up toolbar') # NOTE: Context for this commands must be "Workbench" self.appendToolbar(QT_TRANSLATE_NOOP("Workbench", "KiConnect"), self.toolbox) self.appendMenu(QT_TRANSLATE_NOOP("Workbench", "KiConnect"), self.toolbox) + Gui.addPreferencePage(os.path.join(settings.UIPATH, 'preferences.ui'), 'KiConnect') + + def Activated(self): App.Console.PrintMessage(translate("Log", "Workbench KiConnect activated.") + "\n") diff --git a/freecad/kiconnect/resources/ui/preferences.ui b/freecad/kiconnect/resources/ui/preferences.ui new file mode 100644 index 0000000..bc67141 --- /dev/null +++ b/freecad/kiconnect/resources/ui/preferences.ui @@ -0,0 +1,134 @@ + + + KiConnect::DlgSettingsKiConnect + + + + 0 + 0 + 1151 + 591 + + + + + 1151 + 16777215 + + + + General + + + + + + Defaults + + + Qt::AlignmentFlag::AlignCenter + + + false + + + + + + + + Default Board Thickness + + + + + + + 0.100000000000000 + + + 1.600000000000000 + + + board_thickness + + + Mod/KiConnect + + + + + + + + + Preferences from toolbar + + + true + + + Mod/KiConnect + + + prefs_toolbar + + + + + + + + + + Debug and Development + + + Qt::AlignmentFlag::AlignCenter + + + false + + + + + + + 10 + false + + + + Enable Reload + + + false + + + debug_reload + + + Mod/KiConnect + + + + + + + + + + + Gui::PrefCheckBox + QCheckBox +
Gui/PrefWidgets.h
+
+ + Gui::PrefDoubleSpinBox + QDoubleSpinBox +
Gui/PrefWidgets.h
+
+
+ + +
diff --git a/freecad/kiconnect/settings.py b/freecad/kiconnect/settings.py index fb80af2..0857a8a 100644 --- a/freecad/kiconnect/settings.py +++ b/freecad/kiconnect/settings.py @@ -1,5 +1,10 @@ import os +import FreeCAD as App BOARD_THICKNESS = 0.80 ICONPATH = os.path.join(os.path.dirname(__file__), "resources", 'icons') +UIPATH = os.path.join(os.path.dirname(__file__), "resources", 'ui') KICAD9_3DMODEL_DIR = '/usr/share/kicad/3dmodels/' +PREF_PATH = 'User parameter:BaseApp/Preferences/Mod/KiConnect' + +preferences = App.ParamGet(PREF_PATH)