Changeset 4170

Show
Ignore:
Timestamp:
06/20/08 09:42:56 (4 months ago)
Author:
ed
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/ui/uiwx/dDialog.py

    r4166 r4170  
    208208        self._no = self._extractKey((properties, kwargs), "No") 
    209209        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.") 
    210213        self._cancelOnEscape = True 
    211214        super(dStandardButtonDialog, self).__init__(parent=parent, properties=properties, *args, **kwargs) 
     
    256259        for btn in btns: 
    257260            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) 
    260269                mthd = self._onOK 
    261270            elif id_ == wx.ID_CANCEL: 
    262                 self.btnCancel = btn 
     271                self.btnCancel = newbtn = dabo.ui.dButton(btn.Parent) 
    263272                mthd = self._onCancel 
    264             elif id_ == wx.ID_YES: 
    265                 self.btnYes = btn 
    266                 mthd = self._onYes 
    267             elif id_ == wx.ID_NO: 
    268                 self.btnNo = btn 
    269                 mthd = self._onNo 
    270273            elif id_ == wx.ID_HELP: 
    271274                self.btnHelp = btn 
     275                newbtn = None 
    272276                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 
    274291             
    275292        # Wx rearranges the order of the buttons per platform conventions, but 
     
    282299        for pos, btn in enumerate(buttons[1:]): 
    283300            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) 
    297303 
    298304        # Let the user add their controls 
     
    309315            sz.append(bs, "x") 
    310316        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 
    311330 
    312331    ################################################