Ticket #1035: modal_dForm.patch

File modal_dForm.patch, 4.6 kB (added by paul, 2 years ago)
  • dabo/lib/datanav2/Form.py

    old new  
    4444        # Create the various elements: 
    4545        self.setupPageFrame() 
    4646 
    47         if not self.Testing
     47        if not self.Testing and not self.Modal
    4848            self.setupToolBar() 
    4949            self.setupMenu() 
    5050 
  • dabo/ui/uiwx/dPemMixin.py

    old new  
    11441144     
    11451145    def show(self): 
    11461146        """Make the object visible.""" 
    1147         self.Show(True) 
     1147        self.Visible = True 
    11481148         
    11491149         
    11501150    def hide(self): 
     
    22462246     
    22472247    def _setVisible(self, val): 
    22482248        if self._constructed(): 
    2249             val = bool(val) 
    2250             self.Show(val) 
    2251             if not val: 
    2252                 if getattr(self, "_shownModal", False): 
    2253                     ## This is a form that was shown modally. Need to undo that 
    2254                     ## when the form goes hidden. 
    2255                     self.MakeModal(False) 
    2256                     self._shownModal = False 
     2249            self.Show(bool(val)) 
    22572250        else: 
    22582251            self._properties["Visible"] = val 
    22592252 
  • dabo/ui/uiwx/dFormMixin.py

    old new  
    283283        """ 
    284284        raise dException.FeatureNotSupportedException, \ 
    285285                _("The underlying UI toolkit does not support modal forms. Use a dDialog instead.") 
    286         #self.MakeModal(True) 
    287         #self._isModal = self.Visible = True 
    288286         
    289287         
    290288    def release(self): 
     
    945943 
    946944    MenuBarFile = property(_getMenuBarFile, _setMenuBarFile, None, 
    947945            _("Path to the .mnxml file that defines this form's menu bar  (str)")) 
    948      
     946 
    949947    SaveRestorePosition = property(_getSaveRestorePosition,  
    950948            _setSaveRestorePosition, None, 
    951949            _("""Specifies whether the form's position and size as set by the user 
  • dabo/ui/uiwx/dForm.py

    old new  
    775775    def __init__(self, parent=None, properties=None, attProperties=None, *args, **kwargs): 
    776776        self._baseClass = dForm 
    777777 
    778         if dabo.settings.MDI and isinstance(parent, wx.MDIParentFrame): 
    779             # Hack this into an MDI Child: 
    780             dForm.__bases__ = (BaseForm, wx.MDIChildFrame
    781             preClass = wx.PreMDIChildFrame 
    782             self._mdi = True 
     778        if kwargs.pop("Modal", False): 
     779            # Hack this into a wx.Dialog, for true modality 
     780            dForm.__bases__ = (BaseForm, wx.Dialog
     781            preClass = wx.PreDialog 
     782            self._modal = True 
    783783        else: 
    784             # This is a normal SDI form: 
    785             dForm.__bases__ = (BaseForm, wx.Frame) 
    786             preClass = wx.PreFrame 
    787             self._mdi = False 
    788         ## (Note that it is necessary to run the above block each time, because 
     784            # Normal dForm 
     785            if dabo.settings.MDI and isinstance(parent, wx.MDIParentFrame): 
     786                # Hack this into an MDI Child: 
     787                dForm.__bases__ = (BaseForm, wx.MDIChildFrame) 
     788                preClass = wx.PreMDIChildFrame 
     789                self._mdi = True 
     790            else: 
     791                # This is a normal SDI form: 
     792                dForm.__bases__ = (BaseForm, wx.Frame) 
     793                preClass = wx.PreFrame 
     794                self._mdi = False 
     795 
     796        ## (Note that it is necessary to run the above blocks each time, because 
    789797        ##  we are modifying the dForm class definition globally.) 
    790798        BaseForm.__init__(self, preClass, parent, properties, attProperties, *args, **kwargs) 
    791799 
     
    797805        super(dForm, self).Layout() 
    798806        wx.CallAfter(self.update) 
    799807 
     808    def _getModal(self): 
     809        return getattr(self, "_modal", False) 
    800810 
     811    def _getVisible(self): 
     812        return self.IsShown() 
     813     
     814    def _setVisible(self, val): 
     815        if self._constructed(): 
     816            val = bool(val) 
     817            if val and self.Modal: 
     818                self.ShowModal() 
     819            else: 
     820                self.Show(val) 
     821        else: 
     822            self._properties["Visible"] = val 
     823 
     824    Modal = property(_getModal, None, None, 
     825            _("""Specifies whether this dForm is modal or not  (bool) 
     826 
     827            A modal dForm runs its own event loop, blocking program flow until the 
     828            form is hidden or closed, exactly like a dDialog does it. This property 
     829            may only be sent to the constructor, and once instantiated you may not 
     830            change the modality of a form. For example, 
     831                    frm = dabo.ui.dForm(Modal=True) 
     832            will create a modal form. 
     833 
     834            Note that a modal dForm is actually a dDialog, and as such does not 
     835            have the ability to contain MenuBars, StatusBars, or ToolBars.""")) 
     836 
     837    Visible = property(_getVisible, _setVisible, None, 
     838            _("Specifies whether the form is shown or hidden.  (bool)") ) 
     839 
     840     
     841 
    801842class dToolForm(BaseForm, wx.MiniFrame): 
    802843    def __init__(self, parent=None, properties=None, attProperties=None, *args, **kwargs): 
    803844        self._baseClass = dToolForm