Changeset 4166
- Timestamp:
- 06/19/08 18:10:44 (4 months ago)
- Files:
-
- trunk/dabo/ui/uiwx/dDialog.py (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dabo/ui/uiwx/dDialog.py
r4164 r4166 1 1 # -*- coding: utf-8 -*- 2 import warnings 2 3 import wx 3 4 import dabo … … 96 97 def _onEscape(self, evt): 97 98 evt.stop() 98 if self.ReleaseOnEscape: 99 self.release() 100 self.Close() 99 self.hide() 101 100 102 101 … … 128 127 129 128 130 def _setEscapeBehavior(self):131 """Allow subclasses to respond to changes in the ReleaseOnEscape property."""132 pass133 134 135 129 def _getAutoSize(self): 136 130 return self._fit … … 164 158 165 159 166 def _getReleaseOnEscape(self):167 try:168 val = self._releaseOnEscape169 except AttributeError:170 val = True171 return val172 173 def _setReleaseOnEscape(self, val):174 self._releaseOnEscape = bool(val)175 self._setEscapeBehavior()176 177 178 160 def _getShowStat(self): 179 161 # Dialogs cannot have status bars. … … 194 176 "Determines if the dialog is shown modal (default) or modeless. (bool)") 195 177 196 ReleaseOnEscape = property(_getReleaseOnEscape, _setReleaseOnEscape, None,197 "Determines if the <Esc> key releases the dialog. Default=True. (bool)")198 199 178 200 179 DynamicAutoSize = makeDynamicProperty(AutoSize) … … 218 197 you must specify them all; in other words, OK is only assumed if nothing is specified. 219 198 Then add your custom controls in the addControls() hook method, and respond to 220 the pressing of the standard buttons in the on*() handlers, where * is the name of the221 associated property (e.g., onOK(), onNo(), etc.). You can query the Accepted property199 the pressing of the standard buttons in the run*() handlers, where * is the name of the 200 associated property (e.g., runOK(), runOo(), etc.). You can query the Accepted property 222 201 to find out if the user pressed "OK" or "Yes"; if neither of these was pressed, 223 202 Accepted will be False. … … 229 208 self._no = self._extractKey((properties, kwargs), "No") 230 209 self._help = self._extractKey((properties, kwargs), "Help") 210 self._cancelOnEscape = True 231 211 super(dStandardButtonDialog, self).__init__(parent=parent, properties=properties, *args, **kwargs) 232 212 self._baseClass = dStandardButtonDialog … … 267 247 # Initialize the button references 268 248 self.btnOK = self.btnCancel = self.btnYes = self.btnNo = self.btnHelp = None 269 self.stdButtonSizer = sbs = self.CreateButtonSizer(flags) 249 250 # We need a Dabo sizer to wrap the wx sizer. 251 self.stdButtonSizer = dabo.ui.dSizer() 252 sbs = self.CreateButtonSizer(flags) 253 self.stdButtonSizer.append1x(sbs) 254 270 255 btns = [b.GetWindow() for b in sbs.GetChildren() if b.IsWindow()] 271 256 for btn in btns: … … 297 282 for pos, btn in enumerate(buttons[1:]): 298 283 btn.MoveAfterInTabOrder(buttons[pos-1]) 299 if cancel or no:284 if self.CancelOnEscape: 300 285 # The default Escape behavior destroys the dialog, so we need to replace 301 286 # this with out own. … … 305 290 elif no: 306 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 307 297 308 298 # Let the user add their controls … … 310 300 311 301 # Just in case user changed Self.Sizer, update our reference: 312 bs = dabo.ui.dSizer("v") 313 bs.append((0, sz.DefaultBorder/2)) 314 bs.append(sbs, "x") 315 bs.append((0, sz.DefaultBorder)) 316 sz.append(bs, "x") 302 sz = self.Sizer 303 if self.ButtonSizerPosition is None: 304 # User code didn't add it, so we must. 305 bs = dabo.ui.dSizer("v") 306 bs.append((0, sz.DefaultBorder/2)) 307 bs.append(self.ButtonSizer, "x") 308 bs.append((0, sz.DefaultBorder)) 309 sz.append(bs, "x") 310 self.layout() 317 311 318 312 ################################################ 319 # Handlers for the standard buttons 313 # Handlers for the standard buttons. 314 ################################################ 315 # Note that onOK() and 316 # onCancel() are the names of the old event handlers, and 317 # code has been written to use these. So as not to break this 318 # older code, we issue a deprecation warning and call the 319 # old handler. 320 320 def _onOK(self, evt): 321 321 self.Accepted = True 322 self.onOK() 322 try: 323 self.onOK() 324 except TypeError: 325 warnings.warn(_("The onOK() handler is deprecated. Use the runOK() method instead"), 326 Warning) 327 self.onOK(None) 328 except AttributeError: 329 # New code should not have onOK 330 pass 331 self.runOK() 323 332 self.EndModal(kons.DLG_OK) 324 333 def _onCancel(self, evt): 325 self.onCancel() 334 try: 335 self.onCancel() 336 except TypeError: 337 warnings.warn(_("The onCancel() handler is deprecated. Use the runCancel() method instead"), 338 Warning) 339 self.onCancel(None) 340 except AttributeError: 341 # New code should not have onCancel 342 pass 343 self.runCancel() 326 344 self.EndModal(kons.DLG_CANCEL) 327 345 def _onYes(self, evt): 328 346 self.Accepted = True 329 self. onYes()347 self.runYes() 330 348 self.EndModal(kons.DLG_YES) 331 349 def _onNo(self, evt): 332 self. onNo()350 self.runNo() 333 351 self.EndModal(kons.DLG_NO) 334 352 def _onHelp(self, evt): 335 self.onHelp() 353 self.runHelp() 354 336 355 # The following are stub methods that can be overridden when needed. 337 def onOK(self): pass338 def onCancel(self): pass339 def onYes(self): pass340 def onNo(self): pass341 def onHelp(self): pass356 def runOK(self): pass 357 def runCancel(self): pass 358 def runYes(self): pass 359 def runNo(self): pass 360 def runHelp(self): pass 342 361 ################################################ 343 362 … … 389 408 390 409 410 def _getButtonSizerPosition(self): 411 return self.ButtonSizer.getPositionInSizer() 412 413 391 414 def _getCancelButton(self): 392 415 return self.btnCancel 393 416 394 417 418 def _getCancelOnEscape(self): 419 return self._cancelOnEscape 420 421 def _setCancelOnEscape(self, val): 422 if self._constructed(): 423 self._cancelOnEscape = val 424 else: 425 self._properties["CancelOnEscape"] = val 426 427 395 428 def _getHelpButton(self): 396 429 return self.btnHelp … … 415 448 _("Returns a reference to the sizer controlling the Ok/Cancel buttons. (dSizer)")) 416 449 450 ButtonSizerPosition = property(_getButtonSizerPosition, None, None, 451 _("""Returns the position of the Ok/Cancel buttons in the sizer. (int)""")) 452 417 453 CancelButton = property(_getCancelButton, None, None, 418 454 _("Reference to the Cancel button on the form, if present (dButton or None).")) 419 455 456 CancelOnEscape = property(_getCancelOnEscape, _setCancelOnEscape, None, 457 _("""When True (default), pressing the Escape key will perform the same action 458 as clicking the Cancel button. If no Cancel button is present but there is a No button, 459 the No behavior will be executed. If neither button is present, the default button's 460 action will be executed (bool)""")) 461 420 462 HelpButton = property(_getHelpButton, None, None, 421 463 _("Reference to the Help button on the form, if present (dButton or None).")) … … 438 480 super(dOkCancelDialog, self).__init__(parent, properties, *args, **kwargs) 439 481 self._baseClass = dOkCancelDialog 440 441 482 442 483 class dYesNoDialog(dStandardButtonDialog): … … 448 489 449 490 450 451 491 if __name__ == "__main__": 452 492 import test
