dabo Commit
Revision 4317
Date: 2008-07-24 14:04:54 -0700 (Thu, 24 Jul 2008)
Author: Paul
Trac: http://svn.dabodev.com/trac/dabo/changeset/4317

Changed:
U   trunk/dabo/ui/uiwx/dDialog.py

Log:
Fixed dDialog.CancelOnEscape on Windows. Will test Mac and Windows next.

Diff:
Modified: trunk/dabo/ui/uiwx/dDialog.py
===================================================================
--- trunk/dabo/ui/uiwx/dDialog.py       2008-07-23 23:20:31 UTC (rev 4316)
+++ trunk/dabo/ui/uiwx/dDialog.py       2008-07-24 21:04:54 UTC (rev 4317)
@@ -50,7 +50,6 @@
                self.MenuBarClass = None
                self.Sizer = dabo.ui.dSizer("V")
                super(dDialog, self)._afterInit()
-               self.bindKey("esc", self._onEscape)
 
 
        def Show(self, show=True, *args, **kwargs):
@@ -99,11 +98,7 @@
                return retVals.get(ret)
                
 
-       def _onEscape(self, evt):
-               evt.stop()
-               self.hide()
 
-
        def _addControls(self):
                """Any controls that need to be added to the dialog 
                can be added in this method in framework classes, or
@@ -234,6 +229,9 @@
 
 
        def _addControls(self):
+               # Tell wx not to intercept the esc key.
+               self.SetEscapeId(wx.ID_NONE)
+
                # Set some default Sizer properties (user can easily override):
                sz = self.Sizer
                sz.DefaultBorder = 20
@@ -280,6 +278,7 @@
                                mthd = self._onYes
                        elif id_ == wx.ID_NO:
                                self.btnNo = newbtn = 
dabo.ui.dButton(btn.Parent)
+                               self.setEscapeButton(newbtn)
                                mthd = self._onNo
                        elif id_ == wx.ID_OK:
                                self.btnOK = newbtn = 
dabo.ui.dButton(btn.Parent)
@@ -287,6 +286,7 @@
                        elif id_ == wx.ID_CANCEL:
                                self.btnCancel = newbtn = 
dabo.ui.dButton(btn.Parent)
                                mthd = self._onCancel
+                               self.setEscapeButton(newbtn)
                        elif id_ == wx.ID_HELP:
                                self.btnHelp = btn
                                newbtn = None
@@ -315,8 +315,6 @@
                                buttons.append(win)
                for pos, btn in enumerate(buttons[1:]):
                        btn.MoveAfterInTabOrder(buttons[pos-1])
-               self.SetEscapeId(wx.ID_NONE)
-               self.bindKey("esc", self._onEscapePressed)
 
                # Let the user add their controls
                super(dStandardButtonDialog, self)._addControls()
@@ -333,18 +331,18 @@
                self.layout()
 
 
-       def _onEscapePressed(self, evt):
-               if self.CancelOnEscape:
-                       if self.CancelButton:
-                               self._onCancel(evt)
-                       elif self.NoButton:
-                               self._onNo(evt)
-                       elif self.OKButton:
-                               self._onOK(evt)
-                       elif self.YesButton:
-                               self._onYes(evt)
+       def setEscapeButton(self, btn=None):
+               """Set which button gets hit when Esc pressed.
 
+               CancelOnEscape must be True for this to work.
+               """
+               if not self.CancelOnEscape or not btn:
+                       self.SetEscapeId(wx.ID_NONE)
+               else:
+                       self.SetEscapeId(btn.GetId())
 
+
+
        ################################################
        #    Handlers for the standard buttons. 
        ################################################
@@ -366,6 +364,7 @@
                        pass
                if self.runOK() is not False:
                        self.EndModal(kons.DLG_OK)
+
        def _onCancel(self, evt):
                self.Accepted = False
                try:
@@ -380,14 +379,20 @@
                self.runCancel()
                if self.runCancel() is not False:
                        self.EndModal(kons.DLG_CANCEL)
+               else:
+                       evt.stop()
        def _onYes(self, evt):
                self.Accepted = True
                if self.runYes() is not False:
                        self.EndModal(kons.DLG_YES)
+
        def _onNo(self, evt):
                self.Accepted = False
                if self.runNo() is not False:
                        self.EndModal(kons.DLG_NO)
+               else:
+                       evt.stop()
+
        def _onHelp(self, evt):
                self.runHelp()
 
@@ -460,6 +465,12 @@
        def _setCancelOnEscape(self, val):
                if self._constructed():
                        self._cancelOnEscape = val
+                       self.setEscapeButton(None)
+                       if val:
+                               for trial in (self.btnCancel, self.btnNo):
+                                       if trial is not None:
+                                               self.setEscapeButton(trial)
+                                               break
                else:
                        self._properties["CancelOnEscape"] = val
 




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to