Question related to data_stream example

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

Question related to data_stream example

sylvain roy
Hello,

I based myself on the chaco_examples/advanced/data_stream example to
stream real time data.
I have to say, it works very well. I have a related problem. I isolated it
in the following simple example, hoping that someone can help me.

A main GUI displays an 'open' button. Once this button is pressed, a
second GUI appears displaying
a 'close' button and a process is also launched: 'hello world' is
printed every 1/10 of a second on the screen.
When 'close' is pressed, I expect this process to stop, which is not the
case. Only the 'close' button GUI disappears (which is expected).
How can I stop the 'hello world' printing process? I'm not sure if this
is related to Enthought or wx but I try
on this mailing list anyway.

The example follows.
Cheers,
Sylvain

import wx
from enthought.traits.api import HasTraits, Button
from enthought.traits.ui.api import View, Item, Handler
from enthought.traits.ui.menu import Action


class UI_Handler(Handler):
    def close_display(self, info):
        info.ui.dispose()

class Controller(HasTraits):
    close_button = Action(name='Close',action='close_display')
    view = View(
                handler = UI_Handler(),
                buttons=[close_button],
                resizable = True,
                width=250,
                height=75,
                )
    def timer_tick(self, *args):
        print 'hello world'
     
class MyApp(wx.PySimpleApp):
    def __init__(self, controller, **kw):
        super(MyApp, self).__init__(**kw)
        self.controller = controller

    def setup_timer(self):
        self.controller.edit_traits()
        timerId = wx.NewId()
        self.timer = wx.Timer(self, timerId)
        self.Bind(wx.EVT_TIMER, self.controller.timer_tick, id=timerId)
        self.timer.Start(100.0, wx.TIMER_CONTINUOUS)
        return
   
class MyInterface(HasTraits):
    open = Button(label='Open')
   
    view = View(Item('open', show_label=False),
                resizable = True,
                width=250,
                height=75,
                )
   
    def _open_fired(self):
        controller = Controller()
        my_app = MyApp(controller = controller)
        my_app.setup_timer()
        my_app.MainLoop()  

if __name__ == "__main__":
    my_interface = MyInterface()
    my_interface.configure_traits()
   
# EOF


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

Re: Question related to data_stream example

Robert Kern
On Fri, May 7, 2010 at 2:43 PM, Sylvain Roy <[hidden email]> wrote:

> Hello,
>
> I based myself on the chaco_examples/advanced/data_stream example to
> stream real time data.
> I have to say, it works very well. I have a related problem. I isolated it
> in the following simple example, hoping that someone can help me.
>
> A main GUI displays an 'open' button. Once this button is pressed, a
> second GUI appears displaying
> a 'close' button and a process is also launched: 'hello world' is
> printed every 1/10 of a second on the screen.
> When 'close' is pressed, I expect this process to stop, which is not the
> case. Only the 'close' button GUI disappears (which is expected).
> How can I stop the 'hello world' printing process? I'm not sure if this
> is related to Enthought or wx but I try
> on this mailing list anyway.
>
> The example follows.
> Cheers,
> Sylvain
>
> import wx
> from enthought.traits.api import HasTraits, Button
> from enthought.traits.ui.api import View, Item, Handler
> from enthought.traits.ui.menu import Action
>
>
> class UI_Handler(Handler):
>    def close_display(self, info):
>        info.ui.dispose()
>
> class Controller(HasTraits):
>    close_button = Action(name='Close',action='close_display')
>    view = View(
>                handler = UI_Handler(),
>                buttons=[close_button],
>                resizable = True,
>                width=250,
>                height=75,
>                )
>    def timer_tick(self, *args):
>        print 'hello world'
>
> class MyApp(wx.PySimpleApp):
>    def __init__(self, controller, **kw):
>        super(MyApp, self).__init__(**kw)
>        self.controller = controller
>
>    def setup_timer(self):
>        self.controller.edit_traits()
>        timerId = wx.NewId()
>        self.timer = wx.Timer(self, timerId)
>        self.Bind(wx.EVT_TIMER, self.controller.timer_tick, id=timerId)
>        self.timer.Start(100.0, wx.TIMER_CONTINUOUS)
>        return
>
> class MyInterface(HasTraits):
>    open = Button(label='Open')
>
>    view = View(Item('open', show_label=False),
>                resizable = True,
>                width=250,
>                height=75,
>                )
>
>    def _open_fired(self):
>        controller = Controller()
>        my_app = MyApp(controller = controller)
>        my_app.setup_timer()
>        my_app.MainLoop()

You really cannot start two MainLoops at the same time.
.configure_traits() has already created an App and is running a
MainLoop already by the time this code gets executed.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Question related to data_stream example

