Changeset 4067

Show
Ignore:
Timestamp:
05/05/2008 11:39:45 AM (2 months ago)
Author:
ed
Message:

Added the dDockTabs class. This is analogous to the dDockForm, in that it is based on the wxPython AUI; in this case, the aui.AuiNotebook? class.

So far this has only been tested on OS X and wxPython 2.8.4.0; I plan on testing it on other platforms soon. I haven't exposed any of the tab styles, and it also appears that the tabs can only be placed on the top. But they are fully movable and dockable.

Files:

Legend:

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

    r3963 r4067  
    77if __name__ == "__main__": 
    88    dabo.ui.loadUI("wx") 
    9  
    10 import dPage 
    119import dabo.dEvents as dEvents 
    1210from dabo.dLocalize import _ 
    1311from dPageFrameMixin import dPageFrameMixin 
     12 
     13# dDockForm is not available with wxPython < 2.7 
     14_USE_DOCK = (wx.VERSION >= (2, 7)) 
     15if _USE_DOCK: 
     16    import wx.aui as aui 
    1417 
    1518 
     
    130133        dd.AppendItems(choices) 
    131134        dd.SetSelection(pos) 
     135 
     136 
     137if _USE_DOCK: 
     138    class dDockTabs(dPageFrameMixin, aui.AuiNotebook): 
     139        _evtPageChanged = readonly(aui.EVT_AUINOTEBOOK_PAGE_CHANGED) 
     140        _evtPageChanging = readonly(aui.EVT_AUINOTEBOOK_PAGE_CHANGING) 
     141        _tabposBottom = readonly(aui.AUI_NB_BOTTOM) 
     142        _tabposRight = readonly(aui.AUI_NB_RIGHT) 
     143        _tabposLeft = readonly(aui.AUI_NB_LEFT) 
     144        _tabposTop = readonly(aui.AUI_NB_TOP) 
     145     
     146        def __init__(self, parent, properties=None, attProperties=None, *args, **kwargs): 
     147            self._baseClass = dDockTabs 
     148            preClass = aui.AuiNotebook 
     149             
     150            newStyle = (aui.AUI_NB_TOP | aui.AUI_NB_TAB_SPLIT | aui.AUI_NB_TAB_MOVE 
     151                    | aui.AUI_NB_SCROLL_BUTTONS | aui.AUI_NB_CLOSE_ON_ALL_TABS) 
     152            if "style" in kwargs: 
     153                newStyle = kwargs["style"] | newStyle 
     154            kwargs["style"] = newStyle 
     155            dPageFrameMixin.__init__(self, preClass, parent, properties, attProperties, *args, **kwargs) 
     156     
     157     
     158        def insertPage(self, pos, pgCls=None, caption="", imgKey=None, 
     159                ignoreOverride=False): 
     160            """ Insert the page into the pageframe at the specified position,  
     161            and optionally sets the page caption and image. The image  
     162            should have already been added to the pageframe if it is  
     163            going to be set here. 
     164            """ 
     165            # Allow subclasses to potentially override this behavior. This will 
     166            # enable them to handle page creation in their own way. If overridden, 
     167            # the method will return the new page. 
     168            ret = None 
     169            if not ignoreOverride: 
     170                ret = self._insertPageOverride(pos, pgCls, caption, imgKey) 
     171            if ret: 
     172                return ret           
     173            if pgCls is None: 
     174                pgCls = self.PageClass 
     175            if isinstance(pgCls, dabo.ui.dPage): 
     176                pg = pgCls 
     177            else: 
     178                # See if the 'pgCls' is either some XML or the path of an XML file 
     179                if isinstance(pgCls, basestring): 
     180                    xml = pgCls 
     181                    from dabo.lib.DesignerXmlConverter import DesignerXmlConverter 
     182                    conv = DesignerXmlConverter() 
     183                    pgCls = conv.classFromXml(xml) 
     184                pg = pgCls(self) 
     185            if not caption: 
     186                # Page could have its own default caption 
     187                caption = pg._caption 
     188            if imgKey: 
     189                idx = self._imageList[imgKey] 
     190                bmp = self.GetImageList().GetBitmap(idx) 
     191                self.InsertPage(pos, pg, caption=caption, bitmap=bmp) 
     192            else: 
     193                self.InsertPage(pos, pg, caption=caption) 
     194            self.layout() 
     195            return self.Pages[pos] 
     196        def _insertPageOverride(self, pos, pgCls, caption, imgKey): pass 
     197else: 
     198    dDockTabs = dPageFrame 
    132199         
    133200 
    134201import random 
    135 class _dPageFrame_test(dPageFrame): 
     202 
     203class TestMixin(object): 
    136204    def initProperties(self): 
    137205        self.Width = 400 
     
    142210        self.appendPage(caption="Introduction") 
    143211        self.appendPage(caption="Chapter I") 
     212        self.appendPage(caption="Chapter 2") 
     213        self.appendPage(caption="Chapter 3") 
    144214        self.Pages[0].BackColor = "darkred" 
    145215        self.Pages[1].BackColor = "darkblue" 
     216        self.Pages[2].BackColor = "green" 
     217        self.Pages[3].BackColor = "yellow" 
    146218     
    147219    def onPageChanged(self, evt): 
    148220        print "Page number changed from %s to %s" % (evt.oldPageNum, evt.newPageNum) 
    149221 
    150  
    151 class _dPageList_test(dPageList): 
    152     def initProperties(self): 
    153         self.Width = 400 
    154         self.Height = 175 
    155         self.TabPosition = random.choice(("Top", "Bottom", "Left", "Right")) 
    156      
    157     def afterInit(self): 
    158         self.appendPage(caption="Introduction") 
    159         self.appendPage(caption="Chapter I") 
    160         self.Pages[0].BackColor = "darkred" 
    161         self.Pages[1].BackColor = "darkblue" 
    162      
    163     def onPageChanged(self, evt): 
    164         print "Page number changed from %s to %s" % (evt.oldPageNum, evt.newPageNum) 
    165  
    166  
    167 class _dPageSelect_test(dPageSelect): 
    168     def initProperties(self): 
    169         self.Width = 400 
    170         self.Height = 175 
    171         self.TabPosition = random.choice(("Top", "Bottom", "Left", "Right")) 
    172      
    173     def afterInit(self): 
    174         self.appendPage(caption="Introduction") 
    175         self.appendPage(caption="Chapter I") 
    176         self.Pages[0].BackColor = "darkred" 
    177         self.Pages[1].BackColor = "darkblue" 
    178      
    179     def onPageChanged(self, evt): 
    180         print "Page number changed from %s to %s" % (evt.oldPageNum, evt.newPageNum) 
     222class _dPageFrame_test(TestMixin, dPageFrame): pass 
     223class _dPageList_test(TestMixin, dPageList): pass 
     224class _dPageSelect_test(TestMixin, dPageSelect): pass 
     225class _dDockTabs_test(TestMixin, dDockTabs): pass 
    181226 
    182227 
     
    187232    test.Test().runTest(_dPageList_test) 
    188233    test.Test().runTest(_dPageSelect_test) 
    189  
     234    test.Test().runTest(_dDockTabs_test)