Changeset 504

Show
Ignore:
Timestamp:
04/08/03 14:46:59 (6 years ago)
Author:
sholloway
Message:

Changed docking components to allow for single replacement

Files:

Legend:

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

    r498 r504  
    5757            rootlayout = self.wxEvalCond('rootlayout', parent.GetSizer()) 
    5858            self.object = wxDockingTools.wxDockHost(parent, layout, rootparent=rootparent, rootlayout=rootlayout, prepend=prepend, hideempty=hideempty) 
     59 
     60        single = self.wxEvalCond('single', 0) 
     61        if single: 
     62            wxDockingTools.wxSingleDockHostAspect.MixinAspect(self.object) 
     63 
    5964        self.wxStandardOptions() 
    6065  
  • trunk/RBSkinning/RBSkinning/wxTools/wxDockingTools.py

    r501 r504  
    2424#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2525 
     26import weakref 
     27from wxPython import wx 
    2628from __init__ import SetLayoutContainerSizeHints 
    27 from wxPython import wx 
    2829 
    2930#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    7677        else: return self.Dock() 
    7778 
    78     def OnDocked(self, dockhost): 
    79         pass 
     79    def OnDocked(self, dockitem, dockhost): 
     80        pass # print "OnDocked", dockitem.__class__.__name__, dockhost.__class__.__name__ 
    8081 
    8182    def Dock(self, adjust=True): 
     
    8586                self.dockhost.DockItem(self, item, *args, **kw) 
    8687            self.docked = True 
    87             self.OnDocked(self.dockhost) 
     88            self.OnDocked(self, self.dockhost) 
    8889        return self.docked 
    8990 
    90     def OnUndocked(self, dockhost): 
    91         pass 
     91    def OnUndocked(self, dockitem, dockhost): 
     92        pass # print "OnUndocked", dockitem.__class__.__name__, dockhost.__class__.__name__ 
    9293 
    9394    def Undock(self, adjust=True): 
     
    9697                if adjust: self._AdjustItem(item, False) 
    9798                self.dockhost.UndockItem(self, item) 
    98             self.OnUndocked(self.dockhost) 
     99            self.OnUndocked(self, self.dockhost) 
    99100        elif adjust:  
    100101            for item, args, kw in self.items: 
     
    111112 
    112113class wxDockHostBase(object): 
    113     def OnDockItem(self, container, dockitem=None, *args, **kw): 
    114         pass # print "OnDockItem", self.__class__.__name__, container.__class__.__name__ 
     114    def OnDockItem(self, dockhost, container, dockitem, *args, **kw): 
     115        pass # print "OnDockItem", dockhost.__class__.__name__, container.__class__.__name__ 
    115116 
    116117    def DockItem(self, container, dockitem=None, *args, **kw): 
    117118        raise NotImplementedError 
    118119 
    119     def OnUndockItem(self, container, dockitem=None, *args, **kw): 
    120         pass # print "OnUndockItem", self.__class__.__name__, container.__class__.__name__ 
     120    def OnUndockItem(self, dockhost, container, dockitem, *args, **kw): 
     121        pass # print "OnUndockItem", dockhost.__class__.__name__, container.__class__.__name__ 
    121122 
    122123    def UndockItem(self, container, dockitem=None, *args, **kw): 
    123124        raise NotImplementedError 
     125 
     126#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     127 
     128class wxSingleDockHostMixin(object): 
     129    """Adapts a multiple DockHost to only accept a single dock container""" 
     130 
     131    _current = None 
     132 
     133    def DockItem(self, container, dockitem=None, *args, **kw): 
     134        if container is None: 
     135            container.DockTo(self) 
     136        else: 
     137            if self._current is not None: 
     138                self._current.Undock() 
     139            self.__super.DockItem(container, dockitem, *args, **kw) 
     140            self._current = weakref.proxy(container) 
     141 
     142    def UndockItem(self, container, dockitem=None, *args, **kw): 
     143        if container is None: 
     144            if container.IsDocked(self): 
     145                container.Undock() 
     146        else: 
     147            self.__super.UndockItem(container, dockitem, *args, **kw) 
     148            self._current = None 
     149 
     150wxSingleDockHostMixin._wxSingleDockHostMixin__super = super(wxSingleDockHostMixin) 
     151 
     152#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     153 
     154class wxSingleDockHostAspect(wxSingleDockHostMixin): 
     155    def MixinAspect(mixinclass, instance, add=True): 
     156        try: 
     157            instance.__restoreclass 
     158            if not add: 
     159                # Make it back to a normal dock host 
     160                instance.__class__ = instance.__restoreclass 
     161            #else: pass # It already is a single dock host 
     162        except AttributeError: 
     163            if add: 
     164                # Make it a single dock host 
     165                oldclass = instance.__class__ 
     166                instance.__class__ = type('%s+%s'%(mixinclass, instance.__class__), (mixinclass, instance.__class__), {'__restoreclass': oldclass}) 
     167            #else: pass # It is not a dock host, and it should stay that way 
     168    MixinAspect = classmethod(MixinAspect) 
    124169 
    125170#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    150195            container.DockTo(self) 
    151196        else: 
    152             self.dockcount += 1 
    153             try: DIReparent = dockitem.Reparent 
    154             except AttributeError: pass 
    155             else: DIReparent(self.parent) 
    156  
    157             if self.prepend: 
    158                 self.layout.Prepend(dockitem, *args, **kw) 
    159             else: self.layout.Add(dockitem, *args, **kw) 
    160             self.OnDockItem(container, dockitem) 
    161             self.Layout() 
     197            return self._DoDockItem(container, dockitem, *args, **kw) 
     198 
     199    def _DoDockItem(self, container, dockitem, *args, **kw): 
     200        self.dockcount += 1 
     201        try: DIReparent = dockitem.Reparent 
     202        except AttributeError: pass 
     203        else: DIReparent(self.parent) 
     204 
     205        if self.prepend: 
     206            self.layout.Prepend(dockitem, *args, **kw) 
     207        else: self.layout.Add(dockitem, *args, **kw) 
     208        self.OnDockItem(self, container, dockitem) 
     209        self.Layout() 
    162210 
    163211    def UndockItem(self, container, dockitem=None, *args, **kw): 
     
    166214                container.Undock() 
    167215        else: 
    168             self.dockcount -= 1 
    169             ### The following code is not required, but included so  
    170             ### we don't wonder about the asymetry ;) 
    171             ##try: DIReparent = dockitem.Reparent 
    172             ##except AttributeError: pass 
    173             ##else: DIReparent(None) 
    174  
    175             # Disable size hints so the frame can resize when needed 
    176             # We will re-enable in self.Layout 
    177             self.parent.SetSizeHints(0, 0) 
    178             self.layout.Remove(dockitem) 
    179             self.OnUndockItem(container, dockitem) 
    180             self.Layout() 
     216            return self._DoUndockItem(container, dockitem, *args, **kw) 
     217 
     218    def _DoUndockItem(self, container, dockitem, *args, **kw): 
     219        self.dockcount -= 1 
     220        ### The following code is not required, but included so  
     221        ### we don't wonder about the asymetry ;) 
     222        ##try: DIReparent = dockitem.Reparent 
     223        ##except AttributeError: pass 
     224        ##else: DIReparent(None) 
     225 
     226        # Disable size hints so the frame can resize when needed 
     227        # We will re-enable in self.Layout 
     228        self.parent.SetSizeHints(0, 0) 
     229        self.layout.Remove(dockitem) 
     230        self.OnUndockItem(self, container, dockitem) 
     231        self.Layout() 
    181232 
    182233    def Layout(self): 
     
    199250        SetLayoutContainerSizeHints(self.layout, self.parent) 
    200251        SetLayoutContainerSizeHints(self.rootlayout, self.rootparent) 
     252 
     253#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     254 
     255class wxSingleDockHost(wxDockHost, wxSingleDockHostMixin): 
     256    pass 
    201257 
    202258#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    257313            container.DockTo(self) 
    258314        else: 
    259             self.dockcount += 1 
    260  
    261             page = self.AcquireNotebookDockPage() 
    262  
    263             try: DIReparent = dockitem.Reparent 
     315            return self._DoDockItem(container, dockitem, *args, **kw) 
     316 
     317    def _DoDockItem(self, container, dockitem, *args, **kw): 
     318        self.dockcount += 1 
     319 
     320        page = self.AcquireNotebookDockPage() 
     321 
     322        try: DIReparent = dockitem.Reparent 
     323        except AttributeError: pass 
     324        else: DIReparent(page) 
     325 
     326        page.DockItem(dockitem, *args, **kw) 
     327 
     328        text = None 
     329        if text is None: 
     330            try: text = container.pagename 
    264331            except AttributeError: pass 
    265             else: DIReparent(page) 
    266  
    267             page.DockItem(dockitem, *args, **kw) 
    268  
    269             text = None 
    270             if text is None: 
    271                 try: text = container.pagename 
    272                 except AttributeError: pass 
    273             if text is None: 
    274                 try: text = dockitem.GetLabel() 
    275                 except AttributeError: pass 
    276             if text is None: 
    277                 text = text or dockitem.__class__.__name__ 
    278  
    279             if self.prepend: 
    280                 self.notebook.InsertPage(0, page, text, self.selectpage) 
    281             else: 
    282                 self.notebook.AddPage(page, text, self.selectpage) 
    283             page.Show(True) 
    284             self.OnDockItem(container, dockitem) 
    285             self.Layout() 
     332        if text is None: 
     333            try: text = dockitem.GetLabel() 
     334            except AttributeError: pass 
     335        if text is None: 
     336            text = text or dockitem.__class__.__name__ 
     337 
     338        if self.prepend: 
     339            self.notebook.InsertPage(0, page, text, self.selectpage) 
     340        else: 
     341            self.notebook.AddPage(page, text, self.selectpage) 
     342        page.Show(True) 
     343        self.OnDockItem(self, container, dockitem) 
     344        self.Layout() 
    286345 
    287346    def UndockItem(self, container, dockitem=None, *args, **kw): 
     
    290349                container.Undock() 
    291350        else: 
    292             self.dockcount -= 1 
    293             ### The following code is not required, but included so  
    294             ### we don't wonder about the asymetry ;) 
    295             ##try: DIReparent = dockitem.Reparent 
    296             ##except AttributeError: pass 
    297             ##else: DIReparent(None) 
    298  
    299             page = self.FindNotebookDockPage(dockitem) 
    300             page.UndockItem(dockitem) 
    301  
    302             for idx in range(self.notebook.GetPageCount()): 
    303                 if self.notebook.GetPage(idx) is page: 
    304                     self.notebook.RemovePage(idx) 
    305                     break 
    306  
    307             self.ReleaseNotebookDockPage(page) 
    308             self.OnUndockItem(container, dockitem) 
    309             self.Layout() 
     351            return self._DoUndockItem(container, dockitem, *args, **kw) 
     352 
     353    def _DoUndockItem(self, container, dockitem, *args, **kw): 
     354        self.dockcount -= 1 
     355        ### The following code is not required, but included so  
     356        ### we don't wonder about the asymetry ;) 
     357        ##try: DIReparent = dockitem.Reparent 
     358        ##except AttributeError: pass 
     359        ##else: DIReparent(None) 
     360 
     361        page = self.FindNotebookDockPage(dockitem) 
     362        if page is None: raise KeyError, "Dockitem not found" 
     363        page.UndockItem(dockitem) 
     364 
     365        for idx in range(self.notebook.GetPageCount()): 
     366            if self.notebook.GetPage(idx) is page: 
     367                self.notebook.RemovePage(idx) 
     368                break 
     369 
     370        self.ReleaseNotebookDockPage(page) 
     371        self.OnUndockItem(self, container, dockitem) 
     372        self.Layout() 
    310373 
    311374    def Layout(self): 
     
    338401                return page 
    339402 
     403#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     404 
     405class wxSingleNotebookDockHost(wxNotebookDockHost, wxSingleDockHostMixin): 
     406    pass 
     407 
  • trunk/RBSkinning/demo/wxPythonSkin/grafting/graft_layout.py

    r501 r504  
    3737        <layout sizercfg='1, wxEXPAND' fit='0'> 
    3838            <panel sizercfg='1, wxEXPAND' sizehints='300,300'> 
    39                 <layout ctxvar='ctx.behaviormodel.graftlayout' ctxnode='ctx.behaviormodel.graftpoint' sizercfg='1, wxEXPAND' > 
    40                     <button label='Add'> 
    41                         <command_event type='EVT_BUTTON' call='ctx.behaviormodel.Add' /> 
    42                     </button> 
     39                <layout sizercfg='1, wxEXPAND' > 
     40                    <layout sizercfg='0, wxEXPAND' > 
     41                        <button label='Add'> 
     42                            <command_event type='EVT_BUTTON' call='ctx.behaviormodel.Add' /> 
     43                        </button> 
     44                        <button label='Remove'> 
     45                            <command_event type='EVT_BUTTON' call='ctx.behaviormodel.Remove' /> 
     46                        </button> 
     47                    </layout> 
     48                    <panel ctxvar='ctx.behaviormodel.graftpanel' sizercfg='1, wxEXPAND' > 
     49                        <layout ctxvar='ctx.behaviormodel.graftlayout' ctxnode='ctx.behaviormodel.graftpoint' orientation='vertical' sizercfg='1, wxEXPAND' /> 
     50                    </panel> 
    4351                </layout> 
    4452            </panel> 
     
    7280        self.graftlayout.Layout() 
    7381 
     82    def Remove(self, evt): 
     83        # Remove all the children from the panel 
     84        while self.graftlayout.Remove(0): pass 
     85        # Destroy all the children, freeing up their resources 
     86        self.graftpanel.DestroyChildren() 
     87 
    7488#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    7589#~ Main