unregistering hot key does not work
jeremy alexander
jccfifkf at yahoo.com
Sat Sep 2 15:41:23 PDT 2006
Hi,
I'm trying to implement a feature where a hotkey is
only enabled temporarily.
I have no trouble enabling the hotkey by registering
it. However, the unregister method always returns
fail and the hotkey is still active.
A test program is below. It enables the Escape key to
be a hotkey and then for test purposes it immediately
tries to disable it. The print results indicate that
the unregistering failed. If you press escape
anywhere on the console after the radiobox is
displayed, the hotkey handler prints a message
indicating that the escape key is still a hotkey
Jeremy.
======================================
import wx
#----------------------------------------------------------------------
class Panel1(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.parent = parent
self.SetupAbortHotKeyEscape()
# create radio button
regexlist = ['test1',
'test2',
]
self.rb = wx.RadioBox(
self, -1, "Test Box",
wx.DefaultPosition, wx.DefaultSize,
regexlist, len (regexlist),
wx.RA_SPECIFY_COLS
)
lbox = wx.StaticBox(self, -1, 'Static box
label')
regexsizer = wx.BoxSizer(wx.HORIZONTAL)
self.mastersizer = wx.BoxSizer(wx.VERTICAL)
self.mastersizer.Add(regexsizer, 10.25,
wx.ALL|wx.EXPAND,
0)
self.SetSizer(self.mastersizer)
self.Show(True)
def OnAbortHotKey(self, e) :
print "abort key preesed"
def SetupAbortHotKeyEscape(self) :
self.HOTKEY_OFFSET = 0xbf00
rcode =
self.RegisterHotKey(wx.WXK_ESCAPE+self.HOTKEY_OFFSET,
0, wx.WXK_ESCAPE)
print "register escape; rcode is: ", rcode,
wx.WXK_ESCAPE+self.HOTKEY_OFFSET
wx.EVT_HOTKEY(self,
wx.WXK_ESCAPE+self.HOTKEY_OFFSET, self.OnAbortHotKey)
rcode =
self.UnregisterHotKey(wx.WXK_ESCAPE+self.HOTKEY_OFFSET)
print "unreg escape; rcode is: ", rcode,
wx.WXK_ESCAPE+self.HOTKEY_OFFSET
class MainWindow(wx.Frame):
def __init__(self,parent,id, title):
wx.Frame.__init__(self,parent,wx.ID_ANY,title,size=(200,100),
style=wx.DEFAULT_FRAME_STYLE)
self.control = Panel1(self,-1)
self.Show(True)
app = wx.PySimpleApp()
frame=MainWindow(None,-1, 'test window')
frame.Show()
app.MainLoop()
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the wxpython-users
mailing list