1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 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 = """<html><body>
<h2><center>Simplebook</center></h2>
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.
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|