Enaml - equivalent of traitsui.api.Handler

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

Enaml - equivalent of traitsui.api.Handler

Jaidev Deshpande
Hello,

Is there an equivalent of the traitsui.api.Handler class in enaml?

Examples or tutorials about using enaml to perform the stuff of
Handler are welcome too.

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

Re: Enaml - equivalent of traitsui.api.Handler

Robert Kern
On Tue, Jun 26, 2012 at 11:01 PM, Jaidev Deshpande
<[hidden email]> wrote:
> Hello,
>
> Is there an equivalent of the traitsui.api.Handler class in enaml?
>
> Examples or tutorials about using enaml to perform the stuff of
> Handler are welcome too.

There is no exact equivalent. Most things that a Handler would do is
done through the attribute bindings. Can you be more specific about
the stuff you are interested in?

--
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: Enaml - equivalent of traitsui.api.Handler

Jaidev Deshpande
On Wed, Jun 27, 2012 at 3:59 AM, Robert Kern <[hidden email]> wrote:

> On Tue, Jun 26, 2012 at 11:01 PM, Jaidev Deshpande
> <[hidden email]> wrote:
>> Hello,
>>
>> Is there an equivalent of the traitsui.api.Handler class in enaml?
>>
>> Examples or tutorials about using enaml to perform the stuff of
>> Handler are welcome too.
>
> There is no exact equivalent. Most things that a Handler would do is
> done through the attribute bindings. Can you be more specific about
> the stuff you are interested in?
>
> --
> Robert Kern
> Enthought
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev

I'm trying to modify Gael's traitsUI tutorial for enaml.

Here's the tut, for reference -
http://gael-varoquaux.info/computers/traits_tutorial/traits_tutorial.html#putting-it-all-together-a-sample-application

In section 5.4 there's this class MainWindowHandler which inherits from Handler.

class MainWindowHandler(Handler):
    def close(self, info, is_OK):
        if ( info.object.panel.acquisition_thread
                        and info.object.panel.acquisition_thread.isAlive() ):
            info.object.panel.acquisition_thread.wants_abort = True
            while info.object.panel.acquisition_thread.isAlive():
                sleep(0.1)
            wx.Yield()
        return True

I can't figure out how to do this in enaml. An instance of this class
is to be later passed to the MainWindow traits view as a handler. So I
was thinking if there is an equivalent handler attribute in an enaml
MainWindow.

Which class in enaml contains equivalents of these attributes (info,
close(), is_OK, etc)?

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

Re: Enaml - equivalent of traitsui.api.Handler

Chris Colbert
MainWindow and Dialog have 'closed' events that you can bind to:

enamldef Foo(MainWindow):
    closed ::
        <do your shutdown stuff>

It would be nice to have this even on the base Window component as well. I should probably move it at some point...


On Tue, Jun 26, 2012 at 6:51 PM, Jaidev Deshpande <[hidden email]> wrote:
On Wed, Jun 27, 2012 at 3:59 AM, Robert Kern <[hidden email]> wrote:
> On Tue, Jun 26, 2012 at 11:01 PM, Jaidev Deshpande
> <[hidden email]> wrote:
>> Hello,
>>
>> Is there an equivalent of the traitsui.api.Handler class in enaml?
>>
>> Examples or tutorials about using enaml to perform the stuff of
>> Handler are welcome too.
>
> There is no exact equivalent. Most things that a Handler would do is
> done through the attribute bindings. Can you be more specific about
> the stuff you are interested in?
>
> --
> Robert Kern
> Enthought
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev

I'm trying to modify Gael's traitsUI tutorial for enaml.

Here's the tut, for reference -
http://gael-varoquaux.info/computers/traits_tutorial/traits_tutorial.html#putting-it-all-together-a-sample-application

In section 5.4 there's this class MainWindowHandler which inherits from Handler.

class MainWindowHandler(Handler):
   def close(self, info, is_OK):
       if ( info.object.panel.acquisition_thread
                       and info.object.panel.acquisition_thread.isAlive() ):
           info.object.panel.acquisition_thread.wants_abort = True
           while info.object.panel.acquisition_thread.isAlive():
               sleep(0.1)
           wx.Yield()
       return True

I can't figure out how to do this in enaml. An instance of this class
is to be later passed to the MainWindow traits view as a handler. So I
was thinking if there is an equivalent handler attribute in an enaml
MainWindow.

Which class in enaml contains equivalents of these attributes (info,
close(), is_OK, etc)?

Thanks
_______________________________________________
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: Enaml - equivalent of traitsui.api.Handler

Robert Kern
In reply to this post by Jaidev Deshpande
On Tue, Jun 26, 2012 at 11:51 PM, Jaidev Deshpande
<[hidden email]> wrote:

> On Wed, Jun 27, 2012 at 3:59 AM, Robert Kern <[hidden email]> wrote:
>> On Tue, Jun 26, 2012 at 11:01 PM, Jaidev Deshpande
>> <[hidden email]> wrote:
>>> Hello,
>>>
>>> Is there an equivalent of the traitsui.api.Handler class in enaml?
>>>
>>> Examples or tutorials about using enaml to perform the stuff of
>>> Handler are welcome too.
>>
>> There is no exact equivalent. Most things that a Handler would do is
>> done through the attribute bindings. Can you be more specific about
>> the stuff you are interested in?
>>
>> --
>> Robert Kern
>> Enthought
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
> I'm trying to modify Gael's traitsUI tutorial for enaml.
>
> Here's the tut, for reference -
> http://gael-varoquaux.info/computers/traits_tutorial/traits_tutorial.html#putting-it-all-together-a-sample-application
>
> In section 5.4 there's this class MainWindowHandler which inherits from Handler.
>
> class MainWindowHandler(Handler):
>    def close(self, info, is_OK):
>        if ( info.object.panel.acquisition_thread
>                        and info.object.panel.acquisition_thread.isAlive() ):
>            info.object.panel.acquisition_thread.wants_abort = True
>            while info.object.panel.acquisition_thread.isAlive():
>                sleep(0.1)
>            wx.Yield()
>        return True
>
> I can't figure out how to do this in enaml. An instance of this class
> is to be later passed to the MainWindow traits view as a handler. So I
> was thinking if there is an equivalent handler attribute in an enaml
> MainWindow.
>
> Which class in enaml contains equivalents of these attributes (info,
> close(), is_OK, etc)?

Enaml does not replicate Traits UI's model of how UIs are built. There
are no real equivalents down at this low level. What you need to do is
step back up a level and ask "What is this code trying to accomplish,
and how can I accomplish the same thing in Enaml?" When you answer the
first part, don't use any terminology or refer to objects specific to
Traits UI. Just use terminology that is general to any UI.

In this case, the code is intercepting the request to close the dialog
and making sure that the acquisition thread exits cleanly before
completing the closing of the dialog. At the moment, Enaml does not
let you stop or hold up the closing of the dialog. The `closed` event
just lets you be informed that the window has received and handled a
close event. For the purpose of this exercise, that's probably fine.
The code does not really need to hold up the disappearance of the
window while it closes the thread. For other purposes, like bringing
up a "You have unsaved work. Do you really want to quit?" dialog,
we'll probably need to add something like an `about_to_close` event
that can cause the close request to be ignored.

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