Actions, menus & toolbars, and enabled state

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Actions, menus & toolbars, and enabled state

Rob McMullen
I'm using tasks and creating a simple application to edit stuff. Some menu and toolbar items will need to be enabled or disabled depending on the state of the active task (e.g. dirty state of active editor, what's selected, etc.)

What's the recommended way to set the enabled/disabled state of all the menu and toolbar items? My naive idea is just looping through the Actions and set the enabled trait, but I'm still new and so maybe there's a way to use traits notification to do it?

Also, if the same Action is used in a menu and a toolbar, can they share the same Action instance, or should there be an instance for each place the action occurs?

Thanks,

Rob

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Actions, menus & toolbars, and enabled state

Tony S Yu
Hi Rob,


On Thu, Feb 20, 2014 at 12:07 PM, Rob McMullen <[hidden email]> wrote:
I'm using tasks and creating a simple application to edit stuff. Some menu and toolbar items will need to be enabled or disabled depending on the state of the active task (e.g. dirty state of active editor, what's selected, etc.)

What's the recommended way to set the enabled/disabled state of all the menu and toolbar items? My naive idea is just looping through the Actions and set the enabled trait, but I'm still new and so maybe there's a way to use traits notification to do it?

Have you looked at `ListeningAction` and `TaskAction`:


The first defines an `enabled_name` trait, which points to an attribute on some parent object. The True/False value of that attribute will control the enabled state of your action. `TaskAction` extends that concept by automatically setting the parent object to be the task. (This automatic-setting occurs when the action is added to the tasks menu).

I'm fairly new to Tasks, so I'm not sure about the implications of sharing Action instances between a menu and a toolbar.

Best,
-Tony
 

Also, if the same Action is used in a menu and a toolbar, can they share the same Action instance, or should there be an instance for each place the action occurs?

Thanks,

Rob

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev



_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Actions, menus & toolbars, and enabled state

Rob McMullen
Tony,

On Sun, Feb 23, 2014 at 11:16 AM, Tony Yu <[hidden email]> wrote:
Have you looked at `ListeningAction` and `TaskAction`:

Thanks for the explanation, that makes so much sense.  I totally didn't connect that that was how to use those classes. Thanks for taking the time to help me understand it. I'll recode my project to use the enabled_name/visible_name attributes.

I'm fairly new to Tasks, so I'm not sure about the implications of sharing Action instances between a menu and a toolbar.

I'm new as well. I poked around the code and it looks like there's a one-to-one relationship between an action and the UI item that it will ultimately be mapped to, so I'm guessing Bad Things will happen if I would have tried to share them. But since the enabled state is so easily managed using the ListeningAction, it doesn't seem to be a big deal to just have an action instance for each item.

Thanks again,

Rob


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Actions, menus & toolbars, and enabled state

Corran Webster
In reply to this post by Tony S Yu



On Sun, Feb 23, 2014 at 1:16 PM, Tony Yu <[hidden email]> wrote:
Hi Rob,


On Thu, Feb 20, 2014 at 12:07 PM, Rob McMullen <[hidden email]> wrote:
I'm using tasks and creating a simple application to edit stuff. Some menu and toolbar items will need to be enabled or disabled depending on the state of the active task (e.g. dirty state of active editor, what's selected, etc.)

What's the recommended way to set the enabled/disabled state of all the menu and toolbar items? My naive idea is just looping through the Actions and set the enabled trait, but I'm still new and so maybe there's a way to use traits notification to do it?

Have you looked at `ListeningAction` and `TaskAction`:


The first defines an `enabled_name` trait, which points to an attribute on some parent object. The True/False value of that attribute will control the enabled state of your action. `TaskAction` extends that concept by automatically setting the parent object to be the task. (This automatic-setting occurs when the action is added to the tasks menu).

Also, if the Acton state depends upon the state of the active editor, an EditorAction may be more appropriate than a TaskAction.  EditorActions are subclasses of ListeningAction, and work in more or less the same way, but with the parent object being the active editor instead of the task.
 
I'm fairly new to Tasks, so I'm not sure about the implications of sharing Action instances between a menu and a toolbar.

You can do it, but because toolbar Actions typically have an icon and menu Actions typically don't you typically want two slightly different instances.  But Actions are, in general, designed to be shareable between different views like Toolbars, Menus, Buttons, etc.

-- Corran
 
Best,
-Tony
 

Also, if the same Action is used in a menu and a toolbar, can they share the same Action instance, or should there be an instance for each place the action occurs?

Thanks,

Rob

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev



_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev



_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Actions, menus & toolbars, and enabled state

Rob McMullen
Corran,


On Mon, Feb 24, 2014 at 11:00 AM, Corran Webster <[hidden email]> wrote:
Also, if the Acton state depends upon the state of the active editor, an EditorAction may be more appropriate than a TaskAction.  EditorActions are subclasses of ListeningAction, and work in more or less the same way, but with the parent object being the active editor instead of the task.

Also a great help, I had missed that one, too.

I have not traitsified my thinking yet, but it certainly does present some advantages over my old way of thinking. Previously, I used idle time handlers to loop through each and every action and set their enabled state.
 
You can do it, but because toolbar Actions typically have an icon and menu Actions typically don't you typically want two slightly different instances.  But Actions are, in general, designed to be shareable between different views like Toolbars, Menus, Buttons, etc.

Good to know, thanks. I hadn't thought about sharing actions with buttons. I've got a lot to learn with this framework, obviously!

Thanks,

Rob

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev