[MERGED] Ticket #4474 - [FR] Ghost tabs within Preferences dialog to indicate menus that are available but not activated

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
User avatar
Kunda1
Posts: 10398
Joined: Thu Jan 05, 2017 9:03 pm

[MERGED] Ticket #4474 - [FR] Ghost tabs within Preferences dialog to indicate menus that are available but not activated

Postby Kunda1 » Tue Oct 20, 2020 12:35 am

In a recent thread an idea occurred to me as a workaround. First the thread is wmayer helping a user locate a setting in dialog menu that is missing in Preferences because the workbench it's associated with has not been preloaded:
wmayer wrote: Mon Oct 19, 2020 3:49 pm There is an independent setting used for mesh export. You will find it in the preferences under Import/Export -> Mesh formats. In order to show this tab you must have loaded the Mesh workbench beforehand.
So my idea is to have a 'ghost' inactive tab (a placeholder if you will) of each workbench available in FreeCAD core but has not been activated. If the user so chooses then upon clicking said inactive workbench tab, it is then loaded and the menu becomes accessible. This then informs the user of other capabilities of FreeCAD while simultaneously educates them about a fundamental aspect of workbenches requiring to be loaded in order to access their settings. 2 birds, 1 stone (lacking a less morbid analogy).

Thoughts?
Last edited by Kunda1 on Thu Feb 04, 2021 8:43 pm, edited 2 times in total.
Reason: [MERGED]
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
wmayer
Site Admin
Posts: 17301
Joined: Thu Feb 19, 2009 10:32 am

Re: [Feature Discussion] Ghost tabs within Preferences dialog to indicate menus that are available but not activated

Postby wmayer » Tue Oct 20, 2020 8:26 am

I have thought about something similar. So, the idea is to register a ghost tab in the InitGui.py file and as soon as the user activates it we load the module in the background. This however is a bit tricky to implement I guess.

In some simple cases where the preferences page only reads and writes settings from/to the user parameters but doesn't do anything else we can implement something much simpler: The .ui file can be added to a resource file which at build time will be converted into a qrc_something.py file which can be imported from within the InitGui.py file. This way the tab can be shown directly and is functional without loading the actual workbench module.
User avatar
Kunda1
Posts: 10398
Joined: Thu Jan 05, 2017 9:03 pm

Re: [Feature Discussion] Ghost tabs within Preferences dialog to indicate menus that are available but not activated

Postby Kunda1 » Tue Oct 20, 2020 10:39 am

wmayer wrote: Tue Oct 20, 2020 8:26 am In some simple cases where the preferences page only reads and writes settings from/to the user parameters but doesn't do anything else we can implement something much simpler: The .ui file can be added to a resource file which at build time will be converted into a qrc_something.py file which can be imported from within the InitGui.py file. This way the tab can be shown directly and is functional without loading the actual workbench module.
Nice! Great to know that there is a practical way to achieve this, although just for simple operations.
Not to get too ahead of ourselves, but at some point it would be great to understand what a workaround for the more 'expensive' preferences. Could we label them in a way that indicates to the user that they require exiting Preferences and loading the workbench manually in order to see the full preference option list of said workbench ?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
wmayer
Site Admin
Posts: 17301
Joined: Thu Feb 19, 2009 10:32 am

Re: [Feature Discussion] Ghost tabs within Preferences dialog to indicate menus that are available but not activated

Postby wmayer » Tue Oct 20, 2020 12:17 pm

Could we label them in a way that indicates to the user that they require exiting Preferences and loading the workbench manually in order to see the full preference option list of said workbench ?
Not really. The preferences pages are handled in the core system but it doesn't know anything about which extension modules are available and thus can't tell the user what actions are needed. What the core system knows are workbench handlers (these are Python classes that implement a certain interface) that are registered at program start.

An easy (but dumb) approach could be to add a further (optional) function that must load the needed Python module(s). Then when opening the preferences we iterate over all these handlers and invoke this function if available.
This way all modules and their tabs will be loaded but the first time when opening the preferences the UI might be blocked for some time.
User avatar
Kunda1
Posts: 10398
Joined: Thu Jan 05, 2017 9:03 pm

Re: [Feature Discussion] Ghost tabs within Preferences dialog to indicate menus that are available but not activated

Postby Kunda1 » Wed Oct 21, 2020 1:45 pm