sylvain roy
Robert Kern wrote:

> On Fri, May 7, 2010 at 2:43 PM, Sylvain Roy <[hidden email]> wrote:
>  
>> Hello,
>>
>> I based myself on the chaco_examples/advanced/data_stream example to
>> stream real time data.
>> I have to say, it works very well. I have a related problem. I isolated it
>> in the following simple example, hoping that someone can help me.
>>
>> A main GUI displays an 'open' button. Once this button is pressed, a
>> second GUI appears displaying
>> a 'close' button and a process is also launched: 'hello world' is
>> printed every 1/10 of a second on the screen.
>> When 'close' is pressed, I expect this process to stop, which is not the
>> case. Only the 'close' button GUI disappears (which is expected).
>> How can I stop the 'hello world' printing process? I'm not sure if this
>> is related to Enthought or wx but I try
>> on this mailing list anyway.
>>
>> The example follows.
>> Cheers,
>> Sylvain
>>
>> import wx
>> from enthought.traits.api import HasTraits, Button
>> from enthought.traits.ui.api import View, Item, Handler
>> from enthought.traits.ui.menu import Action
>>
>>
>> class UI_Handler(Handler):
>>    def close_display(self, info):
>>        info.ui.dispose()
>>
>> class Controller(HasTraits):
>>    close_button = Action(name='Close',action='close_display')
>>    view = View(
>>                handler = UI_Handler(),
>>                buttons=[close_button],
>>                resizable = True,
>>                width=250,
>>                height=75,
>>                )
>>    def timer_tick(self, *args):
>>        print 'hello world'
>>
>> class MyApp(wx.PySimpleApp):
>>    def __init__(self, controller, **kw):
>>        super(MyApp, self).__init__(**kw)
>>        self.controller = controller
>>
>>    def setup_timer(self):
>>        self.controller.edit_traits()
>>        timerId = wx.NewId()
>>        self.timer = wx.Timer(self, timerId)
>>        self.Bind(wx.EVT_TIMER, self.controller.timer_tick, id=timerId)
>>        self.timer.Start(100.0, wx.TIMER_CONTINUOUS)
>>        return
>>
>> class MyInterface(HasTraits):
>>    open = Button(label='Open')
>>
>>    view = View(Item('open', show_label=False),
>>                resizable = True,
>>                width=250,
>>                height=75,
>>                )
>>
>>    def _open_fired(self):
>>        controller = Controller()
>>        my_app = MyApp(controller = controller)
>>        my_app.setup_timer()
>>        my_app.MainLoop()
>>    
>
> You really cannot start two MainLoops at the same time.
> .configure_traits() has already created an App and is running a
> MainLoop already by the time this code gets executed.
>  
Robert, I think I succeeded to do want I wanted to do
althought I'm really not in control of the situation.
Feel free to have a look and send some comments.

Cheers,
Sylvain


import wx
from enthought.traits.api import HasTraits, Button, Instance, Bool
from enthought.traits.ui.api import View, Item, Handler
from enthought.traits.ui.menu import Action


class UI_Handler(Handler):
    def close_display(self, info):
        info.ui.dispose()
        info.object.do_display = False

class Controller(HasTraits):
    do_display = Bool(False)
    close_button = Action(name='Close',action='close_display')
    view = View(
                handler = UI_Handler(),
                buttons=[close_button],
                resizable = True,
                width=250,
                height=75,
                )
    def timer_tick(self, *args):
        if self.do_display:
            print 'hello world'
        else:
            pass
     
class MyApp(wx.PySimpleApp):
    def __init__(self, my_interface, **kw):
        super(MyApp, self).__init__(**kw)
        self.my_interface = my_interface
        self.controller = my_interface.controller

    def setup_timer(self):
        self.my_interface.edit_traits()
        timerId = wx.NewId()
        self.timer = wx.Timer(self, timerId)
        self.Bind(wx.EVT_TIMER, self.controller.timer_tick, id=timerId)
        self.timer.Start(100.0, wx.TIMER_CONTINUOUS)
       
   
class MyInterface(HasTraits):
    open = Button(label='Open')
    controller = Instance(Controller)
   
    def __init__(self, **traits):
        super(MyInterface, self).__init__(**traits)
        self.controller = Controller()
   
    view = View(Item('open', show_label=False),
                resizable = True,
                width=250,
                height=75,
                )
   
    def _open_fired(self):
        self.controller.do_display = True
        self.controller.configure_traits()
       

if __name__ == "__main__":
    my_interface = MyInterface()
    my_app = MyApp(my_interface = my_interface)
    my_app.setup_timer()
    my_app.MainLoop()
   

# EOF




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