wxpython: how does EVT_IDLE work?

J

John Salerno

Quick question about the code below: I understand why the progress bar
fills up at a steady pace when the mouse is idle over the frame; but
why, when you move the mouse, does the progress bar speed up? Shouldn't
it stop completely until the mouse is idle again?

Also, on a side note, I'm confused by the use of the word "bevel" and
"bezel". The methods seem to use "bezel", but according to wxPython in
Action, it's referring to the bevel of the border of the widget. Also,
the book refers to a method called SetBevelWidth(), but the code shows
it as SetBezelWidth() -- and only the latter works -- so what's the deal
with these words?

Thanks!

--------------------------------------

import wx

class GaugeFrame(wx.Frame):

def __init__(self):
wx.Frame.__init__(self, None, -1, 'Gauge Example')
panel = wx.Panel(self)
self.count = 0
self.gauge = wx.Gauge(panel, -1, 50, (20, 50), (250, 25))
self.gauge.SetBevelFace(3)
self.gauge.SetShadowWidth(3)
self.Bind(wx.EVT_IDLE, self.OnIdle)

def OnIdle(self, event):
self.count += 1
if self.count >= 50:
self.count = 0
self.gauge.SetValue(self.count)

if __name__ == '__main__':
app = wx.App(redirect=False)
GaugeFrame().Show()
app.MainLoop()
 
J

John Salerno

John said:
Quick question about the code below: I understand why the progress bar
fills up at a steady pace when the mouse is idle over the frame; but
why, when you move the mouse, does the progress bar speed up? Shouldn't
it stop completely until the mouse is idle again?

Ok, now I'm really confused. I just ran the code again and this time it
*doesn't* increase the progress bar when the mouse is idle, and it only
increases when I move it. This wasn't the behavior just a few minutes
ago, and I didn't change anything! What's going on?


self.gauge.SetBevelFace(3)

Should be 'Bezel'.
 
J

John Salerno

John said:
Ok, now I'm really confused. I just ran the code again and this time it
*doesn't* increase the progress bar when the mouse is idle, and it only
increases when I move it. This wasn't the behavior just a few minutes
ago, and I didn't change anything! What's going on?

Ok, this helps explain why moving the mouse causes the idle event:

"Note that, unless you do something specifically, the idle events are
not sent if the system remains idle once it has become it, e.g. only a
single idle event will be generated until something else resulting in
more normal events happens and only then is the next idle event sent again."

But I'm still confused about why *not* moving the mouse still allowed
the progress bar to increase (although that behavior has stopped now for
some reason).
 
R

Rob Williscroft

John Salerno wrote in in
comp.lang.python:
Quick question about the code below: I understand why the progress bar
fills up at a steady pace when the mouse is idle over the frame; but
why, when you move the mouse, does the progress bar speed up? Shouldn't
it stop completely until the mouse is idle again?

wxWidgets is sending the idle event after it has processed all
other events, but it just sends it once not in a loop.

see the documentation (help) for wxIdleEvent::RequestMore.

def OnIdle(self, event):

event.RequestMore(True)
self.count += 1
if self.count >= 50:
self.count = 0

Rob.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top