wmayer wrote: Tue Oct 20, 2020 12:17 pm An easy (but dumb) approach could be to add a further (optional) function that must load the needed Python module(s). Then when opening the preferences we iterate over all these handlers and invoke this function if available.
This way all modules and their tabs will be loaded but the first time when opening the preferences the UI might be blocked for some time.
Can we use a LazyLoader approach ?
Extra_python_modules#LazyLoader
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
wmayer
Site Admin
Posts: 17301
Joined: Thu Feb 19, 2009 10:32 am

Re: [Feature Discussion] Ghost tabs within Preferences dialog to indicate menus that are available but not activated

Postby wmayer » Wed Oct 21, 2020 2:06 pm

No. The LazyLoader module is only helpful to delay the loading or to avoid to even load it if none of its functions is used. But for the pref pages the module always must be loaded and delaying it doesn't help.
User avatar
Kunda1
Posts: 10398
Joined: Thu Jan 05, 2017 9:03 pm

Re: Ticket #4474 - [FR] Ghost tabs within Preferences dialog to indicate menus that are available but not activated

Postby Kunda1 » Sun Oct 25, 2020 2:56 pm

Created issue #4474 to track this FR

Edit: this issue is related to 3498 as well.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
chennes
Posts: 862
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Ticket #4474 - [FR] Ghost tabs within Preferences dialog to indicate menus that are available but not activated

Postby chennes » Mon Dec 21, 2020 4:15 am

Kunda1 wrote: Sun Oct 25, 2020 2:56 pm Edit: this issue is related to 3498 as well.
I actually started from the discussion of 3498(@Kunda1, you ended up with a wiki link...) and was poking around at these ideas tonight. I took a simple (probably stopgap) approach: I've implemented a single additional Preferences tab that looks like this:
LazyPrefs.PNG
LazyPrefs.PNG (85.21 KiB) Viewed 377 times
You can select workbenches there and tell them to load. Which would be great, except I can't figure out how to reload the Preferences dialog from inside the preferences dialog! So you have to manually close it and open it again, which is stupid. So if anyone has any suggestion for how to do that, it would be much appreciated.

I have mixed feelings about this approach. On the one hand, it is minimally invasive. It doesn't require workbench authors to do anything, doesn't mess around with any other FreeCAD code, and simply explains to users what they are seeing. It also doesn't clutter up the preferences dialog with a bunch of workbenches you might not ever use. (OK, yes, I need to make an Icon for its group, it's pretty ugly right now!)

I think in an ideal world preferences would be something that a Workbench could deliver on-demand without loading the whole bench. Then when the preferences dialog launches the first time we could just iterate over all the workbenches that are registered but not loaded yet and ask them to insert their pages. We could even get really "lazy" and actually only ask the workbenches to pre-register the names of their groups, pages, and group icons. Then we could ask the bench to deliver the actual page content only if the user actually clicks on it. But that might be a bit overkill, I don't know if it's really necessary to be that stingy with resource usage, as long as we can implement the preferences without loading the entire workbench.
Chris Hennes
Pioneer Library System
User avatar
Kunda1
Posts: 10398
Joined: Thu Jan 05, 2017 9:03 pm

Re: Ticket #4474 - [FR] Ghost tabs within Preferences dialog to indicate menus that are available but not activated

Postby Kunda1 » Mon Dec 21, 2020 7:18 pm

chennes wrote: Mon Dec 21, 2020 4:15 am I took a simple (probably stopgap) approach: I've implemented a single additional Preferences tab that looks like this:
Thank you for pushing this topic a few more kilometers. I grok your approach. It at least gives the user a heads up that there are some hoops jump through in order to achieve what they think should be intuitive "Hey where are the TechDraw preferences?!? 🤬"
So FWIW, I +1 this.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
chennes
Posts: 862
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Ticket #4474 - [FR] Ghost tabs within Preferences dialog to indicate menus that are available but not activated

Postby chennes » Mon Dec 21, 2020 10:53 pm

chennes wrote: Mon Dec 21, 2020 4:15 am You can select workbenches there and tell them to load. Which would be great, except I can't figure out how to reload the Preferences dialog from inside the preferences dialog! So you have to manually close it and open it again, which is stupid.
OK, I wrote the code to deal with this -- it was significantly more challenging than expected (wow, that never happens! :roll: ). I still need to make an icon for it, and handle the case of pages being removed.

My strategy here was to have the class keep track of its instance (if there is one), and to have the static addPages() and removePages() functions explicitly tell the instance if the page list changed. For now I think the only reason those lists would change is because my new preferences page causes it, but in principle there is no reason that some external code might not run that causes the available preferences to change while the dialog is open. So this will just naturally handle that if it ever happens.

With regards to pages being removed: when does it happen? I don't really have a good test case for it.
Chris Hennes
Pioneer Library System