Where to find documentation on setting up preferences for a workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Veteran
- Posts: 2764
- Joined: Mon Feb 27, 2012 5:31 pm
Where to find documentation on setting up preferences for a workbench.
Where can I find documentation on setting up and using a preference dialog for a workbench.
Thanks
Thanks
Re: Where to find documentation on setting up preferences for a workbench.
Quick headstart:
- You need to compile the Qt designer plugin that allows you to add preference settings with Qt Designer (only Qt4 I think) https://www.freecadweb.org/wiki/Compile ... ner_plugin
- Create a blank widget in Qt Designer (no buttons or anything)
- Design your preference page, any setting that must be saved (preferences) must be one if the Gui::Pref* widgets that were added by the plugin)
- In any of those, make sure you fill the PrefName (the name of your preference value) and PrefPath (ex: Mod/MyWorkbenchName), which will save your value under BaseApp/Preferences/Mod/MyWorkbebchName
- Save the ui file in your workbench, make sure it's handled by cmake
- In your workbench, for ex. inside the InitGui file, inside the Initialize method (but any other place works too), add: FreeCADGui.addPreferencePage("/path/to/myUiFile.ui","MyGroup"), "MyGroup" being one of the preferences groups on the left. FreeCAD will automatically look for a "preferences-mygroup.svg" file in its known locations (which you can extend with FreeCADGui.addIconPath())
- Make sure the addPreferencePage() method is called only once, otherwise your pref page will be added several times
- You need to compile the Qt designer plugin that allows you to add preference settings with Qt Designer (only Qt4 I think) https://www.freecadweb.org/wiki/Compile ... ner_plugin
- Create a blank widget in Qt Designer (no buttons or anything)
- Design your preference page, any setting that must be saved (preferences) must be one if the Gui::Pref* widgets that were added by the plugin)
- In any of those, make sure you fill the PrefName (the name of your preference value) and PrefPath (ex: Mod/MyWorkbenchName), which will save your value under BaseApp/Preferences/Mod/MyWorkbebchName
- Save the ui file in your workbench, make sure it's handled by cmake
- In your workbench, for ex. inside the InitGui file, inside the Initialize method (but any other place works too), add: FreeCADGui.addPreferencePage("/path/to/myUiFile.ui","MyGroup"), "MyGroup" being one of the preferences groups on the left. FreeCAD will automatically look for a "preferences-mygroup.svg" file in its known locations (which you can extend with FreeCADGui.addIconPath())
- Make sure the addPreferencePage() method is called only once, otherwise your pref page will be added several times
Re: Where to find documentation on setting up preferences for a workbench.
#documentation
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
-
- Veteran
- Posts: 2764
- Joined: Mon Feb 27, 2012 5:31 pm
Re: Where to find documentation on setting up preferences for a workbench.
Thanks @Yorik
I have tried to cheat as I don't really want to have to build a FreeCAD system and FreeCAD daily uses Qt5 and you mention Qt4.
Plus happy to hand edit the UI xml file. Plus confused when trying to use QtCreator
I tried coping the ui file from OpenSCAD to ~/FreeCAD_Python_GDML/Mod/Resources/ui and did the same add as OpenSCAD i.e.
Also tried with
But when I run I get
Why does my cheat not work?
I have tried to cheat as I don't really want to have to build a FreeCAD system and FreeCAD daily uses Qt5 and you mention Qt4.
Plus happy to hand edit the UI xml file. Plus confused when trying to use QtCreator
I tried coping the ui file from OpenSCAD to ~/FreeCAD_Python_GDML/Mod/Resources/ui and did the same add as OpenSCAD i.e.
Code: Select all
FreeCADGui.addPreferencePage(":/ui/openscadprefs-base.ui","OpenSCAD")
Code: Select all
FreeCADGui.addPreferencePage(FreeCAD.getResourceDir() + \
"Mod/Resources/ui/GDML-base.ui","GDML")
But when I run I get
Code: Select all
UI file does not exist
Traceback (most recent call last):
File "<string>", line 68, in Initialize
- wandererfan
- Veteran
- Posts: 6320
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: Where to find documentation on setting up preferences for a workbench.
Did you add an entry for xxx.ui to the qrc file in "FreeCAD_Python_GDML/Mod/Resources"? ":/ui/..." means look in the "compiled" resource file.keithsloan52 wrote: ↑Tue Jun 18, 2019 11:10 am I tried coping the ui file from OpenSCAD to ~/FreeCAD_Python_GDML/Mod/Resources/ui and did the same add as OpenSCAD i.e.Code: Select all
FreeCADGui.addPreferencePage(":/ui/openscadprefs-base.ui","OpenSCAD")
-
- Veteran
- Posts: 2764
- Joined: Mon Feb 27, 2012 5:31 pm
Re: Where to find documentation on setting up preferences for a workbench.
No, so I have now changed InitGui.py towandererfan wrote: ↑Tue Jun 18, 2019 12:17 pm Did you add an entry for xxx.ui to the qrc file in "FreeCAD_Python_GDML/Mod/Resources"? ":/ui/..." means look in the "compiled" resource file.
Code: Select all
FreeCADGui.addPreferencePage(FreeCAD.getResourceDir() + \
"Mod/Resources/ui/openscadprefs-base.ui","OpenSCAD")
-
- Veteran
- Posts: 2764
- Joined: Mon Feb 27, 2012 5:31 pm
Re: Where to find documentation on setting up preferences for a workbench.
Okay I have setup the following in Resources/GDML.qrc
My InitGui.py has
But still cannot find.
How does FreeCAD know to use GDML.qrc?
Code: Select all
<RCC>
<qresource>
<file>ui/openscadprefs-base.ui</file>
<file>ui/GDML-base.ui</file>
</qresource>
</RCC>
Code: Select all
FreeCADGui.addPreferencePage(":/ui/openscadprefs-base.ui","OpenSCAD")
How does FreeCAD know to use GDML.qrc?
- wandererfan
- Veteran
- Posts: 6320
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: Where to find documentation on setting up preferences for a workbench.
Re: Where to find documentation on setting up preferences for a workbench.
#documentation
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
-
- Veteran
- Posts: 2764
- Joined: Mon Feb 27, 2012 5:31 pm
Re: Where to find documentation on setting up preferences for a workbench.
Okay trying to follow https://www.forum.freecadweb.org/viewto ... 22&t=30336
When it says "in the main *.py directory, run pyside-rcc -o myResources.py myqrc.qrc"
By main *.py directory does it mean the workbench's Mod directory where most of the ,py code is?
I default to looking at the OpenSCAD workbench as my goto for developing a workbench, it has the qrc
file in ~/FreeCAD_sf_master/src/Mod/OpenSCAD/Resources. Do the above instructions assume that the qrc
file is also in the Mod directory?
Thanks
When it says "in the main *.py directory, run pyside-rcc -o myResources.py myqrc.qrc"
By main *.py directory does it mean the workbench's Mod directory where most of the ,py code is?
I default to looking at the OpenSCAD workbench as my goto for developing a workbench, it has the qrc
file in ~/FreeCAD_sf_master/src/Mod/OpenSCAD/Resources. Do the above instructions assume that the qrc
file is also in the Mod directory?
Thanks