Thanks Robin,
How the wx.Timer works is a bit mysterious to me. I am definitely
missing an important concept here, I greatly appreciate any help in that
direction.
Here is an example of a mini frame that registers itself for a call back
from the timer. Now, when the timer calls the OnTimer() method object,
what assumptions can we make about the thread? Can I draw to the screen
from inside the OnTimer() method?
class TimerAgent(wx.MiniFrame):
···
#---------------------------------------------
def __init__(self, parent, interval):
wx.MiniFrame.__init__(self, parent, -1, ' ', pos=(200, 200),
size=(100, 100), style=wx.DEFAULT_FRAME_STYLE | wx.TINY_CAPTION_HORIZ)
self.Show(False)
self.interval = interval
self.timerId = wx.NewId()
#---------------------------------------------
def StartWork(self):
self.timer = wx.Timer(self, self.timerId)
wx.EVT_TIMER(self, self.timerId, self.OnTimer)
self.timer.Start(self.interval)
#---------------------------------------------
def OnTimer(self, event):
self.DoScheduledWork()
#---------------------------------------------
def DoScheduledWork(self):
# do some work here. But can I draw to the screen?
Thanks,
-H
-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Tuesday, May 18, 2004 2:15 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] EventManager, wx.Timer and the UI thread
Hatim Khan wrote:
I got a few questions about event handling:
1- If a hidden frame is using wx.Timer for call back, the wx.Timer
would use the postEvent method to send the events. Correct?
No. Hidden frames can recieve events exactly the same way as shown
frames.
So this way it
does not matter if wx.Timer is running on an non UI thread.
It does matter. Timers should only be used on the UI thread.
2- What is the difference between using Connect, Bind,
EventManager.register, and all the EVT_* helper functions?
The EVT_* helper (used to be) functions are just simple wrappers around
Connect that were meant to make binding events similar to using the
EVT_* macros in an event table in C++. Bind is a recent addition that
abstracts the same thing to a little higher more OO level.
EventManager is a completely different animal, sorta. It allows you to
subscribe listeners to receive messages published in response to events,
following a Publish/Subscribe or Observer design pattern. It makes it
easy to have more loosly coupled applications as the subscriber doesn't
have to be the object that receives the wxEvent, and there can be many
subscribers to a single event if you need it.
What are the
best practices.
A lot of people are shifting to using Bind for normal event handling,
although the EVT_* funciton interface will probably still be valid for
the forseeable future. (The EVT_* objects are now instances of a class
that has a __call__ method, so they can still be used as functions.)
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org