added preferences

fixes #8
This commit is contained in:
Morgan 'ARR\!' Allen 2025-06-10 17:53:30 -07:00
parent 205254a4f3
commit b19c95cd2e
3 changed files with 159 additions and 1 deletions

View file

@ -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")

View file

@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>KiConnect::DlgSettingsKiConnect</class>
<widget class="QWidget" name="KiConnect::DlgSettingsKiConnect">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1151</width>
<height>591</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>1151</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>General</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="defaults_group">
<property name="title">
<string>Defaults</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Default Board Thickness</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefDoubleSpinBox" name="doubleSpinBox">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>1.600000000000000</double>
</property>
<property name="prefEntry" stdset="0">
<cstring>board_thickness</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/KiConnect</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="checkBox">
<property name="text">
<string> Preferences from toolbar</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>Mod/KiConnect</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>prefs_toolbar</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="debug_group">
<property name="title">
<string>Debug and Development</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="Gui::PrefCheckBox" name="check_debug_reload">
<property name="font">
<font>
<pointsize>10</pointsize>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Enable Reload</string>
</property>
<property name="tristate">
<bool>false</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>debug_reload</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/KiConnect</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View file

@ -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)