From a926640f1a7c671e303843189eb6cf3d54b99cd5 Mon Sep 17 00:00:00 2001 From: Gyedo Jeon Date: Fri, 26 Feb 2010 20:05:51 +0000 Subject: [PATCH] Added key down, up event binding --- direct/src/leveleditor/HotKeyUI.py | 4 +-- direct/src/leveleditor/LevelEditorUIBase.py | 35 +++++++++++++++++++-- direct/src/leveleditor/ObjectMgr.py | 4 +-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/direct/src/leveleditor/HotKeyUI.py b/direct/src/leveleditor/HotKeyUI.py index c7ab6f2b83..0281acccce 100755 --- a/direct/src/leveleditor/HotKeyUI.py +++ b/direct/src/leveleditor/HotKeyUI.py @@ -139,7 +139,7 @@ class HotKeyPanel(ScrolledPanel): self.parent.parent.updateMenu() def onEdit(self, evt, key): - base.le.ui.wxApp.Unbind(wx.EVT_CHAR) + base.le.ui.bindKeyEvents(False) editUI = EditHotKeyDialog(self, -1, 'Edit Hot Key', key) editUI.ShowModal() editUI.Destroy() @@ -148,7 +148,7 @@ class HotKeyPanel(ScrolledPanel): if sizer is not None: sizer.DeleteWindows() self.SetSizer(None) - base.le.ui.wxApp.Bind(wx.EVT_CHAR, base.le.ui.onKeyEvent) + base.le.ui.bindKeyEvents(True) self.updateUI() class HotKeyUI(wx.Dialog): diff --git a/direct/src/leveleditor/LevelEditorUIBase.py b/direct/src/leveleditor/LevelEditorUIBase.py index 730175a0a6..a9a9a271cc 100755 --- a/direct/src/leveleditor/LevelEditorUIBase.py +++ b/direct/src/leveleditor/LevelEditorUIBase.py @@ -130,9 +130,19 @@ class LevelEditorUIBase(WxAppShell): if not kw.get('size'): kw['size'] = wx.Size(self.frameWidth, self.frameHeight) WxAppShell.__init__(self, *args, **kw) - self.wxApp.Bind(wx.EVT_CHAR, self.onKeyEvent) + self.bindKeyEvents(True) self.initialize() + def bindKeyEvents(self, toBind=True): + if toBind: + self.wxApp.Bind(wx.EVT_CHAR, self.onKeyEvent) + self.wxApp.Bind(wx.EVT_KEY_DOWN, self.onKeyDownEvent) + self.wxApp.Bind(wx.EVT_KEY_UP, self.onKeyUpEvent) + else: + self.wxApp.Unbind(wx.EVT_CHAR) + self.wxApp.Unbind(wx.EVT_KEY_DOWN) + self.wxApp.Unbind(wx.EVT_KEY_UP) + def createMenu(self): menuItem = self.menuFile.Insert(0, ID_NEW, self.MENU_TEXTS[ID_NEW][0]) self.Bind(wx.EVT_MENU, self.onNew, menuItem) @@ -264,8 +274,29 @@ class LevelEditorUIBase(WxAppShell): self.layerEditorUI = LayerEditorUI(self.rightBarDownPane0, self.editor) self.showGridMenuItem.Check(True) + + def onKeyDownEvent(self, evt): + if evt.GetKeyCode() == wx.WXK_ALT: + base.direct.fAlt = 1 + elif evt.GetKeyCode() == wx.WXK_CONTROL: + base.direct.fControl = 1 + elif evt.GetKeyCode() == wx.WXK_SHIFT: + base.direct.fShift = 1 + else: + evt.Skip() + + def onKeyUpEvent(self, evt): + if evt.GetKeyCode() == wx.WXK_ALT: + base.direct.fAlt = 0 + elif evt.GetKeyCode() == wx.WXK_CONTROL: + base.direct.fControl = 0 + elif evt.GetKeyCode() == wx.WXK_SHIFT: + base.direct.fShift = 0 + else: + evt.Skip() def onKeyEvent(self, evt): + input = '' if evt.GetKeyCode() in range(97, 123): # for keys from a to z if evt.GetModifiers() == 4: # when shift is pressed while caps lock is on input = 'shift-%s'%chr(evt.GetKeyCode()) @@ -287,7 +318,7 @@ class LevelEditorUIBase(WxAppShell): input = 'shift-%s'%chr(evt.GetKeyCode()) elif evt.GetModifiers() == 2: input = 'control-%s'%chr(evt.GetKeyCode()) - else: + elif evt.GetKeyCode() < 256: input = chr(evt.GetKeyCode()) if input in base.direct.hotKeyMap.keys(): keyDesc = base.direct.hotKeyMap[input] diff --git a/direct/src/leveleditor/ObjectMgr.py b/direct/src/leveleditor/ObjectMgr.py index 9772c69249..9bc937e217 100755 --- a/direct/src/leveleditor/ObjectMgr.py +++ b/direct/src/leveleditor/ObjectMgr.py @@ -200,11 +200,11 @@ class ObjectMgr: def onEnterObjectPropUI(self, event): taskMgr.remove('_le_updateObjectUITask') - self.editor.ui.wxApp.Unbind(wx.EVT_CHAR) + self.editor.ui.bindKeyEvents(False) def onLeaveObjectPropUI(self, event): self.spawnUpdateObjectUITask() - self.editor.ui.wxApp.Bind(wx.EVT_CHAR, self.editor.ui.onKeyEvent) + self.editor.ui.bindKeyEvents(True) def spawnUpdateObjectUITask(self): if self.currNodePath is None: