dabo Commit
Revision 4067
Date: 2008-05-05 11:39:45 -0700 (Mon, 05 May 2008)
Author: Ed
Trac: http://svn.dabodev.com/trac/dabo/changeset/4067

Changed:
U   trunk/dabo/ui/uiwx/dPageFrame.py

Log:
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.



Diff:
Modified: trunk/dabo/ui/uiwx/dPageFrame.py
===================================================================
--- trunk/dabo/ui/uiwx/dPageFrame.py    2008-05-05 18:16:02 UTC (rev 4066)
+++ trunk/dabo/ui/uiwx/dPageFrame.py    2008-05-05 18:39:45 UTC (rev 4067)
@@ -6,13 +6,16 @@
 
 if __name__ == "__main__":
        dabo.ui.loadUI("wx")
-
-import dPage
 import dabo.dEvents as dEvents
 from dabo.dLocalize import _
 from dPageFrameMixin import dPageFrameMixin
 
+# dDockForm is not available with wxPython < 2.7
+_USE_DOCK = (wx.VERSION >= (2, 7))
+if _USE_DOCK:
+       import wx.aui as aui
 
+
 def readonly(value):
        """ Create a read-only property. """
        return property(lambda self: value)
@@ -129,26 +132,75 @@
                dd.Clear()
                dd.AppendItems(choices)
                dd.SetSelection(pos)
-               
 
-import random
-class _dPageFrame_test(dPageFrame):
-       def initProperties(self):
-               self.Width = 400
-               self.Height = 175
-               self.TabPosition = random.choice(("Top", "Bottom", "Left", 
"Right"))
+
+if _USE_DOCK:
+       class dDockTabs(dPageFrameMixin, aui.AuiNotebook):
+               _evtPageChanged = readonly(aui.EVT_AUINOTEBOOK_PAGE_CHANGED)
+               _evtPageChanging = readonly(aui.EVT_AUINOTEBOOK_PAGE_CHANGING)
+               _tabposBottom = readonly(aui.AUI_NB_BOTTOM)
+               _tabposRight = readonly(aui.AUI_NB_RIGHT)
+               _tabposLeft = readonly(aui.AUI_NB_LEFT)
+               _tabposTop = readonly(aui.AUI_NB_TOP)
        
-       def afterInit(self):
-               self.appendPage(caption="Introduction")
-               self.appendPage(caption="Chapter I")
-               self.Pages[0].BackColor = "darkred"
-               self.Pages[1].BackColor = "darkblue"
+               def __init__(self, parent, properties=None, attProperties=None, 
*args, **kwargs):
+                       self._baseClass = dDockTabs
+                       preClass = aui.AuiNotebook
+                       
+                       newStyle = (aui.AUI_NB_TOP | aui.AUI_NB_TAB_SPLIT | 
aui.AUI_NB_TAB_MOVE
+                                       | aui.AUI_NB_SCROLL_BUTTONS | 
aui.AUI_NB_CLOSE_ON_ALL_TABS)
+                       if "style" in kwargs:
+                               newStyle = kwargs["style"] | newStyle
+                       kwargs["style"] = newStyle
+                       dPageFrameMixin.__init__(self, preClass, parent, 
properties, attProperties, *args, **kwargs)
        
-       def onPageChanged(self, evt):
-               print "Page number changed from %s to %s" % (evt.oldPageNum, 
evt.newPageNum)
+       
+               def insertPage(self, pos, pgCls=None, caption="", imgKey=None,
+                               ignoreOverride=False):
+                       """ Insert the page into the pageframe at the specified 
position, 
+                       and optionally sets the page caption and image. The 
image 
+                       should have already been added to the pageframe if it 
is 
+                       going to be set here.
+                       """
+                       # Allow subclasses to potentially override this 
behavior. This will
+                       # enable them to handle page creation in their own way. 
If overridden,
+                       # the method will return the new page.
+                       ret = None
+                       if not ignoreOverride:
+                               ret = self._insertPageOverride(pos, pgCls, 
caption, imgKey)
+                       if ret:
+                               return ret                      
+                       if pgCls is None:
+                               pgCls = self.PageClass
+                       if isinstance(pgCls, dabo.ui.dPage):
+                               pg = pgCls
+                       else:
+                               # See if the 'pgCls' is either some XML or the 
path of an XML file
+                               if isinstance(pgCls, basestring):
+                                       xml = pgCls
+                                       from dabo.lib.DesignerXmlConverter 
import DesignerXmlConverter
+                                       conv = DesignerXmlConverter()
+                                       pgCls = conv.classFromXml(xml)
+                               pg = pgCls(self)
+                       if not caption:
+                               # Page could have its own default caption
+                               caption = pg._caption
+                       if imgKey:
+                               idx = self._imageList[imgKey]
+                               bmp = self.GetImageList().GetBitmap(idx)
+                               self.InsertPage(pos, pg, caption=caption, 
bitmap=bmp)
+                       else:
+                               self.InsertPage(pos, pg, caption=caption)
+                       self.layout()
+                       return self.Pages[pos]
+               def _insertPageOverride(self, pos, pgCls, caption, imgKey): pass
+else:
+       dDockTabs = dPageFrame
+               
 
+import random
 
-class _dPageList_test(dPageList):
+class TestMixin(object):
        def initProperties(self):
                self.Width = 400
                self.Height = 175
@@ -157,33 +209,26 @@
        def afterInit(self):
                self.appendPage(caption="Introduction")
                self.appendPage(caption="Chapter I")
+               self.appendPage(caption="Chapter 2")
+               self.appendPage(caption="Chapter 3")
                self.Pages[0].BackColor = "darkred"
                self.Pages[1].BackColor = "darkblue"
+               self.Pages[2].BackColor = "green"
+               self.Pages[3].BackColor = "yellow"
        
        def onPageChanged(self, evt):
                print "Page number changed from %s to %s" % (evt.oldPageNum, 
evt.newPageNum)
 
+class _dPageFrame_test(TestMixin, dPageFrame): pass
+class _dPageList_test(TestMixin, dPageList): pass
+class _dPageSelect_test(TestMixin, dPageSelect): pass
+class _dDockTabs_test(TestMixin, dDockTabs): pass
 
-class _dPageSelect_test(dPageSelect):
-       def initProperties(self):
-               self.Width = 400
-               self.Height = 175
-               self.TabPosition = random.choice(("Top", "Bottom", "Left", 
"Right"))
-       
-       def afterInit(self):
-               self.appendPage(caption="Introduction")
-               self.appendPage(caption="Chapter I")
-               self.Pages[0].BackColor = "darkred"
-               self.Pages[1].BackColor = "darkblue"
-       
-       def onPageChanged(self, evt):
-               print "Page number changed from %s to %s" % (evt.oldPageNum, 
evt.newPageNum)
 
-
                
 if __name__ == "__main__":
        import test
        test.Test().runTest(_dPageFrame_test)
        test.Test().runTest(_dPageList_test)
        test.Test().runTest(_dPageSelect_test)
-
+       test.Test().runTest(_dDockTabs_test)




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to