Changeset 4230

Show
Ignore:
Timestamp:
07/04/08 10:10:15 (5 months ago)
Author:
ed
Message:

Added the FloatingPanel? property. This references a borderless dialog that can be used similarly to a context menu, but which can contain any controls you want. Additionally, it will guarantee that it is displayed completely within the available screen real estate.

It has two properties itself:

Above: by default the dialog is positioned below its owning control. This changes the behavior so that it is positioned above the control.
Owner: this is the control used to position the dialog.

Typical usage (written in a custom control):

fp = self.Form.FloatingPanel?
fp.clear()
# Add controls
ctrl = dabo.ui.dTextBox(fp, ...)
ctrl2 = ...
# Set the Owner to the control
fp.Owner = self
fp.show()

The controls in the FloatingPanel? should hide or release it, depending on whether you expect to re-use it. See the update to dDateTextBox for an implementation of it.

Files:

Legend:

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

    r4186 r4230  
    1111from dabo.dLocalize import _ 
    1212from dabo.ui import makeDynamicProperty 
     13from dDialog import dDialog 
     14 
     15 
     16class _FloatDialog(dDialog): 
     17    def __init__(self, owner, *args, **kwargs): 
     18        self._above = None 
     19        self._owner = None 
     20        kwargs["Borderless"] = True 
     21        kwargs["FloatOnParent"] = True 
     22        super(_FloatDialog, self).__init__(*args, **kwargs) 
     23 
     24 
     25    def clear(self): 
     26        """Releases any controls remaining from a previous usage.""" 
     27        self.Sizer.clear(True) 
     28 
     29 
     30    def show(self): 
     31        # position by owner 
     32        if self.Owner is None: 
     33            self.Centered = True 
     34        else: 
     35            self.Centered = None 
     36            left, top = self.Owner.absoluteCoordinates() 
     37            self.Left = left 
     38            if self.Above: 
     39                self.Bottom = top 
     40            else: 
     41                self.Top = top + self.Owner.Height 
     42        # Make sure that we're within the display limits 
     43        maxW, maxH = dabo.ui.getDisplaySize() 
     44        self.Left = max(5, self.Left) 
     45        self.Top = max(5, self.Top) 
     46        self.Right = min(self.Right, maxW-5) 
     47        self.Bottom = min(self.Bottom, maxH-5) 
     48        super(_FloatDialog, self).show() 
     49         
     50 
     51    def _getAbove(self): 
     52        return self._above 
     53 
     54    def _setAbove(self, val): 
     55        if self._constructed(): 
     56            self._above = val 
     57        else: 
     58            self._properties["Above"] = val 
     59 
     60 
     61    def _getOwner(self): 
     62        return self._owner 
     63 
     64    def _setOwner(self, val): 
     65        if self._constructed(): 
     66            self._owner = val 
     67        else: 
     68            self._properties["Owner"] = val 
     69 
     70 
     71    Above = property(_getAbove, _setAbove, None, 
     72            _("Is this dialog positioned above its owner? Default=False  (bool)")) 
     73 
     74    Owner = property(_getOwner, _setOwner, None, 
     75            _("Control which is currently managing this window.  (varies)")) 
     76 
    1377 
    1478 
     
    2286        self.bizobjs = {} 
    2387        self._primaryBizobj = None 
     88        self._floatingPanel = None 
    2489         
    2590        # If this is True, a panel will be automatically added to the 
     
    81146            self.activeControlValid() 
    82147            ret = self.confirmChanges() 
     148        if self._floatingPanel: 
     149            self._floatingPanel.release() 
    83150        if ret: 
    84151            ret = super(BaseForm, self)._beforeClose(evt) 
     
    796863         
    797864 
     865    def _getFloatingPanel(self): 
     866        if not self._floatingPanel: 
     867            self._floatingPanel = _FloatDialog(self) 
     868        return self._floatingPanel 
     869 
     870 
    798871    def _getPrimaryBizobj(self): 
    799872        """The attribute '_primaryBizobj' should be a bizobj, but due 
     
    855928            box asking whether to save changes, discard changes, or cancel the  
    856929            operation that led to the dialog being presented.""") ) 
     930 
     931    FloatingPanel = property(_getFloatingPanel, None, None, 
     932            _("""Small modal dialog that is designed to be used for temporary displays,  
     933            similar to context menus, but which can contain any controls.   
     934            (read-only) (dDialog)""")) 
    857935 
    858936    PrimaryBizobj = property(_getPrimaryBizobj, _setPrimaryBizobj, None,