Skipping work based on future events

From: Chuck Esterbrook [mailto:ChuckEsterbrook@yahoo.com]

Let's say the user of a wxPython-based app is traversing a
list control,
grid or what-have-you with DOWN ARROW, and the keyboard
repeat rate is
faster than the background work associated with each change in
position. In my case, the background work is displaying a
preview of a
large image.

I think what I want to do is peek at the future events list
and if I see
additional movement events (arrow keys, for example), skip the
background work (e.g., the image preview). In this way, the
user could
traverse as quickly as their keyboard repeat rate is set.

Has anyone done anything like this? Is there a recommended approach?
None of the documented wxEvtHandler methods looked useful for this
purpose.

I don't know about peeking at future events, but I solved exactly the same
problem (in a tree control) using a timer. It worked really well for me. The
code looked something like this:

# 500 = 1/2 second. Change to suit.
DisplayDelay = 500

def __init__(...):
    # ...
    EVT_TREE_SEL_CHANGED(self,self.GetId(),self.OnItemSelect)
    self.selectionTimer = wxTimer(self,timerId)
    EVT_TIMER(self,timerId,self.OnSelectionTimer)
    # ...

def OnItemSelect(self, event):
    # ...
    # Start()ing a running timer restarts it
    self.selectionTimer.Start(DisplayDelay ,wxTIMER_ONE_SHOT)

def OnSelectionTimer(self,event):
    # Do the display

Good idea. So on the timer event, you can get the current selection and
display that image if it's not already displayed.

I think peeking at events would still be a little better because I
wouldn't need to add an arbitrary delay, but this still might work well
enough.

Thanks!

···

On Tuesday 08 April 2003 01:44 am, Richard Cooper wrote:

I don't know about peeking at future events, but I solved exactly the
same problem (in a tree control) using a timer. It worked really well
for me. The code looked something like this:

# 500 = 1/2 second. Change to suit.
DisplayDelay = 500

def __init__(...):
    # ...
    EVT_TREE_SEL_CHANGED(self,self.GetId(),self.OnItemSelect)
    self.selectionTimer = wxTimer(self,timerId)
    EVT_TIMER(self,timerId,self.OnSelectionTimer)
    # ...

def OnItemSelect(self, event):
    # ...
    # Start()ing a running timer restarts it
    self.selectionTimer.Start(DisplayDelay ,wxTIMER_ONE_SHOT)

def OnSelectionTimer(self,event):
    # Do the display

--
Chuck
http://ChuckEsterbrook.com

Chuck Esterbrook wrote:

I think peeking at events would still be a little better because I wouldn't need to add an arbitrary delay, but this still might work well enough.

Unfortunatly there is no way to do an event look ahead.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!