threads and exception in wxPython
Josiah Carlson
jcarlson at uci.edu
Wed Nov 3 22:01:57 EST 2004
Jeff Shannon <jeff at ccvcorp.com> wrote:
>
> Josiah Carlson wrote:
>
> >The only ugly part about idle handling is that idle handlers are called
> >quite often (at least in the wxPython versions I've run). Specifically,
> >whenever I move my mouse over a wxPython app window, idle events are
> >streamed to the idle event handler at 30-60 events/second.
> >
> >Not really a big deal, but something people should know about none the
> >less.
> >
> >
>
> True enough. I believe that in most cases, checking a queue for content
> and acting if there's something there should be a fairly negligible
> load, and that typically it's a load that happens only when nothing else
> would be happening anyhow. But it *is* something to be aware of, and
> one should be at least somewhat cautious about what's done during idle
> processing. OTOH, it's a bit simpler to implement than creating a
> custom event and installing a handler for that... Not *much* simpler, as
> creating a custom event isn't exactly difficult, but in simple
> circumstances it has its benefits... :)
Who said anything about a custom event? Timers are useful and so very
easy to use.
- Josiah
#example code...
from wxPython.wx import wxPySimpleApp, wxFrame, wxTimer, wxNewId, EVT_TIMER
import time
class myframe(wxFrame):
def __init__(self, *args, **kwargs):
wxFrame.__init__(self, *args, **kwargs)
self.t = None
tid = wxNewId()
self.tim = wxTimer(self, tid)
self.tim.Start(1000, False)
EVT_TIMER(self, tid, self.idle_handler)
def idle_handler(self, evt):
if self.t is None:
self.t = time.time()
else:
print round(time.time()-self.t, 3),
self.t = time.time()
app = wxPySimpleApp()
frame = myframe(None, -1, "Ugly Idle Handling")
frame.Show(1)
app.MainLoop()
More information about the Python-list
mailing list