dabo Commit
Revision 4436
Date: 2008-08-22 11:40:14 -0700 (Fri, 22 Aug 2008)
Author: Nate
Trac: http://svn.dabodev.com/trac/dabo/changeset/4436
Changed:
U trunk/dabo/ui/uiwx/__init__.py
U trunk/dabo/ui/uiwx/dPageFrame.py
Log:
Merged changes from my branch into the trunk. DPageFrame is now in trunk.
Diff:
Modified: trunk/dabo/ui/uiwx/__init__.py
===================================================================
--- trunk/dabo/ui/uiwx/__init__.py 2008-08-22 18:33:02 UTC (rev 4435)
+++ trunk/dabo/ui/uiwx/__init__.py 2008-08-22 18:40:14 UTC (rev 4436)
@@ -151,6 +151,10 @@
except ImportError:
pass
+#The flatnotebook version we need is not avialable with wxPython < 2.8.4
+if wx.VERSION >= (2, 8, 4):
+ from dPageFrame import DPageFrame
+
# dDockForm is not available with wxPython < 2.7
if wx.VERSION >= (2, 7):
from dDockForm import dDockForm
Modified: trunk/dabo/ui/uiwx/dPageFrame.py
===================================================================
--- trunk/dabo/ui/uiwx/dPageFrame.py 2008-08-22 18:33:02 UTC (rev 4435)
+++ trunk/dabo/ui/uiwx/dPageFrame.py 2008-08-22 18:40:14 UTC (rev 4436)
@@ -9,18 +9,30 @@
import dabo.dEvents as dEvents
from dabo.dLocalize import _
from dPageFrameMixin import dPageFrameMixin
+import dabo.dColors as dColors
# dDockForm is not available with wxPython < 2.7
_USE_DOCK = (wx.VERSION >= (2, 7))
if _USE_DOCK:
import wx.aui as aui
+#The flatnotebook version we need is not avialable with wxPython < 2.8.4
+_USE_FLAT = (wx.VERSION >= (2, 8, 4))
+if _USE_FLAT:
+ #The Editra flatnotebook module takes care of the Nav Buttons and
Dropdown Tab List overlap problem, so import that module
+ #Why wxPython doesn't fold this flatnotebook module into the main one
is beyond me...
+ if (wx.VERSION >= (2, 8, 7, 1)):
+ _USE_EDITRA = True
+ import wx.tools.Editra.src.extern.flatnotebook as fnb
+ else:
+ _USE_EDITRA = False
+ import wx.lib.flatnotebook as fnb
+
def readonly(value):
""" Create a read-only property. """
return property(lambda self: value)
-
class dPageFrame(dPageFrameMixin, wx.Notebook):
"""Creates a pageframe, which can contain an unlimited number of pages,
each of which should be a subclass/instance of the dPage class.
@@ -36,8 +48,7 @@
preClass = wx.PreNotebook
dPageFrameMixin.__init__(self, preClass, parent, properties,
attProperties, *args, **kwargs)
-
-
+
def _afterInit(self):
if sys.platform[:3] == "win":
## This keeps Pages from being ugly on Windows:
@@ -45,7 +56,6 @@
super(dPageFrame, self)._afterInit()
-
class dPageList(dPageFrameMixin, wx.Listbook):
_evtPageChanged = readonly(wx.EVT_LISTBOOK_PAGE_CHANGED)
_evtPageChanging = readonly(wx.EVT_LISTBOOK_PAGE_CHANGING)
@@ -196,8 +206,296 @@
def _insertPageOverride(self, pos, pgCls, caption, imgKey): pass
else:
dDockTabs = dPageFrame
+
+if _USE_FLAT:
+ 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(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 = fnb.FlatNotebook
+
+ self._inactiveTabTextColor = None
+ self._menuBackColor = None
+ self._showDropdownTabList = False
+ self._showMenuCloseButton = True
+ self._showMenuOnSingleTab = True
+ self._showNavButtons = True
+ self._showPageCloseButtons = False
+ self._tabSideIncline = 0
+ self._tabStyle = "Default"
+
+ 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 insertPage(self, *args, **kwargs):
+ page = super(DPageFrame, self).insertPage(*args,
**kwargs)
+ self.SetAllPagesShapeAngle(self._tabSideIncline)
#incline isn't autoset on new page add so set it
+ return 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 _getActiveTabTextColor(self):
+ return self._activeTabTextColor
+
+ def _setActiveTabTextColor(self, val):
+ if self._constructed():
+ self._activeTabTextColor = val
+ if isinstance(val, basestring):
+ val = dColors.colorTupleFromName(val)
+ if isinstance(val, tuple):
+
self.SetActiveTabTextColour(wx.Colour(*val))
+ self.Refresh()
+ else:
+ raise ValueError, (_("'%s' can not be
translated into a color" % val))
+ else:
+ self._properties["ActiveTabTextColor"] = val
+
+
+ def _getInactiveTabTextColor(self):
+ return self._inactiveTabTextColor
+
+ def _setInactiveTabTextColor(self, val):
+ if self._constructed():
+ self._inactiveTabTextColor = val
+ if isinstance(val, basestring):
+ val = dColors.colorTupleFromName(val)
+ if isinstance(val, tuple):
+
self.SetNonActiveTabTextColour(wx.Colour(*val))
+ self.Refresh()
+ else:
+ raise ValueError, (_("'%s' can not be
translated into a color" % val))
+ else:
+ self._properties["InactiveTabTextColor"] = val
+
+
+ def _getMenuBackColor(self):
+ return self._menuBackColor
+
+ def _setMenuBackColor(self, val):
+ if self._constructed():
+ self._menuBackColor = val
+ if isinstance(val, basestring):
+ val = dColors.colorTupleFromName(val)
+ if isinstance(val, tuple):
+ self.SetTabAreaColour(wx.Colour(*val))
+ self.Refresh()
+ else:
+ raise ValueError, (_("'%s' can not be
translated into a color" % val))
+ else:
+ self._properties["MenuBackColor"] = val
+
+
+ def _getShowDropdownTabList(self):
+ return self._showDropdownTabList
+
+ def _setShowDropdownTabList(self, val):
+ val = bool(val)
+ if val:
+
self._addWindowStyleFlag(fnb.FNB_DROPDOWN_TABS_LIST)
+ if not _USE_EDITRA:
+
self._addWindowStyleFlag(fnb.FNB_NO_NAV_BUTTONS)
+ self._showNavButtons = False
+ else:
+
self._delWindowStyleFlag(fnb.FNB_DROPDOWN_TABS_LIST)
+
+ self._showDropdownTabList = val
+
+
+ def _getShowMenuCloseButton(self):
+ return self._showMenuCloseButton
+
+ def _setShowMenuCloseButton(self, val):
+ val = bool(val)
+ if val:
+ self._delWindowStyleFlag(fnb.FNB_NO_X_BUTTON)
+ else:
+ self._addWindowStyleFlag(fnb.FNB_NO_X_BUTTON)
+ self._showMenuCloseButton = val
+
+
+ def _getShowMenuOnSingleTab(self):
+ return self._showMenuOnSingleTab
+
+ def _setShowMenuOnSingleTab(self, val):
+ val = bool(val)
+ if val:
+
self._delWindowStyleFlag(fnb.FNB_HIDE_ON_SINGLE_TAB)
+ else:
+
self._addWindowStyleFlag(fnb.FNB_HIDE_ON_SINGLE_TAB)
+ self._showMenuOnSingleTab = val
+
+
+ def _getShowNavButtons(self):
+ return self._showNavButtons
+
+ def _setShowNavButtons(self, val):
+ val = bool(val)
+ if val:
+ self._delWindowStyleFlag(fnb.FNB_NO_NAV_BUTTONS)
+ if not _USE_EDITRA:
+
self._delWindowStyleFlag(fnb.FNB_DROPDOWN_TABS_LIST)
+ self._showDropdownTabList = False
+ else:
+ self._addWindowStyleFlag(fnb.FNB_NO_NAV_BUTTONS)
+ self._showNavButtons = val
+
+
+ def _getShowPageCloseButtons(self):
+ return self._showPageCloseButtons
+
+ def _setShowPageCloseButtons(self, val):
+ val = bool(val)
+ if val:
+ self._addWindowStyleFlag(fnb.FNB_X_ON_TAB)
+ else:
+ self._delWindowStyleFlag(fnb.FNB_X_ON_TAB)
+ self._showPageCloseButtons = val
+
+
+ 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'"))
+
+
+ def _getTabSideIncline(self):
+ return self._tabSideIncline
+
+ def _setTabSideIncline(self, val):
+ val = int(val)
+ if val<0 or val>15:
+ raise ValueError, (_("Value must be 0 through
15"))
+
+ self._tabSideIncline = val
+ self.SetAllPagesShapeAngle(val)
+
+
+ def _getTabStyle(self):
+ return self._tabStyle
+
+ def _setTabStyle(self, val):
+ self._delWindowStyleFlag(fnb.FNB_VC8)
+ self._delWindowStyleFlag(fnb.FNB_VC71)
+ self._delWindowStyleFlag(fnb.FNB_FANCY_TABS)
+ self._delWindowStyleFlag(fnb.FNB_FF2)
+
+ if val == "Default":
+ pass
+ elif val == "VC8":
+ self._addWindowStyleFlag(fnb.FNB_VC8)
+ elif val == "VC71":
+ self._addWindowStyleFlag(fnb.FNB_VC71)
+ elif val == "Fancy":
+ self._addWindowStyleFlag(fnb.FNB_FANCY_TABS)
+ elif val == "Firefox":
+ self._addWindowStyleFlag(fnb.FNB_FF2)
+ else:
+ ValueError, (_("The only possible values are
'Default' and 'VC8', 'VC71', 'Fancy', or 'Firefox'"))
+
+ self._tabStyle = val
+
+
+ #Property definitions
+ ActiveTabTextColor = property(_getActiveTabTextColor,
_setActiveTabTextColor, None,
+ _("""Specifies the color of the text of the active tab
(str or 3-tuple) (Default=None)
+ Note, is not visible with the 'VC8'
TabStyle"""))
+
+ InactiveTabTextColor = property(_getInactiveTabTextColor,
_setInactiveTabTextColor, None,
+ _("""Specifies the color of the text of non active tabs
(str or 3-tuple) (Default=None)
+ Note, is not visible with the 'VC8'
TabStyle"""))
+
+ MenuBackColor = property(_getMenuBackColor, _setMenuBackColor,
None,
+ _("""Specifies the background color of the menu (str or
3-tuple) (Default=None)
+ Note, is not visible with 'VC71' TabStyle."""))
+
+ ShowDropdownTabList = property(_getShowDropdownTabList,
_setShowDropdownTabList, None,
+ _("""Specifies whether the dropdown tab list
button is visible in the menu (bool) (Default=False)
+ Setting this property to True will set
ShowNavButtons to False"""))
+
+ ShowMenuCloseButton = property(_getShowMenuCloseButton,
_setShowMenuCloseButton, None,
+ _("Specifies whether the close button is
visible in the menu (bool) (Default=False)"))
+
+ ShowMenuOnSingleTab = property(_getShowMenuOnSingleTab,
_setShowMenuOnSingleTab, None,
+ _("Specifies whether the tab thumbs and nav
buttons are shown when there is a single tab. (bool) (Default=True)"))
+
+ ShowPageCloseButtons = property(_getShowPageCloseButtons,
_setShowPageCloseButtons, None,
+ _("Specifies whether the close button is
visible on the page tab (bool) (Default=False)"))
+
+ ShowNavButtons = property(_getShowNavButtons,
_setShowNavButtons, None,
+ _("""Specifies whether the left and right nav
buttons are visible in the menu (bool) (Default=True)
+ Setting this property to True will set
ShowDropdownTabList to False"""))
+
+ TabPosition = property(_getTabPosition, _setTabPosition, None,
+ _("""Specifies where the page tabs are located.
(string)
+ Top (default)
+ Bottom""") )
+
+ TabSideIncline = property(_getTabSideIncline,
_setTabSideIncline, None,
+ _("""Specifies the incline of the sides of the
tab in degrees (int) (Default=0)
+ Acceptable values are 0 - 15.
+ Note this property will have no effect
on TabStyles other than Default.
+ """))
+
+ TabStyle = property(_getTabStyle, _setTabStyle, None,
+ _("""Specifies the style of the display tabs.
(string)
+ "Default" (default)
+ "VC8"
+ "VC71"
+ "Fancy"
+ "Firefox\""""))
+
import random
class TestMixin(object):
@@ -223,12 +521,29 @@
class _dPageList_test(TestMixin, dPageList): pass
class _dPageSelect_test(TestMixin, dPageSelect): pass
class _dDockTabs_test(TestMixin, dDockTabs): pass
+if _USE_FLAT:
+ class _DPageFrame_test(TestMixin, DPageFrame):
+ def initProperties(self):
+ print "in init properties"
+ self.Width = 400
+ self.Height = 175
+ self.TabStyle = random.choice(("Default", "VC8",
"VC71", "Fancy", "Firefox"))
+ self.TabPosition = random.choice(("Top", "Bottom"))
+ self.ShowPageCloseButtons = random.choice(("True",
"False"))
+ self.ShowDropdownTabList = random.choice(("True",
"False"))
+ self.ShowMenuClose = random.choice(("True", "False"))
+ self.ShowMenuOnSingleTab = random.choice(("True",
"False"))
+ self.MenuBackColor = random.choice(dColors.colors)
+ self.InactiveTabTextColor =
random.choice(dColors.colors)
+ self.ActiveTabTextColor = random.choice(dColors.colors)
-
+
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)
+ if _USE_FLAT:
+ test.Test().runTest(_DPageFrame_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]