enthought / enthought/pyface

ActionManager shared state issues

Open
#333 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
115
Forks
54
PR merge metrics
No merged PRs in 30d

Description

This possibly should be a TraitsUI issue rather than a Pyface issue.

Currently the various `ActionManager` subclasses (particularly `ToolBarManager`) don't seem to know if they want to be "factories" which create toolkit objects which then follow their own independent existence, or "managers" which update the toolkit controls as their state changes.

For pure Pyface UIs this is not a huge problem, as the typical patterns used create independent instances of the action managers per top-level `ApplicationWindow`, or have explicit creation methods (eg. Tasks Schemas). However typical patterns using these in TraitsUI end up sharing action managers between UIs with the same Views.

This means that any changes made by one user of the view are shared by all, whether or not that is desirable. For example:
```
from traits.api import Bool, HasStrictTraits, Instance, on_trait_change
from traitsui.api import Action, View, Item, Controller, ToolBar

class Test(HasStrictTraits):

show_toolbar = Bool(True)

toolbar = ToolBar(Action(name='Toolbar Thing', action='do_toolbar_thing'))

class TestController(Controller):

model = Instance(Test, ())

@on_trait_change('model:show_toolbar')
def show_toolbar(self, new):
self.info.ui.view.toolbar.visible = new

def do_toolbar_thing(self, ui_info):
print('toolbar thing done')

traits_view = View(Item('show_toolbar'), toolbar=toolbar, resizable=True)

if __name__ == '__main__':
t1 = TestController()
t2 = TestController()
t1.edit_traits()
t2.configure_traits()
```

This is an esoteric example, but there is no other cross-platform way to show/hide the whole toolbar from with TraitsUI (in particular, there is no `visible_when` or `enabled_when` for the whole toolbar.

A design decision needs to be made about whether the action managers should map one-to-one to the widgets they control (note that `StatusBars` do make that assumption); whether they are factories; or whether the current design is OK in Pyface, but TraitsUI needs to grow something more like Tasks schemas for specifying how to build menus and toolbars.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.