Changeset 479

Show
Ignore:
Timestamp:
03/19/03 22:43:52 (6 years ago)
Author:
sholloway
Message:

Finished up the docking tools
Cleaned up a rarely seen bug in the layouts when resizing
Added the docking test harness as the first RBSkinning demo :)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBSkinning/RBSkinning/wxPythonSkin/expander.py

    r478 r479  
    6464            # Layouts cancel the window parent 
    6565            parentLayout = self.winParent 
     66            self.winParent = None 
    6667 
    6768            # Figure out what type of sizer we should be creating 
  • trunk/RBSkinning/RBSkinning/wxPythonSkin/layout.py

    r478 r479  
    2626import warnings 
    2727from wxSkinLayoutObject import wx, wxSkinLayoutObject, wxSkinObjectNoData 
     28from RBSkinning.wxTools import SetLayoutContainerSizeHints 
    2829 
    2930#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3031#~ Definitions  
    31 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    32  
    33 def SetLayoutContainerSizeHints(layout, container, force=False): 
    34     """Tool to update container's size hints to layout's minsize,  
    35     accounting for client area""" 
    36     minsize = layout.GetMinSize().asTuple() 
    37     size = container.GetSizeTuple() 
    38     clientsize = container.GetClientSizeTuple() 
    39     sizew = minsize[0] + (size[0] - clientsize[0]) 
    40     sizeh = minsize[1] + (size[1] - clientsize[1]) 
    41     if force or sizew > 0 or sizeh > 0: 
    42         container.SetSizeHints(sizew, sizeh) 
    43         return True 
    44     else: return False 
    45  
    46 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    47 #~ Class 
    4832#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4933 
     
    163147            sizerargs = tuple([ChildNode.wxEvalCond(*evalargs) for evalargs in (('sizerOption', 0), ('sizerFlag', 0), ('sizerBorder', 0))]) 
    164148            if sizerargs != (0,0,0): 
    165                 print sizerargs 
    166149                warnings.warn('"sizerOption", "sizerFlag", and "sizerBorder" attributes should be replaced with "sizercfg"', DeprecationWarning) 
    167150        args = args + tuple(sizerargs) 
  • trunk/RBSkinning/RBSkinning/wxPythonSkin/layout_flexgrid.py

    r477 r479  
    3737    default_settings = layout.default_settings.copy() 
    3838    default_settings.update({ 
    39         'ctxvar': 'layout', 
    40         'orientation': 'opposite', 
    41         'sizerAuto': '1', 
    42         'sizerFit': '0', 
    4339        'rows': '0', 
    4440        'cols': '2', 
  • trunk/RBSkinning/RBSkinning/wxTools/__init__.py

    r253 r479  
    2020##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2121 
     22#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     23#~ Definitions  
     24#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2225 
     26def SetLayoutContainerSizeHints(layout, parent): 
     27    minsize = layout.GetMinSize().asTuple() 
     28    clientsize = parent.GetClientSizeTuple() 
     29    if clientsize[0]<minsize[0] or clientsize[1]<minsize[1]: 
     30        clientsize = max(clientsize[0], minsize[0]), max(clientsize[1], minsize[1]) 
     31        parent.SetClientSize(clientsize) 
     32    size = parent.GetSizeTuple() 
     33    sizew = minsize[0] + (size[0] - clientsize[0]) 
     34    sizeh = minsize[1] + (size[1] - clientsize[1]) 
     35    parent.SetSizeHints(sizew, sizeh) 
     36 
  • trunk/RBSkinning/RBSkinning/wxTools/wxDockingTools.py

    r478 r479  
    2020##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2121 
     22from __init__ import SetLayoutContainerSizeHints 
     23 
    2224#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2325#~ Definitions  
     26#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     27 
     28class _matchany(object): 
     29    def __eq__(self, other): return True 
     30    def __ne__(self, other): return False 
     31_matchany = _matchany() 
     32 
     33#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     34 
     35class wxDockContainer(object): 
     36    def __init__(self, dockhost=None): 
     37        self.docked = False 
     38        self.items = [] 
     39        self.dockhost = dockhost 
     40        self.Dock() 
     41 
     42    def Add(self, item, *args, **kw): 
     43        self.items.append((item, args, kw)) 
     44 
     45    def Prepend(self, item, *args, **kw): 
     46        self.items.insert(0, (item, args, kw)) 
     47 
     48    def Remove(self, item, *args, **kw): 
     49        try:  
     50            self.items.remove((item, _matchany, _matchany)) 
     51            return True 
     52        except ValueError: return False 
     53 
     54    def DockTo(self, dockhost): 
     55        if dockhost is not self.dockhost: 
     56            self.Undock() 
     57            self.dockhost = dockhost 
     58            return self.Dock() 
     59        else: 
     60            return self.Dock() 
     61 
     62    def IsDocked(self, to=None): 
     63        if self.docked: 
     64            if to in [None, self.dockhost]: 
     65                return True 
     66        return False 
     67 
     68    def DockToggle(self): 
     69        if self.IsDocked(): 
     70            return self.Undock() 
     71        else: return self.Dock() 
     72 
     73    def Dock(self, adjust=True): 
     74        if not self.docked and self.dockhost: 
     75            for item, args, kw in self.items: 
     76                if adjust: self._AdjustItem(item, True) 
     77                self.dockhost.DockItem(item, *args, **kw) 
     78            self.docked = True 
     79        return self.docked 
     80 
     81    def Undock(self, adjust=True): 
     82        if self.docked and self.dockhost: 
     83            for item, args, kw in self.items: 
     84                if adjust: self._AdjustItem(item, False) 
     85                self.dockhost.UndockItem(item) 
     86        elif adjust:  
     87            for item, args, kw in self.items: 
     88                self._AdjustItem(item, False) 
     89        self.docked = False 
     90        return self.docked 
     91 
     92    def _AdjustItem(self, item, show): 
     93        # Restore to a nominal size 
     94        item.SetSize(item.GetBestSize()) 
     95        item.Show(show) 
     96 
    2497#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2598 
     
    30103 
    31104    prepend = False 
     105    dockcount = 0 
     106    hideempty = False 
    32107 
    33108    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    35110    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    36111 
    37     def __init__(self, parent, layout, rootlayout=None, prepend=False): 
     112    def __init__(self, parent, layout, rootlayout=None, prepend=False, hideempty=False): 
    38113        self.parent = parent 
    39114        self.layout = layout 
    40115        self.rootlayout = rootlayout or layout 
    41116        self.prepend = prepend 
     117        self.hideempty = hideempty 
    42118 
    43119    def DockItem(self, dockitem, *args, **kw): 
    44         if isinstance(dockitem, wxDockItem): 
     120        if isinstance(dockitem, wxDockContainer): 
    45121            dockitem.DockTo(self) 
    46122        else: 
     123            self.dockcount += 1 
    47124            try: DIReparent = dockitem.Reparent 
    48125            except AttributeError: pass 
     
    55132 
    56133    def UndockItem(self, dockitem, *args, **kw): 
    57         if isinstance(dockitem, wxDockItem): 
     134        if isinstance(dockitem, wxDockContainer): 
    58135            if dockitem.IsDocked(self): 
    59136                dockitem.Undock() 
    60137        else: 
     138            self.dockcount -= 1 
    61139            ### The following code is not required, but included so  
    62140            ### we don't wonder about the asymetry ;) 
     
    68146            # We will re-enable in self.Layout 
    69147            self.parent.SetSizeHints(0, 0) 
    70  
    71             if self.layout.Remove(dockitem): 
    72                 self.Layout() 
     148            self.layout.Remove(dockitem) 
     149            self.Layout() 
    73150 
    74151    def Layout(self): 
    75152        self.rootlayout.Layout() 
    76153        self._SetLayoutContainerSizeHints() 
     154 
     155        if self.hideempty: 
     156            if self.dockcount <= 0: 
     157                self.dockcount = 0 
     158                self.parent.Show(False) 
     159            else: 
     160                self.parent.Show(True) 
    77161 
    78162    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    81165 
    82166    def _SetLayoutContainerSizeHints(self): 
    83         minsize = self.layout.GetMinSize().asTuple() 
    84         size = self.parent.GetSizeTuple() 
    85         clientsize = self.parent.GetClientSizeTuple() 
    86         sizew = minsize[0] + (size[0] - clientsize[0]) 
    87         sizeh = minsize[1] + (size[1] - clientsize[1]) 
    88         self.parent.SetSizeHints(sizew, sizeh) 
     167        return SetLayoutContainerSizeHints(self.rootlayout, self.parent) 
    89168 
    90 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    91  
    92 class wxDockItem(object): 
    93     def __init__(self, item, dockhost=None): 
    94         self.docked = False 
    95         self.sizercfg = () 
    96         self.item = item 
    97         self.dockhost = dockhost 
    98         self.Dock() 
    99  
    100     def DockTo(self, dockhost): 
    101         if dockhost is not self.dockhost: 
    102             self.Undock() 
    103             self.dockhost = dockhost 
    104             self.Dock() 
    105         else: 
    106             self.Dock() 
    107  
    108     def IsDocked(self, to=None): 
    109         if self.docked: 
    110             if to in [None, self.dockhost]: 
    111                 return True 
    112         return False 
    113  
    114     def DockToggle(self): 
    115         if self.IsDocked(): 
    116             self.Undock() 
    117         else: self.Dock() 
    118  
    119     def Dock(self, doshow=True): 
    120         if not self.docked and self.dockhost: 
    121             self.docked = True 
    122             if doshow: self.item.Show(True) 
    123             self.dockhost.DockItem(self.item, *self.sizercfg) 
    124  
    125     def Undock(self, dohide=True): 
    126         if self.docked and self.dockhost: 
    127             self.docked = False 
    128             if dohide: self.item.Show(False) 
    129             self.dockhost.UndockItem(self.item) 
    130