Trigger UI update after programmatic UI changes

A forum for research and development of the user interface of FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Trigger UI update after programmatic UI changes

Post by drmacro »

@chennes

It appears the position of toolbars is stored in the parameter config in "Tux>PersistentToolbars>... per workbench when the toolbar position is changed.

But, when it is changed via macro, the UI doesn't update until FC is restarted.

For instance I am setting the appropriate values in Tux to have the File toolbar be on the left in a post.FCMacro in a pref pack. But, it doesn't change when the pack is applied. (Other pack settings do, for instance the stylesheet and activating the report view and python console.)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
chennes
Veteran
Posts: 3877
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Trigger UI update after programmatic UI changes

Post by chennes »

That has to do with how exactly those things are handled within the code: many settings are only read in at the time they are needed, and are not re-examined later (or watched for changes) by the handling code. For example, just changing the stored recent files list is not enough to trigger the menu to get rebuilt. I don't know how to trigger the toolbar code to re-read its settings, but you could look at ToolBarManager, which provides a "restoreState" function. I don't think those functions are directly exposed to Python -- I don't know if that is a deliberate design decision, or just something that we haven't gotten around to.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: Trigger UI update after programmatic UI changes

Post by drmacro »

chennes wrote: Sat Aug 20, 2022 10:39 pm That has to do with how exactly those things are handled within the code: many settings are only read in at the time they are needed, and are not re-examined later (or watched for changes) by the handling code. For example, just changing the stored recent files list is not enough to trigger the menu to get rebuilt. I don't know how to trigger the toolbar code to re-read its settings, but you could look at ToolBarManager, which provides a "restoreState" function. I don't think those functions are directly exposed to Python -- I don't know if that is a deliberate design decision, or just something that we haven't gotten around to.
Is it possible to flag the restart process that is seen when Addon manager installs/updates a workbench?
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
chennes
Veteran
Posts: 3877
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Trigger UI update after programmatic UI changes

Post by chennes »

You can see the code that does it here: https://github.com/FreeCAD/FreeCAD/blob ... es.py#L106
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: Trigger UI update after programmatic UI changes

Post by drmacro »

chennes wrote: Sat Aug 20, 2022 11:31 pm You can see the code that does it here: https://github.com/FreeCAD/FreeCAD/blob ... es.py#L106
Every workbench calls that? Or does the Addon manager call that when a workbench is installed and the user closes the Addon dialog?
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
chennes
Veteran
Posts: 3877
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Trigger UI update after programmatic UI changes

Post by chennes »

That's the code the Addon Manager uses to actually restart FreeCAD -- the new workbenches don't really "exist" yet as far as FreeCAD is concerned. So it's not something a WB does, it's something the AM does.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: Trigger UI update after programmatic UI changes

Post by drmacro »

chennes wrote: Sun Aug 21, 2022 5:27 am That's the code the Addon Manager uses to actually restart FreeCAD -- the new workbenches don't really "exist" yet as far as FreeCAD is concerned. So it's not something a WB does, it's something the AM does.
Right, so what tells AM that it should pop the restart dialog?

I also realized I was thinking about the wrong point in the process anyway.

What I really want is when a PP is applied to tell the user to see all the changes they need to restart.

Could I pop a dialog from the post.FCMacro?

Speaking of pre and post .FCMacro, can they be .py ?
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: Trigger UI update after programmatic UI changes

Post by drmacro »

@chennes

I deleted my earlier post about this because it looked something I did fixed it...

But, for some reason the PP shows up in AM as in All.

And, when a change is pushed to github, "blob" is added to the url and it can't read the README.

It shows fine in Preferences PP though.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
chennes
Veteran
Posts: 3877
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Trigger UI update after programmatic UI changes

Post by chennes »

drmacro wrote: Sun Aug 21, 2022 10:47 am Right, so what tells AM that it should pop the restart dialog?
When it installs or updates a workbench, it sets an internal flag to True. Then, when you close the AM, it sees that flag and pops open a dialog. That dialog's OK button triggers a 1 second timer that then triggers the restart using the code I linked.
Could I pop a dialog from the post.FCMacro?
Yes, that's where I'd do it.
Speaking of pre and post .FCMacro, can they be .py ?
You mean the extension? No, the code only looks for .FCMacro. That would be easy to change, of course.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
chennes
Veteran
Posts: 3877
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Trigger UI update after programmatic UI changes

Post by chennes »

drmacro wrote: Sun Aug 21, 2022 2:15 pm And, when a change is pushed to github, "blob" is added to the url and it can't read the README.
The "blob" is the rendered version of the README, it's supposed to do that. You can take a look at the ProDark preference pack to see what its supposed to look like.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
Post Reply