How to set my preferences panel ?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
lainegates
Posts: 216
Joined: Tue Oct 02, 2012 7:29 am

How to set my preferences panel ?

Postby lainegates » Tue Mar 26, 2013 11:08 am

In FreeCAD , if I select a workbench , for example , 'Part' workbench' , then I could find 'Part design' in 'Edit->Preferences' .
My project also have many parameters to set , and I want to set up my own preferences panel .
So , how to set up my own perferences panel ?
User avatar
yorik
Site Admin
Posts: 12145
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

Re: How to set my preferences panel ?

Postby yorik » Tue Mar 26, 2013 12:32 pm

You must first design a preferences UI page with Qtdesigner. For that you must compile the FreeCAD Qtdesigner plugin (see compile instructions on the wiki). Then you can build a page and add your UI controls (take one of the existing ones as model, for example src/Mod/Draft/Resources/ui/*). Each control from the freecad qt plugin can control a preference setting (you must set the path to the property correctly in the control properties). Then you must make your page known to freecad in your workbench initgui.py file (see Draft for an example). Finally, you must provide a "preferences-yourmodulename.svg" icon that will appear in the preferences screen.

Then you have another system for reading and setting those preferences via python. Look in Draft.py, at the beginning of the file you'll see the whole system to do that.
lainegates
Posts: 216
Joined: Tue Oct 02, 2012 7:29 am

Re: How to set my preferences panel ?

Postby lainegates » Tue Mar 26, 2013 1:27 pm

thank you , yorikvanhavre .
lainegates
Posts: 216
Joined: Tue Oct 02, 2012 7:29 am

Re: How to set my preferences panel ?

Postby lainegates » Tue Apr 09, 2013 1:50 pm

I have QtDesigner installed , and designed my UI done .
Refering to "userprefs-base.ui" of Draft , I add properties : "prefPath" and "prefEntry" to QSpinBox to get value, and add "color" , "prefPath" and "prefEntry" to QPushbutton to select color .
The question comes , in Draft workbench , the following code is used :

Code: Select all

p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
if t == "int": return p.GetInt(param)
elif t == "string": return p.GetString(param)
...

for QSpinBox , I could understand , use obj.getValue() to get value , but for QPushbutton , how does the FreeCAD know to get the property "color" newly added ?
User avatar
yorik
Site Admin
Posts: 12145
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

Re: How to set my preferences panel ?

Postby yorik » Tue Apr 09, 2013 3:59 pm

Colors are stored as unsigned ints. You must "decompose" that value into a rgb color value like this:

Code: Select all

p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/MyMod")
c = p.GetUnsigned("MyColor")
r = float((c>>24)&0xFF)/255.0
g = float((c>>16)&0xFF)/255.0
b = float((c>>8)&0xFF)/255.0
result = (r,g,b,1.0)
lainegates
Posts: 216
Joined: Tue Oct 02, 2012 7:29 am

Re: How to set my preferences panel ?

Postby lainegates » Wed Apr 10, 2013 4:30 am

In QtCreator , I add a QPushbutton to the UI widget , and then I added 3 properties "color" , "prefPath" and "prefEntry" to the button whose value are ( 255 , 0 , 0) , 'Mod/MyBench' and 'mycolor'
then I tried the code

Code: Select all

p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/MyMod")
print p.GetUnsigned("MyColor")    # result is 0
but I got 0 . What is the problem ?

then I check 'userprefs-base.ui' of Draft , I saw that buttons of the ui file were kind of 'Gui::PrefColorButton‘ , Is this the reason ?

And I read your reply again , you told me to recompile FreeCAD Qtdesigner plugin , but where was the plugin , I didn't saw it in http://www.freecadweb.org/wiki/index.ph ... =Main_Page .

Do I need to compile FreeCAD to realize the preference page ?
User avatar
yorik
Site Admin
Posts: 12145
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

Re: How to set my preferences panel ?

Postby yorik » Wed Apr 10, 2013 11:21 am

Aah I understand now... You didn't use the qtdesigner plugin.

You must absolutely use it to produce preferences pages, the standard qt widgets can't change freecad properties.
http://www.freecadweb.org/wiki/index.ph ... ner_plugin
User avatar
wandererfan
Posts: 4078
Joined: Tue Nov 06, 2012 5:42 pm

Re: How to set my preferences panel ?

Postby wandererfan » Wed Apr 10, 2013 2:08 pm

yorikvanhavre wrote:Aah I understand now... You didn't use the qtdesigner plugin.

You must absolutely use it to produce preferences pages, the standard qt widgets can't change freecad properties.
http://www.freecadweb.org/wiki/index.ph ... ner_plugin
I recently did this for Draft.ShapeString. There are some pitfalls to avoid:
- the instructions are in the "autotools" section, but you don't actually use "autotools", just QMake and make.
- building libFreeCAD_widgets.so from your source directory will mess up your git staging. If you can figure out how to build it in your build directory or just in a copy of your source directory, you will save some work.
- $QTDIR/plugin/designer is hard to find. It wasn't defined in my system and it isn't obvious from the Qt Designer docs. I put the library in /usr/lib/qt4/plugins with a symlink from /usr/share/qt4/plugins and it worked.
- the Draft Preferences panel is really crowded in Qt Designer. I had to struggle a bit to fit a new widget in so it displayed properly.

wf
lainegates
Posts: 216
Joined: Tue Oct 02, 2012 7:29 am

Re: How to set my preferences panel ?

Postby lainegates » Thu Apr 11, 2013 2:06 pm

thank you , yorikvanhavre and wandererfan , I will try.
lainegates
Posts: 216
Joined: Tue Oct 02, 2012 7:29 am

Re: How to set my preferences panel ?

Postby lainegates » Fri Apr 12, 2013 4:06 pm

I compiled FreeCAD_widgets.dll and FreeCAD_widgets.lib successfully .
I copied the files to $QTDIR/plugins/designer and $PyQt4/plugins/designer

I am using the 'promotion' function of QtDesigner for the first time , I searched google for help , but there are still 3 questions :

1:if I wirte all the project in C++ with qt , then according to the .pro file , the customed widget will be compiled correctly . But now I just write .qrc file ,which contains a .ui file . Does it do any help that I copied FreeCAD_widgets.dll and FreeCAD_widgets.lib to $QTDIR/plugins/designer

2:I convert the .qrc file to python with pyrcc4.exe , that is to say , I compile the .qrc file with python , does this mean that I should copy FreeCAD_widgets.dll and FreeCAD_widgets.lib to $PyQt4/plugins/designer ? If the answer is yes , the third question comes

3:In the QtDesigner , I saw that in 'Promotion' operation , the header file is Gui/Widgets.h , but the path and file is unknown to pyrcc4.exe , and what I compiled is 'FreeCAD_source/src/Tools/plugins/widgets' , not 'FreeCAD_source/src/Gui' . Should I change the header file reference to 'Tools/plugins/widgets/customwidgets.h' ? And then For that .qrc file doesn't show the path to header file and .cpp file , what should I do to make pyrcc4.exe know the path ?