Persistent toolbars

Info about new implemented features, classes, modules or APIs. Might get technical!
triplus
Posts: 4995
Joined: Mon Dec 12, 2011 4:45 pm

Persistent toolbars

Postby triplus » Fri Mar 17, 2017 10:01 pm

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
DeepSOIC
Posts: 4689
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Persistent toolbars

Postby DeepSOIC » Fri Mar 17, 2017 10:24 pm

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
Posts: 4995
Joined: Mon Dec 12, 2011 4:45 pm

Re: Persistent toolbars

Postby triplus » Fri Mar 17, 2017 11:53 pm

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.
DeepSOIC
Posts: 4689
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Persistent toolbars

Postby DeepSOIC » Sat Mar 18, 2017 1:11 am

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 517 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
Posts: 4995
Joined: Mon Dec 12, 2011 4:45 pm

Re: Persistent toolbars

Postby triplus » Sat Mar 18, 2017 1:30 pm

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
Posts: 4995
Joined: Mon Dec 12, 2011 4:45 pm

Re: Persistent toolbars

Postby triplus » Sat Mar 18, 2017 3:01 pm

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)
DeepSOIC
Posts: 4689
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Persistent toolbars

Postby DeepSOIC » Sat Mar 18, 2017 3:15 pm

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
Posts: 4995
Joined: Mon Dec 12, 2011 4:45 pm

Re: Persistent toolbars

Postby triplus » Sat Mar 18, 2017 3:32 pm

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. ;)