TaskActionSchema?

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

TaskActionSchema?

Pietro Berkes
Hi!

I'm writing a Task subclass that defines a menu bar. At some point in the application, I need to destroy the old menu bar and build a new one. Most of that works without problems, except when I explicitly defined Action's in the menu bar, for example:

    def _menu_bar_default(self):
        menu_bar = SMenuBar(
            SMenu(
                SGroup(
                    MyCustomMenuSchema(my_trait = self.something),
                    TaskAction(
                        name        = 'Open File...',
                        accelerator = 'Ctrl+O',
                        method      = 'open_file',
                    ),
                    id = 'FileGroup'
                ),
                id='File', name='&File'
            ),

When the menu bar manager is destroyed, the TaskAction is destroyed as well, and when the new menu bar manager comes around, it adds a destroyed action to the menu... This does not happen for the Schema's, of course, because they are more like factories for actual menu and groups.

The question is: do we need an ActionSchema, or is there another way of doing this I'm not aware of? I have a working implementation for TaskAction's that I'd be happy to add to pyface:

class TaskActionSchema(Schema):

    # Task action template. The action is not actually used, rather the
    # information inside it is used to create a new TaskAction
    action = Instance(TaskAction)

    def create(self, children):
        """ Create the appropriate pyface.action instance with the specified
            child items.
        """

        return self.action.clone_traits()

Thanks,
Pietro


--
Pietro Berkes
Scientific software developer
Enthought UK



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

Re: TaskActionSchema?

Robert Kern
Sounds like a good idea.

On Wed, Nov 14, 2012 at 10:20 AM, Pietro Berkes <[hidden email]> wrote:

> Hi!
>
> I'm writing a Task subclass that defines a menu bar. At some point in the
> application, I need to destroy the old menu bar and build a new one. Most of
> that works without problems, except when I explicitly defined Action's in
> the menu bar, for example:
>
>     def _menu_bar_default(self):
>         menu_bar = SMenuBar(
>             SMenu(
>                 SGroup(
>                     MyCustomMenuSchema(my_trait = self.something),
>                     TaskAction(
>                         name        = 'Open File...',
>                         accelerator = 'Ctrl+O',
>                         method      = 'open_file',
>                     ),
>                     id = 'FileGroup'
>                 ),
>                 id='File', name='&File'
>             ),
>
> When the menu bar manager is destroyed, the TaskAction is destroyed as well,
> and when the new menu bar manager comes around, it adds a destroyed action
> to the menu... This does not happen for the Schema's, of course, because
> they are more like factories for actual menu and groups.
>
> The question is: do we need an ActionSchema, or is there another way of
> doing this I'm not aware of? I have a working implementation for
> TaskAction's that I'd be happy to add to pyface:
>
> class TaskActionSchema(Schema):
>
>     # Task action template. The action is not actually used, rather the
>     # information inside it is used to create a new TaskAction
>     action = Instance(TaskAction)
>
>     def create(self, children):
>         """ Create the appropriate pyface.action instance with the specified
>             child items.
>         """
>
>         return self.action.clone_traits()
>
> Thanks,
> Pietro
>
>
> --
> Pietro Berkes
> Scientific software developer
> Enthought UK
>
>
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>



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

Re: TaskActionSchema?

Pietro Berkes
I submitted a pull request that would add Action schemas:



On Fri, Nov 16, 2012 at 4:45 PM, Robert Kern <[hidden email]> wrote:
Sounds like a good idea.

On Wed, Nov 14, 2012 at 10:20 AM, Pietro Berkes <[hidden email]> wrote:
> Hi!
>
> I'm writing a Task subclass that defines a menu bar. At some point in the
> application, I need to destroy the old menu bar and build a new one. Most of
> that works without problems, except when I explicitly defined Action's in
> the menu bar, for example:
>
>     def _menu_bar_default(self):
>         menu_bar = SMenuBar(
>             SMenu(
>                 SGroup(
>                     MyCustomMenuSchema(my_trait = self.something),
>                     TaskAction(
>                         name        = 'Open File...',
>                         accelerator = 'Ctrl+O',
>                         method      = 'open_file',
>                     ),
>                     id = 'FileGroup'
>                 ),
>                 id='File', name='&File'
>             ),
>
> When the menu bar manager is destroyed, the TaskAction is destroyed as well,
> and when the new menu bar manager comes around, it adds a destroyed action
> to the menu... This does not happen for the Schema's, of course, because
> they are more like factories for actual menu and groups.
>
> The question is: do we need an ActionSchema, or is there another way of
> doing this I'm not aware of? I have a working implementation for
> TaskAction's that I'd be happy to add to pyface:
>
> class TaskActionSchema(Schema):
>
>     # Task action template. The action is not actually used, rather the
>     # information inside it is used to create a new TaskAction
>     action = Instance(TaskAction)
>
>     def create(self, children):
>         """ Create the appropriate pyface.action instance with the specified
>             child items.
>         """
>
>         return self.action.clone_traits()
>
> Thanks,
> Pietro
>
>
> --
> Pietro Berkes
> Scientific software developer
> Enthought UK
>
>
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>



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



--
Pietro Berkes
Scientific software developer
Enthought UK



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