dabo Commit
Revision 4170
Date: 2008-06-20 09:42:56 -0700 (Fri, 20 Jun 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4170

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

Log:
Fixed the behavior of CancelOnEscape. Now if this is set to False at any time, 
the Escape key will be ignored.


Diff:
Modified: trunk/dabo/ui/uiwx/dDialog.py
===================================================================
--- trunk/dabo/ui/uiwx/dDialog.py       2008-06-20 16:41:06 UTC (rev 4169)
+++ trunk/dabo/ui/uiwx/dDialog.py       2008-06-20 16:42:56 UTC (rev 4170)
@@ -207,6 +207,9 @@
                self._yes = self._extractKey((properties, kwargs), "Yes")
                self._no = self._extractKey((properties, kwargs), "No")
                self._help = self._extractKey((properties, kwargs), "Help")
+               # Check for both OK and Yes. This simply does not work, at 
least with wxPython.
+               if self._ok and self._yes:
+                       raise ValueError, _("Dialogs cannot have both 'OK' and 
'Yes' buttons.")
                self._cancelOnEscape = True
                super(dStandardButtonDialog, self).__init__(parent=parent, 
properties=properties, *args, **kwargs)
                self._baseClass = dStandardButtonDialog
@@ -255,22 +258,36 @@
                btns = [b.GetWindow() for b in sbs.GetChildren() if 
b.IsWindow()]
                for btn in btns:
                        id_ = btn.GetId()
-                       if id_ == wx.ID_OK:
-                               self.btnOK = btn
+                       if id_ == wx.ID_YES:
+                               self.btnYes = newbtn = 
dabo.ui.dButton(btn.Parent)
+                               mthd = self._onYes
+                       elif id_ == wx.ID_NO:
+                               self.btnNo = newbtn = 
dabo.ui.dButton(btn.Parent)
+                               mthd = self._onNo
+                       elif id_ == wx.ID_OK:
+                               self.btnOK = newbtn = 
dabo.ui.dButton(btn.Parent)
                                mthd = self._onOK
                        elif id_ == wx.ID_CANCEL:
-                               self.btnCancel = btn
+                               self.btnCancel = newbtn = 
dabo.ui.dButton(btn.Parent)
                                mthd = self._onCancel
-                       elif id_ == wx.ID_YES:
-                               self.btnYes = btn
-                               mthd = self._onYes
-                       elif id_ == wx.ID_NO:
-                               self.btnNo = btn
-                               mthd = self._onNo
                        elif id_ == wx.ID_HELP:
                                self.btnHelp = btn
+                               newbtn = None
                                mthd = self._onHelp
-                       btn.Bind(wx.EVT_BUTTON, mthd)
+                       if newbtn is None:
+                               # Only the Help button cannot be wrapped, as it 
is platform-specific in appearance.
+                               btn.Bind(wx.EVT_BUTTON, mthd)
+                       else:
+                               newbtn.Caption = btn.GetLabel()
+                               pos = dabo.ui.getPositionInSizer(btn)
+                               sz = btn.GetContainingSizer()
+                               sz.Replace(btn, newbtn)
+                               btn.Destroy()
+                               newbtn.bindEvent(dEvents.Hit, mthd)
+               if ok:
+                       self.OKButton.DefaultButton = True
+               elif yes:
+                       self.YesButton.DefaultButton = True
                        
                # Wx rearranges the order of the buttons per platform 
conventions, but
                # doesn't rearrange the tab order for us. So, we do it manually:
@@ -281,19 +298,8 @@
                                buttons.append(win)
                for pos, btn in enumerate(buttons[1:]):
                        btn.MoveAfterInTabOrder(buttons[pos-1])
-               if self.CancelOnEscape:
-                       # The default Escape behavior destroys the dialog, so 
we need to replace
-                       # this with out own.
-                       self.SetEscapeId(wx.ID_NONE)
-                       if cancel:
-                               self.bindKey("esc", self._onCancel)
-                       elif no:
-                               self.bindKey("esc", self._onNo)
-                       elif ok:
-                               self.bindKey("esc", self._onOK)
-                       elif yes:
-                               self.bindKey("esc", self._onYes)
-                               
+               self.SetEscapeId(wx.ID_NONE)
+               self.bindKey("esc", self._onEscapePressed)
 
                # Let the user add their controls
                super(dStandardButtonDialog, self)._addControls()
@@ -309,6 +315,19 @@
                        sz.append(bs, "x")
                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)
+
+
        ################################################
        #    Handlers for the standard buttons. 
        ################################################




_______________________________________________
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