Where to find documentation on setting up preferences for a workbench.

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Where to find documentation on setting up preferences for a workbench.

Post by keithsloan52 »

Where can I find documentation on setting up and using a preference dialog for a workbench.

Thanks
User avatar
yorik
Founder
Posts: 13664
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Where to find documentation on setting up preferences for a workbench.

Post by yorik »

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
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Where to find documentation on setting up preferences for a workbench.

Post by Kunda1 »

#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
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Where to find documentation on setting up preferences for a workbench.

Post by keithsloan52 »

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.

Code: Select all

FreeCADGui.addPreferencePage(":/ui/openscadprefs-base.ui","OpenSCAD")
Also tried with

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
Why does my cheat not work?
User avatar
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.

Post by wandererfan »

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")
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
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Where to find documentation on setting up preferences for a workbench.

Post by keithsloan52 »

wandererfan 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.
No, so I have now changed InitGui.py to

Code: Select all

FreeCADGui.addPreferencePage(FreeCAD.getResourceDir() + \
                    "Mod/Resources/ui/openscadprefs-base.ui","OpenSCAD")
But it still cannot find
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Where to find documentation on setting up preferences for a workbench.

Post by keithsloan52 »

Okay I have setup the following in Resources/GDML.qrc

Code: Select all

<RCC>
    <qresource>
       <file>ui/openscadprefs-base.ui</file>
       <file>ui/GDML-base.ui</file>
    </qresource>
</RCC>
My InitGui.py has

Code: Select all

FreeCADGui.addPreferencePage(":/ui/openscadprefs-base.ui","OpenSCAD")
But still cannot find.

How does FreeCAD know to use GDML.qrc?
User avatar
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.

Post by wandererfan »

keithsloan52 wrote: Tue Jun 18, 2019 5:59 pm How does FreeCAD know to use GDML.qrc?
I knew I had written it down somewhere....

Preferences for Add-on Modules
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Where to find documentation on setting up preferences for a workbench.

Post by Kunda1 »

wandererfan wrote: Tue Jun 18, 2019 8:20 pm Preferences for Add-on Modules
#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
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Where to find documentation on setting up preferences for a workbench.

Post by keithsloan52 »

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
Post Reply