From b55cfa073a6fc9bfb44f9d09942701c51f481fe1 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 5 Sep 2017 21:32:29 -0700 Subject: [PATCH] Add wx.Simplbook --- CHANGES.rst | 2 + demo/Simplebook.py | 202 +++++++++++++++++++++++++++++++ demo/demodata.py | 2 + docs/sphinx/itemToModuleMap.json | 1 + etg/_core.py | 1 + etg/simplebook.py | 51 ++++++++ unittests/test_simplebook.py | 27 +++++ 7 files changed, 286 insertions(+) create mode 100644 demo/Simplebook.py create mode 100644 etg/simplebook.py create mode 100644 unittests/test_simplebook.py diff --git a/CHANGES.rst b/CHANGES.rst index d8b58c60..680e055a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -68,6 +68,8 @@ Changes in this release include the following: * Fix for calls to wx.Notebook.HitTest calling the wrong instance (base class version) of the method. (#499) +* Add wx.Simplebook class. + diff --git a/demo/Simplebook.py b/demo/Simplebook.py new file mode 100644 index 00000000..1b867b77 --- /dev/null +++ b/demo/Simplebook.py @@ -0,0 +1,202 @@ +#!/usr/bin/env python + +import wx + +#---------------------------------------------------------------------- + +class TestPage(wx.Panel): + def __init__(self, parent, onNextPage, colour=None, title=None, text=None, extra=None): + wx.Panel.__init__(self, parent) + + vbox = wx.BoxSizer(wx.VERTICAL) + + if colour: + self.SetBackgroundColour(colour) + + if title: + st = wx.StaticText(self, label=title) + f = st.GetFont() + f.SetPointSize(f.GetPointSize()+6) + f.SetWeight(wx.FONTWEIGHT_BOLD) + st.SetFont(f) + vbox.Add(st, 0, wx.BOTTOM, 10) + + if text: + st = wx.StaticText(self, label=text) + vbox.Add(st, 0, wx.BOTTOM, 10) + + if extra: + extra(self, vbox) + + vbox.AddStretchSpacer() + + btn = wx.Button(self, label="Next Page") + vbox.Add(btn, 0, wx.ALIGN_RIGHT) + self.Bind(wx.EVT_BUTTON, onNextPage, btn) + + outer_sizer = wx.BoxSizer() + outer_sizer.Add(vbox, 1, wx.EXPAND|wx.ALL, 15) + self.SetSizer(outer_sizer) + + + + + +class TestSimplebook(wx.Simplebook): + def __init__(self, parent): + wx.Simplebook.__init__(self, parent) + + self.showEffect = wx.SHOW_EFFECT_NONE + self.hideEffect = wx.SHOW_EFFECT_NONE + self.showTimeout = 0 + self.hideTimeout = 0 + + self.DoSetEffects() + + page = TestPage(self, self.OnNextPage, + 'sky blue', 'Page 1 of 4', text="""\ +A wx.Simplebook is a notebook-like control that has no tabs or any other way +for the user to be able to select which page is to be shown. Page selection is +totally controlled by the application. For this example we are providing a +button to switch to the next page in the stack.""", + extra=self.MakeOptionsControls + ) + self.AddPage(page, '') + + page = TestPage(self, self.OnNextPage, 'pink', 'Page 2 of 4', + extra=self.MakeBackHomeButton) + self.AddPage(page, '') + + page = TestPage(self, self.OnNextPage, 'medium aquamarine', 'Page 3 of 4', + extra=self.MakeBackHomeButton) + self.AddPage(page, '') + + page = TestPage(self, self.OnNextPage, 'orchid', 'Page 4 of 4', + 'Clicking "Next Page" will cycle back to the first page.', + extra=self.MakeBackHomeButton) + self.AddPage(page, '') + + + def MakeOptionsControls(self, panel, vbox): + fgs = wx.FlexGridSizer(cols=2, hgap=5, vgap=5) + + effects = [ 'wx.SHOW_EFFECT_NONE', + 'wx.SHOW_EFFECT_ROLL_TO_LEFT', + 'wx.SHOW_EFFECT_ROLL_TO_RIGHT', + 'wx.SHOW_EFFECT_ROLL_TO_TOP ', + 'wx.SHOW_EFFECT_ROLL_TO_BOTTOM', + 'wx.SHOW_EFFECT_SLIDE_TO_LEFT', + 'wx.SHOW_EFFECT_SLIDE_TO_RIGHT', + 'wx.SHOW_EFFECT_SLIDE_TO_TOP', + 'wx.SHOW_EFFECT_SLIDE_TO_BOTTOM', + 'wx.SHOW_EFFECT_BLEND', + 'wx.SHOW_EFFECT_EXPAND', + ] + + showEffectChoice = wx.Choice(panel, choices=effects) + showTimeoutSpin = wx.SpinCtrl(panel, initial=0, max=1000) + hideEffectChoice = wx.Choice(panel, choices=effects) + hideTimeoutSpin = wx.SpinCtrl(panel, initial=0, max=1000) + + fgs.Add(wx.StaticText(panel, -1, "Show Effect:")) + fgs.Add(showEffectChoice) + fgs.Add(wx.StaticText(panel, -1, "Show Timeout (ms):")) + fgs.Add(showTimeoutSpin) + + fgs.AddSpacer(10) + fgs.AddSpacer(10) + + fgs.Add(wx.StaticText(panel, -1, "Hide Effect:")) + fgs.Add(hideEffectChoice) + fgs.Add(wx.StaticText(panel, -1, "Hide Timeout (ms):")) + fgs.Add(hideTimeoutSpin) + + vbox.Add(fgs, 0, wx.ALL|wx.ALIGN_CENTER, 10) + + self.Bind(wx.EVT_CHOICE, self.OnShowEffectChoice, showEffectChoice) + self.Bind(wx.EVT_CHOICE, self.OnHideEffectChoice, hideEffectChoice) + self.Bind(wx.EVT_SPINCTRL, self.OnShowTimeoutSpin, showTimeoutSpin) + self.Bind(wx.EVT_SPINCTRL, self.OnHideTimeoutSpin, hideTimeoutSpin) + + + def MakeBackHomeButton(self, panel, vbox): + btn = wx.Button(panel, -1, 'Back to page 1') + self.Bind(wx.EVT_BUTTON, self.OnBackHome, btn) + vbox.AddSpacer(75) + vbox.Add(btn) + + + def OnNextPage(self, evt): + current = self.GetSelection() + current += 1 + if current >= self.GetPageCount(): + current = 0 + self.ChangeSelection(current) + + + def OnBackHome(self, evt): + self.ChangeSelection(0) + + + def OnShowEffectChoice(self, evt): + self.showEffect = eval(evt.GetString()) + self.DoSetEffects() + + + def OnHideEffectChoice(self, evt): + self.hideEffect = eval(evt.GetString()) + self.DoSetEffects() + + + def OnShowTimeoutSpin(self, evt): + self.showTimeout = evt.GetEventObject().GetValue() + self.DoSetEffects() + + def OnHideTimeoutSpin(self, evt): + self.hideTimeout = evt.GetEventObject().GetValue() + self.DoSetEffects() + + + def DoSetEffects(self): + self.SetEffects(self.showEffect, self.hideEffect) + self.SetEffectsTimeouts(self.showTimeout, self.hideTimeout) + + + +#---------------------------------------------------------------------- + +class TestPanel(wx.Panel): + def __init__(self, parent, log): + self.log = log + wx.Panel.__init__(self, parent, -1) + + book = TestSimplebook(self) + self.Sizer = wx.BoxSizer() + self.Sizer.Add(book, 1, wx.EXPAND) + + +def runTest(frame, nb, log): + win = TestPanel(nb, log) + return win + +#---------------------------------------------------------------------- + + + +overview = """ +

Simplebook

+ +A wx.Simplebook is a notebook-like control that has no tabs or +any other way for the user to be able to select which page is to +be shown. Page selection is totally controlled by the application. + + +""" + + + +if __name__ == '__main__': + import sys,os + import run + run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) + diff --git a/demo/demodata.py b/demo/demodata.py index 810342e9..fff20122 100644 --- a/demo/demodata.py +++ b/demo/demodata.py @@ -45,6 +45,7 @@ _treeList = [ 'ToolTip', 'TimePickerCtrl', 'BannerWindow', + 'Simplebook', ]), # managed windows == things with a (optional) caption you can close @@ -136,6 +137,7 @@ _treeList = [ 'FlatNotebook', 'Listbook', 'Notebook', + 'Simplebook', 'Toolbook', 'Treebook', ]), diff --git a/docs/sphinx/itemToModuleMap.json b/docs/sphinx/itemToModuleMap.json index 3bbb310c..f5c0d01f 100644 --- a/docs/sphinx/itemToModuleMap.json +++ b/docs/sphinx/itemToModuleMap.json @@ -5515,6 +5515,7 @@ "SimpleHelpProvider":"wx.", "SimpleHtmlListBox":"wx.html.", "SimpleHtmlListBoxNameStr":"wx.html.", +"Simplebook":"wx.", "SingleChoiceDialog":"wx.", "SingleInstanceChecker":"wx.", "Size":"wx.", diff --git a/etg/_core.py b/etg/_core.py index df888d61..d06ee37a 100644 --- a/etg/_core.py +++ b/etg/_core.py @@ -178,6 +178,7 @@ INCLUDES = [ # base and core stuff 'listbook', 'toolbook', 'treebook', + 'simplebook', 'vlbox', # toplevel and dialogs diff --git a/etg/simplebook.py b/etg/simplebook.py new file mode 100644 index 00000000..aed5256c --- /dev/null +++ b/etg/simplebook.py @@ -0,0 +1,51 @@ +#--------------------------------------------------------------------------- +# Name: etg/simplebook.py +# Author: Robin Dunn +# +# Created: 05-Sep-2017 +# Copyright: (c) 2017 by Total Control Software +# License: wxWindows License +#--------------------------------------------------------------------------- + +import etgtools +import etgtools.tweaker_tools as tools + +PACKAGE = "wx" +MODULE = "_core" +NAME = "simplebook" # Base name of the file to generate to for this script +DOCSTRING = "" + +# The classes and/or the basename of the Doxygen XML files to be processed by +# this script. +ITEMS = [ 'wxSimplebook', + + ] + +#--------------------------------------------------------------------------- + +def run(): + # Parse the XML file(s) building a collection of Extractor objects + module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING) + etgtools.parseDoxyXML(module, ITEMS) + + #----------------------------------------------------------------- + # Tweak the parsed meta objects in the module object as needed for + # customizing the generated code and docstrings. + + module.addHeaderCode('#include ') + + c = module.find('wxSimplebook') + assert isinstance(c, etgtools.ClassDef) + tools.fixWindowClass(c) + tools.fixBookctrlClass(c) + + + #----------------------------------------------------------------- + tools.doCommonTweaks(module) + tools.runGenerators(module) + + +#--------------------------------------------------------------------------- +if __name__ == '__main__': + run() + diff --git a/unittests/test_simplebook.py b/unittests/test_simplebook.py new file mode 100644 index 00000000..3d00239d --- /dev/null +++ b/unittests/test_simplebook.py @@ -0,0 +1,27 @@ +import unittest +from unittests import wtc +import wx + +#--------------------------------------------------------------------------- + +class simplebook_Tests(wtc.WidgetTestCase): + + def test_simplebook01(self): + nb = wx.Simplebook(self.frame) + + def test_simplebook02(self): + nb = wx.Simplebook() + nb.Create(self.frame) + + def test_simplebook03(self): + nb = wx.Simplebook(self.frame) + p1 = wx.Panel(nb) + nb.AddPage(p1, "") + p2 = wx.Panel(nb) + nb.AddPage(p2, "") + nb.ChangeSelection(0) + +#--------------------------------------------------------------------------- + +if __name__ == '__main__': + unittest.main()