Page MenuHome

Per workspace UI filtering
ClosedPublic

Authored by Campbell Barton (campbellbarton) on Feb 23 2018, 12:31 PM.

Details

Summary

This patch supports per-workspace filtering of: Panels, Menus, Keymaps & Manipulators, so a workspace can be set to only show certain add-ons.

  • The tags used for filtering are arbitrary, for now the convention of matching add-on names is used.
  • Each menu/panel/keymap can only have a single tag.
  • Using the filter is optional (a workspace may show all enabled addons).
  • Ignore changes to addon_utils.py and bpy_types.py, this just simulates addon authors using bl_ui_tag in their classes (to help test the patch).
  • Eventually filtering could use a GSet (for runtime), for now don't think its needed.

To use this feature:

  • In the workspace buttons enable "Show/Hide Add-Ons"
  • Expand the panel and select addons to use for the current workspace.

To avoid having to patch many addons only for the purpose of testing this patch, I've added a hack that adds tags to all addons classes. This should be removed and instead addon authors must put bl_ui_tag = __package__ in their classes.

Diff Detail

Repository
rB Blender

Event Timeline

Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)

Can this be done without need to patch all the addons? Like, by default consider they match all the tags?

source/blender/blenkernel/BKE_screen.h
268 ↗(On Diff #10064)

BKE_ST_MAXNAME instead of 64?

Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)

Improve UI, move addon toggles to the workspace panel.

Also free tags

Campbell Barton (campbellbarton) marked an inline comment as done.
  • Use BKE_ST_MAXNAME define

Can this be done without need to patch all the addons? Like, by default consider they match all the tags?

If the addon developers do nothing, the add-ons will always show, since - like Blender's panels, they have no ui_tag.
We could leave this as-is and only have intrusive add-ons used this feature (for e.g. this isn't especially helpful for exporters that only add a single menu item).

We could try having something like the hack in this patch implemented a little more nicely although I don't really like meddling with classes automatically based on a global state - it will backfire if an addon imports classes from another add-on, we can try workaround by detecting class modules, but this feels a bit weak.

Having to modify addons might not be so bad. Since it's quite common for UI heavy addons to share a base class with a generic poll function / space type, this can include a ui_tag too.

I am completely lost now. There is no "Use Tags" in workspace, there is no "Use tags" in addons settings, and no tags control in the addon properties. So how does it work now?

@Sergey Sharybin (sergey) there is a 'use_tags' in workspace, with its new panel in buttons, if I can still read code correctly…

@Campbell Barton (campbellbarton) Patch globally looks OK to me. Only thing I find a tad disappointing is the limitation to a single tag per UI item (panel, menu, etc.).

In my understanding, tags would be used to much more than 'just' filtering addons per workspaces, they could also filtering different levels of complexity (e.g. an addon - or even own UI and operators - could define different panels for an 'advanced' and a 'beginner' UI, a same addon could define different parts of itself for different types of data and/or workflows, etc.). That would imho imply that a single panel could have several tags (e.g. `{'ADVANCED', 'MESH', 'MY_ADDON', 'NORMALS_EDITING'} for a panel regrouping advanced tools in mesh editing). One could of course add a all this as a single super-specialized tag, but…

I guess we can extend current code to that later though, if/when needed.

As I understand it, the idea is that users can create workspaces and choose which addons they want in each.

With that in mind, I don't really understand why this uses generic tags. If we want to have a UI where users can reliably select an addon to be part of some workspaces, then all the panels and menus of that addon must have a the tag equal to the addon name, otherwise that UI breaks. So to me it seems more logical to explicitly name this bl_addon or bl_owner or something, not a tag.

If we want some kind of grouping of addons or automatic matching with workspaces, it seems better to define tags in the addon bl_info.

As for the add-ons side, I think that the concept of the filtering location and what is supported (one workspace or multiple ones) for individual add-ons is more important than the concrete default way.

There is already the panel location altering code for the Toolbar region like in T50726. Things can be more automated there too as it needs preferences defined and adds boiler plate code to each add-on, but it can be looked as a proof of concept for add-on makers for something similar - depending of what is allowed by the API. Like a dropdown list of workspaces in add-on preferences :)

I tested with my own addon (Object Collections) and it worked fine, nice work. However I could not disable the OBJ i/o.

As for UI, shouldn't we disable the list of Addons when use_ui_tags is False?
Also If we are to keep the name Show/Hide Add-On's it should at least be Show/Hide Add-ons. That said I think it may be better to call it Filter Add-ons.

Filter manipulator groups

  • Grey out addons list when tags arent active
  • Currently each UI element has a single identifier, this is only using the add-on name by convention - we could have arbitrary categories easily (the UI currently only shows addon tags, that can be changed trivially).
  • Brecht noted, this could be called bl_owner, seems reasonable since tags hint at allowing multiple.

    If this feature is kept _only_ for add-ons, then agree this would be better located in bl_info, or we try do it automatic.
  • Bastien mentions this could allow for multiple tags. In principle I'm not against this but wonder if we would really end up making use. It's a bit heavy to add a set of strings to each manipulator/menu/panel type - then do a union-test between the two - to check if we draw a panel - for eg (perhaps the result could be cached, but still).

    An issue with having more fine grained & flexible control is IMHO - users aren't going want to do tedious per-add-on, per-panel, per-keymap configuration of multiple tags.

    If the intent is to have tags be hidden from the users, to implement something more simple, then we could look into how that would work.

    OTOH, if we only end up using this for toggling addons per workspace, IMHO it's overkill
  • Dalai: Currently this doesn't remove items, will add support for this.

    Term 'filter' in code context makes sense, I thought in graphical application it might be confused with image-filter. Show/Hide is a more obvious.

Disable modified menus/panels/headers, now items in menus wont show up.

Rename 'ui_tag' -> 'bl_origin'

Replace hack with a bl_origin global in the RNA API (I think this patch is ready to land - unless there are design/UI issues to resolve).

Python accesses this from a context manager
so this will work correctly for nested calls
(addons enable other addons) and will correctly reset in the case of an
error in addon registration.

The bl_origin is now set in the C registration code, instead of relying on a meta-class.


Currently the add-on name is used, we could have a separate text stored in the add-ons bl_info if we want to be able to group add-ons categories.

Show stored settings in the workspace UI that no longer reference any known add-on. Without this the list could become clogged up with no way to remove settings of addons which aren't enabled.

Adding function wrapper was convoluted

Check filter in the draw loop instead,
allows for storing enabled add-ons in a set once for reuse.

source/blender/makesdna/DNA_workspace_types.h
81 ↗(On Diff #10104)

Struct name is crummy (confuses with BLO_* API). Not sure of a better one.

Remove context manager _BL_Origin, call inline using try/except/finally which is less involved.

While they are neat for this kind of tasks, a simple override used once doesn't really warrant having its own context manager.

Cleanup: rename use_bl_origin -> use_filter_by_origin

Besides possible naming/ui improvements, think this patch is ready to land.

Remove reference to UI tag

release/scripts/startup/bl_operators/wm.py
1896 ↗(On Diff #10124)

Still named UI tag here and the other operator, not sure if intentional.

source/blender/blenkernel/BKE_screen.h
197 ↗(On Diff #10124)

Can we name this just origin and leave the bl_ out in C code? We also don't use bl_idname.

source/blender/makesdna/DNA_workspace_types.h
81 ↗(On Diff #10124)

Same comment, do we really need BL in this name?

This revision was not accepted when it landed; it landed in state Needs Review.Feb 28 2018, 2:35 PM
This revision was automatically updated to reflect the committed changes.