[Tutor] wx accelerator table: one keystroke seems skipped

Alex Hall mehgcap at gmail.com
Wed Jan 5 22:41:17 CET 2011


Hello all,
First, this is about a wx accelerator table, so if it is too off-topic
for this list, let me know.

I have a table with 23 entries, all of which work. I added another
entry last night, and it does not work. The odd thing, though, is that
I do not get an error of any kind anywhere in the program, the
keystroke simply does not call the function to which it should be
bound. I even changed the function name to something that should have
thrown an exception, but nothing at all happens. The keystroke in
question is ctrl+m and is tied to ctrlM_id and the cancelMove()
function. Below I have pasted my entire setHotkeys() function. Again,
everything works except ctrl+m, but even that keystroke does not cause
problems, it is like it is not even there.

def setHotkeys():
 upArrow_id=wx.NewId()
 downArrow_id=wx.NewId()
 leftArrow_id=wx.NewId()
 rightArrow_id=wx.NewId()
 space_id=wx.NewId()
 a_id=wx.NewId()
 f_id=wx.NewId()
 m_id=wx.NewId()
 r_id=wx.NewId()
 ctrlM_id=wx.NewId()
 ctrlN_id=wx.NewId()
 one_id=wx.NewId()
 two_id=wx.NewId()
 three_id=wx.NewId()
 four_id=wx.NewId()
 five_id=wx.NewId()
 six_id=wx.NewId()
 seven_id=wx.NewId()
 f1_id=wx.NewId()
 f2_id=wx.NewId()
 f3_id=wx.NewId()
 f4_id=wx.NewId()
 hotkeyList=[
  (wx.ACCEL_NORMAL, wx.WXK_UP, upArrow_id), #up one face-up card in
the current stack
  (wx.ACCEL_NORMAL, wx.WXK_DOWN, downArrow_id), #down one face-up card
  (wx.ACCEL_NORMAL, wx.WXK_LEFT, leftArrow_id), #left a stack
  (wx.ACCEL_NORMAL, wx.WXK_RIGHT, rightArrow_id), #right a stack
  (wx.ACCEL_NORMAL, ord('a'), a_id), #try to move last card to Ace stack
  (wx.ACCEL_NORMAL, ord('1'), one_id), #jump to stack 1
  (wx.ACCEL_NORMAL, ord('2'), two_id), #jump to stack 2
  (wx.ACCEL_NORMAL, ord('3'), three_id), #jump to stack 3
  (wx.ACCEL_NORMAL, ord('4'), four_id), #jump to stack 4
  (wx.ACCEL_NORMAL, ord('5'), five_id), #jump to stack 5
  (wx.ACCEL_NORMAL, ord('6'), six_id), #jump to stack 6
  (wx.ACCEL_NORMAL, ord('7'), seven_id), #jump to stack 7
  (wx.ACCEL_NORMAL, ord('f'), f_id), #flip up a new card
  (wx.ACCEL_NORMAL, ord('r'), r_id), #read the current deck card in play
  (wx.ACCEL_CTRL, ord('m'), ctrlM_id), #cancel Move mode
  (wx.ACCEL_CTRL, ord('n'), ctrlN_id), #start a new hand
  (wx.ACCEL_NORMAL, ord('m'), m_id), #mark stack to be moved
  (wx.ACCEL_NORMAL, wx.WXK_SPACE, space_id), #move deck's facing card
to activeStack
  #now f1-f4, for reviewing the four Ace stacks
  (wx.ACCEL_NORMAL, wx.WXK_F1, f1_id),
  (wx.ACCEL_NORMAL, wx.WXK_F2, f2_id),
  (wx.ACCEL_NORMAL, wx.WXK_F3, f3_id),
  (wx.ACCEL_NORMAL, wx.WXK_F4, f4_id)]
 #now bind the keys to their functions, using lambda to pass args
 f.Bind(wx.EVT_MENU, lambda evt, dir=1: exploreStack(evt, dir), id=upArrow_id)
 f.Bind(wx.EVT_MENU, lambda evt, dir=-1: exploreStack(evt, dir),
id=downArrow_id)
 f.Bind(wx.EVT_MENU, lambda evt, dir=-1: move(evt, dir), id=leftArrow_id)
 f.Bind(wx.EVT_MENU, lambda evt, dir=1: move(evt, dir), id=rightArrow_id)
 f.Bind(wx.EVT_MENU, lambda evt: useDeckCard(evt), id=space_id)
 f.Bind(wx.EVT_MENU, lambda evt: toAcePile(evt), id=a_id)
 f.Bind(wx.EVT_MENU, lambda evt: deal(evt), id=f_id)
 f.Bind(wx.EVT_MENU, lambda evt: readDeckCard(evt), id=r_id)
 f.Bind(wx.EVT_MENU, lambda evt, target=1, jump=True: move(evt,
target, jump), id=one_id)
 f.Bind(wx.EVT_MENU, lambda evt, target=2, jump=True: move(evt,
target, jump), id=two_id)
 f.Bind(wx.EVT_MENU, lambda evt, target=3, jump=True: move(evt,
target, jump), id=three_id)
 f.Bind(wx.EVT_MENU, lambda evt, target=4, jump=True: move(evt,
target, jump), id=four_id)
 f.Bind(wx.EVT_MENU, lambda evt, target=5, jump=True: move(evt,
target, jump), id=five_id)
 f.Bind(wx.EVT_MENU, lambda evt, target=6, jump=True: move(evt,
target, jump), id=six_id)
 f.Bind(wx.EVT_MENU, lambda evt, target=7, jump=True: move(evt,
target, jump), id=seven_id)
 f.Bind(wx.EVT_MENU, lambda evt, sel=activeStack: selectStack(evt,
sel), id=m_id)
 f.Bind(wx.EVT_MENU, lambda evt: cancelMove(evt), id=ctrlM_id)
 f.Bind(wx.EVT_MENU, lambda evt: promptForNewGame(evt), id=ctrlN_id)
 f.Bind(wx.EVT_MENU, lambda evt, target=0: reviewAceStack(evt,
target), id=f1_id)
 f.Bind(wx.EVT_MENU, lambda evt, target=1: reviewAceStack(evt,
target), id=f2_id)
 f.Bind(wx.EVT_MENU, lambda evt, target=2: reviewAceStack(evt,
target), id=f3_id)
 f.Bind(wx.EVT_MENU, lambda evt, target=3: reviewAceStack(evt,
target), id=f4_id)
 hotkeys=wx.AcceleratorTable(hotkeyList)
 f.SetAcceleratorTable(hotkeys)

-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap


More information about the Tutor mailing list