Platform: MSW (XP) Python 2.5 wxPython 2.8
Topic: Clear Keyboard buffer
Hi,
my application shows graphical output on a Canvas and
accepts keyboard input (no buttons, no widgets, no mouse).
When enter is pressed, some calculations are done and
the result is presented as voice output (concatenating
and playing some wav files).
The problem is, that while playing the sounds the user
could press further buttons. Their events are buffered
somewhere and are processed when SayScore is finished.
I don't want that. So I have to:
1. Disable OnKeyEvent before calling SayScore, or
2. clear the keyboard buffer after SayScore
Yield doesn't work because I don't want to process any
keys during voice output.
Threads don't work because then several voice outputs
could appear at the same time.
Playing the sounds ASYNC doesn't work for the same
reason.
I did find the function app.Pending() and I look for
something like:
while app.Pending():
if KeyEvent:
app.KillThatKeyEvent()
at the end of SayScore.
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.NextInput()
#--------------
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.Play(wx.SOUND_SYNC)
...
#--------------
Any ideas?
Thanks in advance
Marcus
--
View this message in context: http://www.nabble.com/Clearing-the-keyboard-buffer-or-kill-pending-events-tp21973194p21973194.html
Sent from the wxPython-users mailing list archive at Nabble.com.