Clearing the keyboard buffer (wxPython)

2009-02-11 Thread MarcusD

Platform: MSW (XP) Python 2.5 wxPython 2.8
Topic: Clear Keyboard buffer

Hi,
I hope I am not off topic asking a wxpython question.
I'm writing a Score counter for Dart games. The software
shows graphical output on a Canvas and accepts keyboard
input (no buttons, no widgest). A stripped version looks
like that:

self.Bind(wx.EVT_CHAR,OnKeyEvent)
.
.
#--
def OnKeyEvent(self, event):
  k =event.GetKeyCode()
  try:
z=chr(k)
  except:
return
  if (z in ["0","1","2","3","4","5","6","7","8","9",.."\r"..]:
self.keystr +=z
score=self.CalculateScore(self.keystr)
self.DisplayScore(score)
.
.
  if z== "\r" #enter
self.SayScore(score)
self.NextPlayer()
#--
def SayScore(self,number):
  if number > 100:
a=os.path.join(self.wavpath,"100.wav")
b=os.path.join(self.wavpath,"%i.wav"%(number-100))
  else:
a=os.path.join(self.wavpath,"%i.wav"%(number))
b=""
  sound1 = wx.Sound(a)
  sound2 = wx.Sound(b)
  sound1.Play(wx.SOUND_SYNC)
  if b:
sound2.HurryupandPlay(wx.SOUND_SYNC)
#--

The problem is, that during the voice output all keystrokes
are buffered somewhere and are processed when SayScore is
finished. So I have to clear the keyboard buffer at the end
of SayScore. Something like:

  evt=MagicFetchPendingKeyEventFunction()
  while evt:
evt=MagicFetchPendingKeyEventFunction()

I was thinking about threading (maybe using delayedresults), but
this might be a little oversized for my problem.
Playing the sound ASYNC doesn't work here.

Any ideas?
Thanks in advance
Marcus


--
http://mail.python.org/mailman/listinfo/python-list


Re: Clearing the keyboard buffer (wxPython)

2009-02-11 Thread MarcusD
Whow. Thanks for the fast and comprehensive answer. To be honest I would 
have posted to wxpython.org but the server seems to be down for the last 
couple of days.

I'll check this wx.Yield thing that I never heard of. And let's see what 
else we get here.
Thanks again
marcus 


--
http://mail.python.org/mailman/listinfo/python-list