X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/299647acac7960652aadb008775429c1f8ea9b8d..b843b628c9f936d6a87ca1e9b91e88a4604270c4:/wxPython/demo/KeyEvents.py diff --git a/wxPython/demo/KeyEvents.py b/wxPython/demo/KeyEvents.py index c992865219..36eb764fa6 100644 --- a/wxPython/demo/KeyEvents.py +++ b/wxPython/demo/KeyEvents.py @@ -1,15 +1,3 @@ -# 11/19/2003 - Jeff Grimmett (grimmtooth@softhome.net) -# -# o Updated for wx namespace -# -# 11/29/2003 - Jeff Grimmett (grimmtooth@softhome.net) -# -# o lib.mixins.listctrl needs wx renamer applied. -# -# 12/21/2003 - Jeff Grimmett (grimmtooth@softhome.net) -# -# o wxListCtrlAutoWidthMixin -> ListCtrlAutoWidthMixin -# import wx import wx.lib.mixins.listctrl as listmix @@ -209,21 +197,27 @@ class KeySink(wx.Window): #---------------------------------------------------------------------- class KeyLog(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin): + colHeaders = [ "Event Type", + "Key Name", + "Key Code", + "Modifiers", + "Unicode", + "RawKeyCode", + "RawKeyFlags", + ] def __init__(self, parent): wx.ListCtrl.__init__(self, parent, -1, style = wx.LC_REPORT|wx.LC_VRULES|wx.LC_HRULES) listmix.ListCtrlAutoWidthMixin.__init__(self) - self.InsertColumn(0, "Event Type") - self.InsertColumn(1, "Key Name") - self.InsertColumn(2, "Key Code") - self.InsertColumn(3, "Modifiers") - self.InsertColumn(4, "RawKeyCode") - self.InsertColumn(5, "RawKeyFlags") - self.InsertColumn(6, "") + for idx, header in enumerate(self.colHeaders): + self.InsertColumn(idx, header) + idx += 1 + print idx + self.InsertColumn(idx, "") - for x in range(6): + for x in range(idx): self.SetColumnWidth(x, wx.LIST_AUTOSIZE_USEHEADER) self.SetColumnWidth(1, 125) @@ -257,8 +251,9 @@ class KeyLog(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin): self.SetStringItem(id, 1, keyname) self.SetStringItem(id, 2, str(keycode)) self.SetStringItem(id, 3, modifiers) - self.SetStringItem(id, 4, str(evt.GetRawKeyCode())) - self.SetStringItem(id, 5, str(evt.GetRawKeyFlags())) + self.SetStringItem(id, 4, str(evt.GetUnicodeKey())) + self.SetStringItem(id, 5, str(evt.GetRawKeyCode())) + self.SetStringItem(id, 6, str(evt.GetRawKeyFlags())) #print ( id, evType, keyname, str(keycode), modifiers, str(evt.GetRawKeyCode()), str(evt.GetRawKeyFlags())) @@ -268,6 +263,32 @@ class KeyLog(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin): def ClearLog(self): self.DeleteAllItems() + def CopyLog(self): + # build a newline and tab delimited string to put into the clipboard + if "unicode" in wx.PlatformInfo: + st = u"" + else: + st = "" + for h in self.colHeaders: + st += h + "\t" + st += "\n" + + for idx in range(self.GetItemCount()): + for col in range(self.GetColumnCount()): + item = self.GetItem(idx, col) + st += item.GetText() + "\t" + st += "\n" + + data = wx.TextDataObject() + data.SetText(st) + if wx.TheClipboard.Open(): + wx.TheClipboard.SetData(data) + wx.TheClipboard.Close() + else: + wx.MessageBox("Unable to open the clipboard", "Error") + + + #---------------------------------------------------------------------- @@ -277,29 +298,33 @@ class TestPanel(wx.Panel): self.log = log wx.Panel.__init__(self, parent, -1, style=0) self.keysink = KeySink(self) - self.keysink.SetSize((100, 65)) + self.keysink.SetMinSize((100, 65)) self.keylog = KeyLog(self) - btn = wx.Button(self, -1, "Clear Log") + btn = wx.Button(self, -1, "Clear", style=wx.BU_EXACTFIT) self.Bind(wx.EVT_BUTTON, self.OnClearBtn, btn) - cb1 = wx.CheckBox(self, -1, "Call evt.Skip for Key Up/Dn events") + btn2 = wx.Button(self, -1, "Copy", style=wx.BU_EXACTFIT) + self.Bind(wx.EVT_BUTTON, self.OnCopyBtn, btn2) + + cb1 = wx.CheckBox(self, -1, "Call evt.Skip in Key* events") self.Bind(wx.EVT_CHECKBOX, self.OnSkipCB, cb1) - cb2 = wx.CheckBox(self, -1, "EVT_KEY_UP") + cb2 = wx.CheckBox(self, -1, "KEY_UP") self.Bind(wx.EVT_CHECKBOX, self.OnKeyUpCB, cb2) cb2.SetValue(True) - cb3 = wx.CheckBox(self, -1, "EVT_KEY_DOWN") + cb3 = wx.CheckBox(self, -1, "KEY_DOWN") self.Bind(wx.EVT_CHECKBOX, self.OnKeyDnCB, cb3) cb3.SetValue(True) - cb4 = wx.CheckBox(self, -1, "EVT_CHAR") + cb4 = wx.CheckBox(self, -1, "CHAR") self.Bind(wx.EVT_CHECKBOX, self.OnCharCB, cb4) cb4.SetValue(True) buttons = wx.BoxSizer(wx.HORIZONTAL) buttons.Add(btn, 0, wx.ALL, 4) + buttons.Add(btn2, 0, wx.ALL, 4) buttons.Add(cb1, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, 6) buttons.Add(cb2, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 6) buttons.Add(cb3, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT, 6) @@ -316,6 +341,9 @@ class TestPanel(wx.Panel): def OnClearBtn(self, evt): self.keylog.ClearLog() + def OnCopyBtn(self, evt): + self.keylog.CopyLog() + def OnSkipCB(self, evt): self.keysink.SetCallSkip(evt.GetInt()) @@ -353,5 +381,5 @@ It is meant to be used as a compatibility test for cross platform work. if __name__ == '__main__': import sys,os import run - run.main(['', os.path.basename(sys.argv[0])]) + run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])