Persistent toolbars

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Persistent toolbars

Post by triplus »

Starting with FreeCAD 0.17 custom toolbar position configured by the user should now be restored in all workbenches. In addition (optionally) developer now can have more control over default toolbar position in workbench.

Image

Reference:
https://forum.freecadweb.org/viewtopic.php?f=22&t=16954
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Persistent toolbars

Post by DeepSOIC »

since 0.17.10489, to be exact.
Thanks!
triplus wrote:In addition (optionally) developer now can have more control over default toolbar position in workbench.
Can you elaborate on this a little bit? I'm researching how to automate adding a global toolbar from part-o-magic...
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Persistent toolbars

Post by triplus »

DeepSOIC wrote:since 0.17.10489, to be exact.
Thanks!
You're welcome.
triplus wrote:In addition (optionally) developer now can have more control over default toolbar position in workbench.
Can you elaborate on this a little bit?
Here you can find an example for Sketcher workbench:

https://forum.freecadweb.org/viewtopic. ... 20#p164854
I'm researching how to automate adding a global toolbar from part-o-magic...
Well luckily you came to the right place. ;) You actually already use something like that as you use TabBar. And adding global toolbar in FreeCAD isn't all that hard. But when adding commands to the toolbar things can get a bit complicated. Therefore i did a few tests and simply add this to part-o-magic InitGui.py file:

Code: Select all

    def Deactivated(self):
        from PySide import QtGui
        mw = FreeCADGui.getMainWindow()
        mw.findChild(QtGui.QToolBar, "POMContainers").show()
This approach only bypasses FreeCAD toolbar show/hide algorithm slightly. And everything else should continue to work as usual. Note that i only tested the code on Ubuntu and i have seen users reporting some strange toolbar show/hide behaviour on macOS when using Qt 5. Therefore if any changes will be made to FreeCAD toolbar show/hide algorithm in the future above example could start to behave differently.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Persistent toolbars

Post by DeepSOIC »

triplus wrote:

Code: Select all

    def Deactivated(self):
        from PySide import QtGui
        mw = FreeCADGui.getMainWindow()
        mw.findChild(QtGui.QToolBar, "POMContainers").show()
Okay, I'll check what it does. What I've been looking at before was to add some parameters as if user has created a global toolbar:
toolbar-params.png
toolbar-params.png (199.83 KiB) Viewed 3308 times
The up side is user has control over it, the usual way. The downside is that FreeCAD needs to be restarted. So I'll think on which option to choose.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Persistent toolbars

Post by triplus »

First a bit of explanation for anybody reading this thread. Not to get confused on what persistent toolbars should do. Show/hide toolbar algorithm is still provided by FreeCAD as it has always has been (C++). What was missing is saving/restoring toolbar position in all workbenches. Toolbar position was restored (when FreeCAD was started) only in default workbench. Algorithm provided by persistent toolbars (Python) now adds that missing piece and restores toolbar positions in all workbenches.

As for your question @DeepSOIC. On how to add global toolbar to FreeCAD from Python.
DeepSOIC wrote:Okay, I'll check what it does. What I've been looking at before was to add some parameters as if user has created a global toolbar:
Mentioned code i provided doesn't add global toolbar per se. What it does it makes local toolbar from PoM visible in all workbenches. PoM module provides this toolbar therefore PoM workbench must be loaded before the toolbar will be available in all workbenches. Only small amount of bypassing FreeCAD show/hide algorithm happens and therefore everything else still results in standard FreeCAD behaviour.

If you would want to add a real global toolbar. You can look for reference in TabBar on how it can be done. Note that in not that distant future SelectorToolbar module will be made. And the toolbar functionality from TabBar will be moved to it. After you create such toolbar it will be available on FreeCAD start. You would need to search for corresponding commands manually and add them to the toolbar yourself. PoM module would still needed to be loaded first. As it provides the commands or the toolbar would end up being empty until PoM module would be loaded or some bypassing would happen for the commands on FreeCAD start. On every workbench change you need to clear the toolbar and add the commands. And from good integration point of view small amount of toolbar flickering could happen when workbench changes (i am still searching for sensible solution to be used for SelectorToolbar purposes).
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Persistent toolbars

Post by triplus »

I checked what you are doing with PoM. And as you are already bypassing FreeCAD by directly importing PoM commands in InitGui.py this is basically the missing piece you need. To add global PoM toolbar with PoM related commands on it (FreeCAD manages the result therefore no potential issues mentioned earlier apply):

Code: Select all

import FreeCAD

path = "User parameter:BaseApp/Workbench/Global/Toolbar/PoM"
p = FreeCAD.ParamGet(path)
p.SetString("Name", "PoM")
p.SetString("PartOMagic_Module", "FreeCAD")
p.SetBool("Active", 1)
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Persistent toolbars

Post by DeepSOIC »

I feel that if I procrastinate just a bit more, you will come with a pull request :mrgreen: Sorry for hijacking the thread :oops:
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Persistent toolbars

Post by triplus »

DeepSOIC wrote:I feel that if I procrastinate just a bit more, you will come with a pull request :mrgreen:
Well i guess i could couldn't i. :lol: Give me a few hours and i will do it (edit: done).
Sorry for hijacking the thread :oops:
As long as the resulting toolbar will keep user set workbench specific position i am fine with that. ;)
Post Reply