Envisage/Tasks Object/Action Sharing

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

Envisage/Tasks Object/Action Sharing

ericjmcd
I have a pretty complicated Envisage/Tasks application with multiple plugins (many of which are task extensions) and am really uncertain on how various parts of the application should be shared.

For instance, I have a Plotter Plugin with a Task Extension and a MenuBar action to create a new Plotter widget in the central pane. I have a Scripting Plugin that would like to call the 'Add Plotter' menubar action but it's not clear how to get to that action (defined/contributed in the Plotter Plugin's Task Extension).

I'd like to be able to call something like:
   application.perform_action(id='plotter.add_plotter')
I don't think "finding" the task extension from application.task_extensions seems the right way:

from x import PlotterTaskExtension
for i in application.task_extensions:
  if isinstance(i, PlotterTaskExtension):
     i.add_plotter()

Similarly, I my Scripting Task Extension adds some menubar actions as well as a TraitsDockPane. I have a button in my DockPane that calls the same menubar action.  I've done this by creating a reference to the DockPane in my task extension and then adding a notification to fire the action:
@on_trait_change('pane.action_btn')
def menubar_action(self):
   ...

This seems a bit ugly but not too bad since it's all within the same TaskExtension.  Doing this across Plugins is rather ugly though.

Also, there doesn't appear to be any way to get to 'application' from within a TaskExtension so I end up creating an app_reference and set it in the Plugin's start() method when I create the TaskExtension object and append it to my task_extensions trait (contributions to the extension point).

Envisage/Tasks/Traits/TraitsUI are great, I just wish I knew the proper way to use them all together.  I think I should probably start looking at the source code for Canopy and see what you guys normally do.

Thanks,
Eric
   
Reply | Threaded
Open this post in threaded view
|

Re: Envisage/Tasks Object/Action Sharing

Martin Chilvers
Hi Eric,

On 22/08/2013 19:42, ericjmcd wrote:

> I have a pretty complicated Envisage/Tasks application with multiple plugins
> (many of which are task extensions) and am really uncertain on how various
> parts of the application should be shared.
>
> For instance, I have a Plotter Plugin with a Task Extension and a MenuBar
> action to create a new Plotter widget in the central pane. I have a
> Scripting Plugin that would like to call the 'Add Plotter' menubar action
> but it's not clear how to get to that action (defined/contributed in the
> Plotter Plugin's Task Extension).
>
> I'd like to be able to call something like:
>     application.perform_action(id='plotter.add_plotter')
> I don't think "finding" the task extension from application.task_extensions
> seems the right way:
>
> from x import PlotterTaskExtension
> for i in application.task_extensions:
>    if isinstance(i, PlotterTaskExtension):
>       i.add_plotter()

I'm not a Tasks expert, but in general terms, it is usually best not to
try to call actions. Think of them really as just visual triggers that
optionally take some user input and call a method (often on an object
registered as a service) to do the real work.

> Similarly, I my Scripting Task Extension adds some menubar actions as well
> as a TraitsDockPane. I have a button in my DockPane that calls the same
> menubar action.  I've done this by creating a reference to the DockPane in
> my task extension and then adding a notification to fire the action:
> @on_trait_change('pane.action_btn')
> def menubar_action(self):
>     ...
>
> This seems a bit ugly but not too bad since it's all within the same
> TaskExtension.  Doing this across Plugins is rather ugly though.

Again, calling actions themselves sounds a alarm bells to me!

Martin

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

Re: Envisage/Tasks Object/Action Sharing

ericjmcd
Martin,

Thanks for the feedback.  That makes a lot more sense and partially explains why TaskExtensions don't have a reference to the active task or application by default.  I've got a bit of rewriting to do but I think this will really clean things up.

It's too bad that Canopy isn't open source because I'd love to look through that code and see how you guys have put that all together.

Thanks again,
Eric


On Wed, Sep 4, 2013 at 2:36 AM, Martin Chilvers [via Enthought Dev] <[hidden email]> wrote:
Hi Eric,

On 22/08/2013 19:42, ericjmcd wrote:

> I have a pretty complicated Envisage/Tasks application with multiple plugins
> (many of which are task extensions) and am really uncertain on how various
> parts of the application should be shared.
>
> For instance, I have a Plotter Plugin with a Task Extension and a MenuBar
> action to create a new Plotter widget in the central pane. I have a
> Scripting Plugin that would like to call the 'Add Plotter' menubar action
> but it's not clear how to get to that action (defined/contributed in the
> Plotter Plugin's Task Extension).
>
> I'd like to be able to call something like:
>     application.perform_action(id='plotter.add_plotter')
> I don't think "finding" the task extension from application.task_extensions
> seems the right way:
>
> from x import PlotterTaskExtension
> for i in application.task_extensions:
>    if isinstance(i, PlotterTaskExtension):
>       i.add_plotter()
I'm not a Tasks expert, but in general terms, it is usually best not to
try to call actions. Think of them really as just visual triggers that
optionally take some user input and call a method (often on an object
registered as a service) to do the real work.

> Similarly, I my Scripting Task Extension adds some menubar actions as well
> as a TraitsDockPane. I have a button in my DockPane that calls the same
> menubar action.  I've done this by creating a reference to the DockPane in
> my task extension and then adding a notification to fire the action:
> @on_trait_change('pane.action_btn')
> def menubar_action(self):
>     ...
>
> This seems a bit ugly but not too bad since it's all within the same
> TaskExtension.  Doing this across Plugins is rather ugly though.
Again, calling actions themselves sounds a alarm bells to me!

Martin

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



If you reply to this email, your message will be added to the discussion below:
http://enthought-dev.117412.n3.nabble.com/Envisage-Tasks-Object-Action-Sharing-tp4026622p4026633.html
To unsubscribe from Envisage/Tasks Object/Action Sharing, click here.
NAML