Trouble with accelerators

Hi,

Was a change made to the accelerator system between 2.8.4.0 and 2.8.9.1? I can't find a mention of it in recent changes, but the following code works on the former, but 'OnFunctionKey' is never invoked on the later. Both systems run Windows XP. The former has Python 2.4.x and the later has 2.5.x, although I have trouble thinking that matters.

TIA,
-Gary

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)

        accel = [( wx.ACCEL_NORMAL, wx.WXK_F1, 101),
                     ( wx.ACCEL_NORMAL, wx.WXK_F2, 102),
                     ( wx.ACCEL_NORMAL, wx.WXK_F3, 103),
                     ( wx.ACCEL_NORMAL, wx.WXK_F4, 104),
                     ( wx.ACCEL_NORMAL, wx.WXK_F5, 105)
        ]
        aTable = wx.AcceleratorTable(accel)
        self.SetAcceleratorTable(aTable)

        self.Bind(wx.EVT_MENU, self.OnFunctionKey, id=101, id2=105)

    def OnFunctionKey(self, evt):
        print 'OnFunctionKey', evt.GetId()

class MyApp(wx.App):
    def OnInit(self):
        self.frame = MyFrame(None, -1, "Accelerator Test")
        self.frame.Show(True)
        self.SetTopWindow(self.frame)
        return True

if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()

Gary,

Hi,
Was a change made to the accelerator system between 2.8.4.0 and 2.8.9.1? I can't find a mention of it in recent changes, but the following code works on the former, but 'OnFunctionKey' is never invoked on the later. Both systems run Windows XP. The former has Python 2.4.x and the later has 2.5.x, although I have trouble thinking that matters.
TIA,
-Gary

If I recall correctly, a bug was introduced in the new version that requires a menubar for accelerators to work on Windows. The menubar doesn't have to be visible...it just needs to exist. It's been mentioned a few times in the archives. I'm not sure if Robin has that fixed in the next release or if it's something we'll have to wait for the wx devs to fix.

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Hi All,

···

On Tue, Feb 3, 2009 at 7:21 PM, Mike Driscoll wrote:

Gary,

Hi,
Was a change made to the accelerator system between 2.8.4.0 and 2.8.9.1?
I can't find a mention of it in recent changes, but the following code
works on the former, but 'OnFunctionKey' is never invoked on the later.
Both systems run Windows XP. The former has Python 2.4.x and the later has
2.5.x, although I have trouble thinking that matters.
TIA,
-Gary

If I recall correctly, a bug was introduced in the new version that requires
a menubar for accelerators to work on Windows. The menubar doesn't have to
be visible...it just needs to exist. It's been mentioned a few times in the
archives. I'm not sure if Robin has that fixed in the next release or if
it's something we'll have to wait for the wx devs to fix.

It has been fixed and it works in the current wxPython pre-release
(tested with FlatMenu).

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

Gary L Hubbard wrote:

Hi,
Was a change made to the accelerator system between 2.8.4.0 and 2.8.9.1? I can't find a mention of it in recent changes, but the following code works on the former, but 'OnFunctionKey' is never invoked on the later. Both systems run Windows XP. The former has Python 2.4.x and the later has 2.5.x, although I have trouble thinking that matters.

There is a problem in 2.8.9.1 where accelerators are ignored if the frame doesn't have a menubar. This has already been fixed for the next release.

···

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