Changeset 4170
- Timestamp:
- 06/20/08 09:42:56 (4 months ago)
- Files:
-
- trunk/dabo/ui/uiwx/dDialog.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/ui/uiwx/dDialog.py
r4166 r4170 208 208 self._no = self._extractKey((properties, kwargs), "No") 209 209 self._help = self._extractKey((properties, kwargs), "Help") 210 # Check for both OK and Yes. This simply does not work, at least with wxPython. 211 if self._ok and self._yes: 212 raise ValueError, _("Dialogs cannot have both 'OK' and 'Yes' buttons.") 210 213 self._cancelOnEscape = True 211 214 super(dStandardButtonDialog, self).__init__(parent=parent, properties=properties, *args, **kwargs) … … 256 259 for btn in btns: 257 260 id_ = btn.GetId() 258 if id_ == wx.ID_OK: 259 self.btnOK = btn 261 if id_ == wx.ID_YES: 262 self.btnYes = newbtn = dabo.ui.dButton(btn.Parent) 263 mthd = self._onYes 264 elif id_ == wx.ID_NO: 265 self.btnNo = newbtn = dabo.ui.dButton(btn.Parent) 266 mthd = self._onNo 267 elif id_ == wx.ID_OK: 268 self.btnOK = newbtn = dabo.ui.dButton(btn.Parent) 260 269 mthd = self._onOK 261 270 elif id_ == wx.ID_CANCEL: 262 self.btnCancel = btn271 self.btnCancel = newbtn = dabo.ui.dButton(btn.Parent) 263 272 mthd = self._onCancel 264 elif id_ == wx.ID_YES:265 self.btnYes = btn266 mthd = self._onYes267 elif id_ == wx.ID_NO:268 self.btnNo = btn269 mthd = self._onNo270 273 elif id_ == wx.ID_HELP: 271 274 self.btnHelp = btn 275 newbtn = None 272 276 mthd = self._onHelp 273 btn.Bind(wx.EVT_BUTTON, mthd) 277 if newbtn is None: 278 # Only the Help button cannot be wrapped, as it is platform-specific in appearance. 279 btn.Bind(wx.EVT_BUTTON, mthd) 280 else: 281 newbtn.Caption = btn.GetLabel() 282 pos = dabo.ui.getPositionInSizer(btn) 283 sz = btn.GetContainingSizer() 284 sz.Replace(btn, newbtn) 285 btn.Destroy() 286 newbtn.bindEvent(dEvents.Hit, mthd) 287 if ok: 288 self.OKButton.DefaultButton = True 289 elif yes: 290 self.YesButton.DefaultButton = True 274 291 275 292 # Wx rearranges the order of the buttons per platform conventions, but … … 282 299 for pos, btn in enumerate(buttons[1:]): 283 300 btn.MoveAfterInTabOrder(buttons[pos-1]) 284 if self.CancelOnEscape: 285 # The default Escape behavior destroys the dialog, so we need to replace 286 # this with out own. 287 self.SetEscapeId(wx.ID_NONE) 288 if cancel: 289 self.bindKey("esc", self._onCancel) 290 elif no: 291 self.bindKey("esc", self._onNo) 292 elif ok: 293 self.bindKey("esc", self._onOK) 294 elif yes: 295 self.bindKey("esc", self._onYes) 296 301 self.SetEscapeId(wx.ID_NONE) 302 self.bindKey("esc", self._onEscapePressed) 297 303 298 304 # Let the user add their controls … … 309 315 sz.append(bs, "x") 310 316 self.layout() 317 318 319 def _onEscapePressed(self, evt): 320 if self.CancelOnEscape: 321 if self.CancelButton: 322 self._onCancel(evt) 323 elif self.NoButton: 324 self._onNo(evt) 325 elif self.OKButton: 326 self._onOK(evt) 327 elif self.YesButton: 328 self._onYes(evt) 329 311 330 312 331 ################################################
