Turning Zolko's theme in to a Preference Pack

A forum for research and development of the user interface of FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Turning Zolko's theme in to a Preference Pack

Post by Zolko »

chennes wrote: Sun Aug 28, 2022 3:49 pm We could consider adding a dialog when the user actually applies a preference pack, confirming that they want to run the pre and post scripts, if they are present.
please no, that would be like the current trend of cookie "consent", or the previous trend of EULA, that nobody actually reads and blindly approves, but still costs some extra clicks and stress. I think we should reconsider how and what to put inside these PreferencePacks, rather than offload our uncertainties onto the unsuspecting users.
try the Assembly4 workbench for FreCAD — tutorials here and here
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Turning Zolko's theme in to a Preference Pack

Post by Zolko »

Jolbas wrote: Sun Aug 28, 2022 6:06 am Shouldn't those scripts be considered a security risk? It's not obvious to me that a preference pack contains executables.
yes, I think that you're right.

chennes wrote: Sun Aug 28, 2022 12:25 am
Zolko wrote: Sat Aug 27, 2022 3:49 pm Would be quite an ugly hack though
Not at all -- that's exactly the sort of thing that pre.FCMacro and post.FCMacro are intended for.
another solution could be that the positions of the docked widgets and the toolbars is specified as XML data, and the PreferencePack code itself executes the Python code based on the XML data. In this case, the XML data wouldn't be a clone of existing config data, but would still look similar.

Would that be possible ?
try the Assembly4 workbench for FreCAD — tutorials here and here
User avatar
adrianinsaval
Veteran
Posts: 5548
Joined: Thu Apr 05, 2018 5:15 pm

Re: Turning Zolko's theme in to a Preference Pack

Post by adrianinsaval »

Zolko wrote: Mon Aug 29, 2022 10:07 am
Jolbas wrote: Sun Aug 28, 2022 6:06 am Shouldn't those scripts be considered a security risk? It's not obvious to me that a preference pack contains executables.
yes, I think that you're right.
but then so is every addon in existence
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Turning Zolko's theme in to a Preference Pack

Post by Zolko »

drmacro wrote: Sat Aug 27, 2022 5:07 pm
Zolko wrote: Sat Aug 27, 2022 3:49 pm I don't have my computer here : is it possible to control these from the Python console ? If so, we could think about a script to launch after the PreferencePack has been applied.
That's sort of what needs to happen with toolbar placement because of the the way persistent toolbars are handled. I've done it in the post.FCMacro.
I don't find your code for that: could you please point me to where you're doing that stuff ? Also, what is to code to manipulate docked widgets ? So far, I've found the following:

Code: Select all

for widget in Gui.getMainWindow().children()
    ...
which lists all widgets. And :

Code: Select all

Gui.getMainWindow().findChild(QtGui.QWidget,'Combo View')
Gui.getMainWindow().findChild(QtGui.QWidget,'Tree view')
which returns the docked widgets (note the MAJUSCULE and minuscule "V" in the "View" !!!). But I fail to find how to set the docking position of them
try the Assembly4 workbench for FreCAD — tutorials here and here
drmacro
Veteran
Posts: 8979
Joined: Sun Mar 02, 2014 4:35 pm

Re: Turning Zolko's theme in to a Preference Pack

Post by drmacro »

https://github.com/macdroid53/ZolkoBase

The code in post.FCMacro sets only the tool bar positions by setting the Tux group in the persistent toolbar group.

The docking of panels is maintained in FreeCAD.cfg in a QT byte string. I have yet to decide what/how the bytes work.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
MisterMaker
Posts: 744
Joined: Mon Sep 21, 2020 7:41 am
Contact:

Re: Turning Zolko's theme in to a Preference Pack

Post by MisterMaker »

drmacro wrote: Tue Aug 30, 2022 10:59 am https://github.com/macdroid53/ZolkoBase

The code in post.FCMacro sets only the tool bar positions by setting the Tux group in the persistent toolbar group.

The docking of panels is maintained in FreeCAD.cfg in a QT byte string. I have yet to decide what/how the bytes work.
The colors are decimals of RGBA values, I would think the others are too decibels but I have no clue on how to understand them.
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Turning Zolko's theme in to a Preference Pack

Post by Zolko »

Zolko wrote: Tue Aug 30, 2022 7:45 am I fail to find how to set the docking position of them
I found a way to specify and change the docking position in Python :

Code: Select all

from PySide import QtGui, QtCore
mw = Gui.getMainWindow()
tv = Gui.getMainWindow().findChild(QtGui.QWidget,'Tree view')
# then
mw.addDockWidget(QtCore.Qt.LeftDockWidgetArea,tv)
tv.show()
So if we want to make this into a PreferencePack, we need to specify where each docked window shall be as XML data, then apply this code.

It's also possible to save and restore the entire wain window state:

Code: Select all

mw.saveState()
=> PySide2.QtCore.QByteArray(b'\x00\x00\x00\xff\...)
mw.restoreState( QtCore.QByteArray(b'\x00\x00\x00\xff\...) )
In which case we need to store the QByteArray in the PreferencePck itself. This is too much of a black-box for my taste
try the Assembly4 workbench for FreCAD — tutorials here and here
User avatar
chennes
Veteran
Posts: 3906
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Turning Zolko's theme in to a Preference Pack

Post by chennes »

Zolko wrote: Thu Sep 08, 2022 1:46 pm In which case we need to store the QByteArray in the PreferencePck itself. This is too much of a black-box for my taste
I agree, I think your first idea is a good one -- you can just make up some arbitrary preference data for your Addon that specifies the information you need, include it in your preference pack, and then use that data in your post.FCMacro file to actually move those tab bars into the appropriate positions. I think that gives users the best transparency. The alternative is to modify core FreeCAD to support preference-set tab bar positions.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Turning Zolko's theme in to a Preference Pack

Post by Zolko »

chennes wrote: Thu Sep 08, 2022 2:20 pm post.FCMacro file to actually move those tab bars into the appropriate positions
yes, that works ... but not on a new virgin FreeCAD install because the Tree view is not enabled. Even though it's set to enabled in the PreferencePack file. So FreeCAD segfaults. Is there a good reason why the tree view is not enabled by default ?

And this gives the docked window positions, not those of the toolbars.
Attachments
ZolkoPack.zip
(1.63 KiB) Downloaded 24 times
try the Assembly4 workbench for FreCAD — tutorials here and here
User avatar
chennes
Veteran
Posts: 3906
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Turning Zolko's theme in to a Preference Pack

Post by chennes »

Is this line failing (e.g. giving "None")?

Code: Select all

tv = Gui.getMainWindow().findChild(QtGui.QWidget,'Tree view')
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
Post Reply