Running methods on the UI thread

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

Running methods on the UI thread

Fredrik Östlund
Hi,

the following code snippet crashes, presumably because
MessageDialog().confirm() is called with another thread than the UI thread.
Is possible to make the following example to work? I've think I have seen
that it is possible to run an on_trait_changed handler with a different
dispatch thread, but I can't find out how to do this. Any hints are most
welcome.


from enthought.traits.api import *
from enthought.traits.ui.api import *
from enthought.pyface.api import *
import threading

class MyMain(HasTraits):
    button = Button('click me')

    def _run(self):
        MessageDialog().confirm("Sure?")

    def _button_fired(self):
        t = threading.Thread(target=self._run)
        t.setDaemon(True)
        t.start()

    view = View(
        'button'
    )

MyMain().configure_traits()


thanks,

Fredrik Oestlund

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

Re: [Enthought-Dev] Running methods on the UI thread

bryce hendrix-2
[hidden email] wrote:

> Hi,
>
> the following code snippet crashes, presumably because
> MessageDialog().confirm() is called with another thread than the UI thread.
> Is possible to make the following example to work? I've think I have seen
> that it is possible to run an on_trait_changed handler with a different
> dispatch thread, but I can't find out how to do this. Any hints are most
> welcome.
>
>  

https://svn.enthought.com/enthought/wiki/OnTraitChangeDispatch

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