dabo Commit
Revision 2541
Date: 2006-12-14 10:31:03 -0800 (Thu, 14 Dec 2006)
Author: Ed

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

Log:
Trapped the page changing event for the various paged controls, and added a 
'beforePageChange' hook that receives two params: the current page, and the one 
that the user is trying to change to. Returning False from that method will 
prevent the page from changing.

Also added test examples for the other paged controls defined in dPageFrame.py.


Diff:
Modified: trunk/dabo/ui/uiwx/dPageFrame.py
===================================================================
--- trunk/dabo/ui/uiwx/dPageFrame.py    2006-12-14 16:50:04 UTC (rev 2540)
+++ trunk/dabo/ui/uiwx/dPageFrame.py    2006-12-14 18:31:03 UTC (rev 2541)
@@ -25,6 +25,7 @@
        Dabo visual control, such as a dPanel, dEditBox, etc.
        """
        _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)
@@ -45,21 +46,10 @@
                super(dPageFrame, self)._afterInit()
 
 
-class _dPageFrame_test(dPageFrame):
-       def initProperties(self):
-               self.Width = 400
-               self.Height = 175
-       
-       def afterInit(self):
-               self.appendPage(caption="Introduction")
-               self.appendPage(caption="Chapter I")
-       
-       def onPageChanged(self, evt):
-               print "Page number changed from %s to %s" % (evt.oldPageNum, 
evt.newPageNum)
 
-
 class dPageList(dPageFrameMixin, wx.Listbook):
        _evtPageChanged = readonly(wx.EVT_LISTBOOK_PAGE_CHANGED)
+       _evtPageChanging = readonly(wx.EVT_LISTBOOK_PAGE_CHANGING)
        _tabposBottom = readonly(wx.LB_BOTTOM)
        _tabposRight = readonly(wx.LB_RIGHT)
        _tabposLeft = readonly(wx.LB_LEFT)
@@ -105,6 +95,7 @@
 
 class dPageSelect(dPageFrameMixin, wx.Choicebook):
        _evtPageChanged = readonly(wx.EVT_CHOICEBOOK_PAGE_CHANGED)
+       _evtPageChanging = readonly(wx.EVT_CHOICEBOOK_PAGE_CHANGING)
        _tabposBottom = readonly(wx.CHB_BOTTOM)
        _tabposRight = readonly(wx.CHB_RIGHT)
        _tabposLeft = readonly(wx.CHB_LEFT)
@@ -134,7 +125,60 @@
                dd.SetSelection(pos)
                
                
+               
+               
+class _dPageFrame_test(dPageFrame):
+       def initProperties(self):
+               self.Width = 400
+               self.Height = 175
+       
+       def afterInit(self):
+               self.appendPage(caption="Introduction")
+               self.appendPage(caption="Chapter I")
+               self.appendPage(caption="Chapter 2")
+       
+       def beforePageChange(self, fromPage, toPage):
+               # Don't allow the user to go from page 0 to page 2
+               if fromPage == 0 and toPage == 2:
+                       return False
+               else:
+                       return True
+       
+       def onPageChanged(self, evt):
+               print "Page number changed from %s to %s" % (evt.oldPageNum, 
evt.newPageNum)
+
+
+class _dPageList_test(dPageList):
+       def initProperties(self):
+               self.Width = 400
+               self.Height = 175
+       
+       def afterInit(self):
+               self.appendPage(caption="Introduction")
+               self.appendPage(caption="Chapter I")
+               self.appendPage(caption="Chapter 2")
+       
+       def onPageChanged(self, evt):
+               print "Page number changed from %s to %s" % (evt.oldPageNum, 
evt.newPageNum)
+
+
+class _dPageSelect_test(dPageSelect):
+       def initProperties(self):
+               self.Width = 400
+               self.Height = 175
+       
+       def afterInit(self):
+               self.appendPage(caption="Introduction")
+               self.appendPage(caption="Chapter I")
+               self.appendPage(caption="Chapter 2")
+       
+       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)
 

Modified: trunk/dabo/ui/uiwx/dPageFrameMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dPageFrameMixin.py       2006-12-14 16:50:04 UTC (rev 
2540)
+++ trunk/dabo/ui/uiwx/dPageFrameMixin.py       2006-12-14 18:31:03 UTC (rev 
2541)
@@ -21,9 +21,29 @@
        def _initEvents(self):
                super(dPageFrameMixin, self)._initEvents()
                self.Bind(self._evtPageChanged, self.__onPageChanged)
+               self.Bind(self._evtPageChanging, self.__onPageChanging)
                self.bindEvent(dEvents.Create, self.__onCreate)
 
+       
+       def __onPageChanging(self, evt):
+               """The page has not yet been changed, so we can veto it if 
conditions call for it."""
+               oldPageNum = evt.GetOldSelection()
+               newPageNum = evt.GetSelection()
+               if self._beforePageChange(oldPageNum, newPageNum) is False:
+                       evt.Veto()
+               self.raiseEvent(dEvents.PageChanging, oldPageNum=oldPageNum, 
+                               newPageNum=newPageNum)
+                               
+       
+       def _beforePageChange(self, old, new):
+               return self.beforePageChange(old, new)
+       
+       
+       def beforePageChange(self, fromPage, toPage):
+               """Return False from this method to prevent the page from 
changing."""
+               pass
                
+               
        def __onCreate(self, evt):
                # Make sure the PageEnter fires for the current page on 
                # pageframe instantiation, as this doesn't happen automatically.




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev

Reply via email to