[gnue] r9651 - trunk/gnue-forms/src/uidrivers/wx26/widgets

[email protected]
Newsgroups gmane.comp.cms.gnue.cvs
Message-ID <[email protected]>
Author: johannes
Date: 2007-06-04 07:51:21 -0500 (Mon, 04 Jun 2007)
New Revision: 9651

Modified:
   trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py
   trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
Log:
Escape-key closes a Dialog


Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py	2007-05-31 14:36:20 UTC (rev 9650)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/button.py	2007-06-04 12:51:21 UTC (rev 9651)
@@ -65,6 +65,7 @@
         self.widget = wx.Button(parent, -1, self._gfObject.label, size=csize)
         self.widget.Bind(wx.EVT_BUTTON   , self.__on_button)
         self.widget.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus)
+        self.widget.Bind(wx.EVT_KEY_DOWN , self.__on_key_down)
         self.widget.Bind(wx.EVT_CHAR     , self.__on_char)
 
         if self.in_grid:
@@ -96,7 +97,24 @@
             else:
                 event.Skip()
 
+    # -------------------------------------------------------------------------
 
+    def __on_key_down(self, event):
+
+        # FIXME: Until a button can be flagged as 'Cancel'-Button, which closes
+        # a dialog after the user pressed the escape key, we have to 'simulate'
+        # that behaviour here.  This event handler can be removed, as soon as
+        # such a button is available.  This handler cannot be integrated into
+        # EVT_CHAR, since wxMSW does not generate such an event for WXK_ESCAPE
+        keycode = event.GetKeyCode()
+
+        if isinstance(self._uiForm.main_window, wx.Dialog) and \
+                keycode == wx.WXK_ESCAPE:
+            self._uiForm.main_window.Close()
+        else:
+            event.Skip()
+
+
     # -------------------------------------------------------------------------
 
     def __on_button (self, event):

Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py	2007-05-31 14:36:20 UTC (rev 9650)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py	2007-06-04 12:51:21 UTC (rev 9651)
@@ -110,6 +110,7 @@
         ctrl = wx.TextCtrl(parent, -1, size=csize, style=xFlags)
         ctrl.Bind(wx.EVT_CHAR, self.__on_keypress)
         ctrl.Bind(wx.EVT_TEXT, self.__on_text_changed)
+        ctrl.Bind(wx.EVT_KEY_DOWN, self.__on_key_down)
 
         ctrl.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus)
 
@@ -142,6 +143,7 @@
                 style=wx.CHK_3STATE)
         result.Bind (wx.EVT_CHECKBOX, self.__on_toggle_checkbox)
         result.Bind (wx.EVT_CHAR, self.__on_keypress)
+        result.Bind (wx.EVT_KEY_DOWN, self.__on_key_down)
         result.Bind (wx.EVT_SET_FOCUS, self.__on_set_focus)
 
         label = None
@@ -194,6 +196,7 @@
         result = wx.ListBox(parent, -1, size=csize, style=wx.LB_SINGLE)
 
         result.Bind(wx.EVT_LISTBOX, self.__on_item_selected)
+        result.Bind(wx.EVT_KEY_DOWN, self.__on_key_down)
         result.Bind(wx.EVT_SET_FOCUS, self.__on_set_focus)
 
         return [self.__add_entry_label(parent), result]
@@ -315,8 +318,27 @@
 
         event.Skip()
 
+
     # -------------------------------------------------------------------------
 
+    def __on_key_down(self, event):
+
+        # FIXME: Until a button can be flagged as 'Cancel'-Button, which closes
+        # a dialog after the user pressed the escape key, we have to 'simulate'
+        # that behaviour here.  This event handler can be removed, as soon as
+        # such a button is available.  This event cannot be integrated into
+        # EVT_CHAR since wxMSW does not generate such an event for WXK_ESCAPE.
+        keycode = event.GetKeyCode()
+
+        if isinstance(self._uiForm.main_window, wx.Dialog) and \
+                keycode == wx.WXK_ESCAPE:
+            self._uiForm.main_window.Close()
+        else:
+            event.Skip()
+
+
+    # -------------------------------------------------------------------------
+
     def __on_keypress(self, event):
 
         keycode = event.GetKeyCode()
@@ -353,6 +375,14 @@
         keycode = event.GetKeyCode()
         command = None
 
+        # FIXME: Until a button can be flagged as 'Cancel'-Button, which closes
+        # a dialog after the user pressed the escape key, we have to 'simulate'
+        # that behaviour here.
+        if isinstance(self._uiForm.main_window, wx.Dialog) and \
+                keycode == wx.WXK_ESCAPE:
+            self._uiForm.main_window.Close()
+            return
+
         allowed = [wx.WXK_RETURN, wx.WXK_TAB]
 
         if keycode in allowed:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.