dabo Commit
Revision 4404
Date: 2008-08-13 12:44:54 -0700 (Wed, 13 Aug 2008)
Author: Nate
Trac: http://svn.dabodev.com/trac/dabo/changeset/4404

Changed:
U   branches/Nate/dabo/dEvents.py
U   branches/Nate/dabo/ui/uiwx/dPageFrame.py

Log:
Initial rewriting of dPageFrame to using the FlatNotebook control in wx.lib.  
The only downside is that the control doesn't support the left or right tab 
position.  However, the functionality it brings out more than warrants it's 
inclusion.  So far, I have wrapped the wx events for page closing, page closed, 
and page context menu.  Added dEvents to correspond to the wx events.  All 
works so feel free to play around with it, though I am going to add more 
functionality.

Ed and Paul, is the TabPosition property not support right and left is going to 
be a problem for inclusion into trunk as dPageFrame?  If so, did you just want 
to rename this class?

Diff:
Modified: branches/Nate/dabo/dEvents.py
===================================================================
--- branches/Nate/dabo/dEvents.py       2008-08-13 16:43:21 UTC (rev 4403)
+++ branches/Nate/dabo/dEvents.py       2008-08-13 19:44:54 UTC (rev 4404)
@@ -467,6 +467,27 @@
        appliesToClass = classmethod(appliesToClass)
 
 
+class PageClosed(dEvent):
+       """Occurs when a page in a dPageFrame control is closed"""
+       def appliesToClass(eventClass, objectClass):
+               return issubclass(objectClass, dabo.ui.dPageFrame)
+       appliesToClass = classmethod(appliesToClass)
+
+
+class PageClosing(dEvent):
+       """Occurs when a page in a dPageFrame control is about to close"""
+       def appliesToClass(eventClass, objectClass):
+               return issubclass(objectClass, dabo.ui.dPageFrame)
+       appliesToClass = classmethod(appliesToClass)
+
+
+class PageContextMenu(dEvent):
+       """Occurs when the user requests a context event for a dPage"""
+       def appliesToClass(eventClass, objectClass):
+               return issubclass(objectClass, dabo.ui.dPage)
+       appliesToClass = classmethod(appliesToClass)
+
+
 class PageEnter(dEvent):
        """Occurs when the page becomes the active page."""
        def appliesToClass(eventClass, objectClass):

Modified: branches/Nate/dabo/ui/uiwx/dPageFrame.py
===================================================================
--- branches/Nate/dabo/ui/uiwx/dPageFrame.py    2008-08-13 16:43:21 UTC (rev 
4403)
+++ branches/Nate/dabo/ui/uiwx/dPageFrame.py    2008-08-13 19:44:54 UTC (rev 
4404)
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 import sys
 import wx
+import wx.lib.flatnotebook as fnb
 import dabo
 import dabo.ui
 
@@ -21,31 +22,80 @@
        return property(lambda self: value)
 
 
-class dPageFrame(dPageFrameMixin, wx.Notebook):
+class dPageFrame(dPageFrameMixin, fnb.FlatNotebook):
        """Creates a pageframe, which can contain an unlimited number of pages,
        each of which should be a subclass/instance of the dPage class.
        """
-       _evtPageChanged = readonly(wx.EVT_NOTEBOOK_PAGE_CHANGED)
-       _evtPageChanging = readonly(wx.EVT_NOTEBOOK_PAGE_CHANGING)
-       _tabposBottom = readonly(wx.NB_BOTTOM)
-       _tabposRight = readonly(wx.NB_RIGHT)
-       _tabposLeft = readonly(wx.NB_LEFT)
+       _evtPageChanged = readonly(fnb.EVT_FLATNOTEBOOK_PAGE_CHANGED)
+       _evtPageChanging = readonly(fnb.EVT_FLATNOTEBOOK_PAGE_CHANGING)
+       _tabposBottom = readonly(fnb.FNB_BOTTOM)
        
        def __init__(self, parent, properties=None, attProperties=None, *args, 
**kwargs):
                self._baseClass = dPageFrame
-               preClass = wx.PreNotebook
+               preClass = fnb.FlatNotebook
                
                dPageFrameMixin.__init__(self, preClass, parent, properties, 
attProperties, *args, **kwargs)
-
-
+       
+       def _initEvents(self):
+               super(dPageFrame, self)._initEvents()
+               self.Bind(fnb.EVT_FLATNOTEBOOK_PAGE_CLOSING, 
self.__onPageClosing)
+               self.Bind(fnb.EVT_FLATNOTEBOOK_PAGE_CLOSED, self.__onPageClosed)
+               self.Bind(fnb.EVT_FLATNOTEBOOK_PAGE_CONTEXT_MENU, 
self.__onPageContextMenu)
+       
        def _afterInit(self):
                if sys.platform[:3] == "win":
                        ## This keeps Pages from being ugly on Windows:
                        self.SetBackgroundColour(self.GetBackgroundColour())
                super(dPageFrame, self)._afterInit()
+       
+       def __onPageClosing(self, evt):
+               """The page has not yet been closed, so we can veto it if 
conditions call for it."""
+               pageNum = evt.GetSelection()
+               if self._beforePageClose(pageNum) is False:
+                       evt.Veto()
+               else:
+                       evt.Skip()
+               self.raiseEvent(dEvents.PageClosing, pageNum=pageNum)
+       
+       def _beforePageClose(self, page):
+               return self.beforePageClose(page)
+       
+       
+       def beforePageClose(self, page):
+               """Return False from this method to prevent the page from 
closing."""
+               pass
+       
+       def __onPageClosed(self, evt):
+               self.raiseEvent(dEvents.PageClosed)
+       
+       def __onPageContextMenu(self, evt):
+               
self.GetPage(self.GetSelection()).raiseEvent(dEvents.PageContextMenu)
+       
+       #Property getters and setters
+       def _getTabPosition(self):
+               if self._hasWindowStyleFlag(self._tabposBottom):
+                       return "Bottom"
+               else:
+                       return "Top"
+       
+       def _setTabPosition(self, val):
+               val = str(val)
+               self._delWindowStyleFlag(self._tabposBottom)
+               
+               if val == "Top":
+                       pass
+               elif val == "Bottom":
+                       self._addWindowStyleFlag(self._tabposBottom)
+               else:
+                       raise ValueError, (_("The only possible values are 
'Top' and 'Bottom'"))
+       
+       #Property definitions
+       TabPosition = property(_getTabPosition, _setTabPosition, None, 
+                       _("""Specifies where the page tabs are located. 
(string) 
+                               Top (default) 
+                               Bottom""") )
 
 
-
 class dPageList(dPageFrameMixin, wx.Listbook):
        _evtPageChanged = readonly(wx.EVT_LISTBOOK_PAGE_CHANGED)
        _evtPageChanging = readonly(wx.EVT_LISTBOOK_PAGE_CHANGING)
@@ -219,7 +269,12 @@
        def onPageChanged(self, evt):
                print "Page number changed from %s to %s" % (evt.oldPageNum, 
evt.newPageNum)
 
-class _dPageFrame_test(TestMixin, dPageFrame): pass
+class _dPageFrame_test(TestMixin, dPageFrame): 
+       def initProperties(self):
+               self.Width = 400
+               self.Height = 175
+               self.TabPosition = random.choice(("Top", "Bottom"))
+
 class _dPageList_test(TestMixin, dPageList): pass
 class _dPageSelect_test(TestMixin, dPageSelect): pass
 class _dDockTabs_test(TestMixin, dDockTabs): pass




_______________________________________________
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