]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Ticker.py
3 from wx
.lib
.ticker
import Ticker
4 import wx
.lib
.colourselect
as csel
#for easy color selection
6 #----------------------------------------------------------------------
8 class TestPanel(wx
.Panel
):
9 def __init__(self
, parent
, log
):
11 wx
.Panel
.__init
__(self
, parent
, -1)
13 self
.ticker
= Ticker(self
)
15 # Controls for ...controlling... the ticker.
16 self
.txt
= wx
.TextCtrl(self
, value
="I am a scrolling ticker!!!!", size
=(200,-1))
17 wx
.CallAfter(self
.txt
.SetInsertionPoint
, 0)
18 txtl
= wx
.StaticText(self
, label
="Ticker text:")
19 fgb
= csel
.ColourSelect(self
, -1, colour
=self
.ticker
.GetForegroundColour())
20 fgl
= wx
.StaticText(self
, label
="Foreground Color:")
21 bgb
= csel
.ColourSelect(self
, -1, colour
=self
.ticker
.GetBackgroundColour())
22 bgl
= wx
.StaticText(self
, label
="Background Color:")
23 fontb
= wx
.Button(self
, label
="Change")
24 self
.fontl
= wx
.StaticText(self
)
25 dirb
= wx
.Button(self
, label
="Switch")
26 self
.dirl
= wx
.StaticText(self
)
27 fpsl
= wx
.StaticText(self
, label
="Frames per Second:")
28 fps
= wx
.Slider(self
, value
=self
.ticker
.GetFPS(), minValue
=1, maxValue
=100,
30 style
=wx
.SL_HORIZONTAL|wx
.SL_AUTOTICKS|wx
.SL_LABELS
)
32 ppfl
= wx
.StaticText(self
, label
="Pixels per frame:")
33 ppf
= wx
.Slider(self
, value
=self
.ticker
.GetPPF(), minValue
=1, maxValue
=10,
35 style
=wx
.SL_HORIZONTAL|wx
.SL_AUTOTICKS|wx
.SL_LABELS
)
38 sz
= wx
.FlexGridSizer(cols
=2, hgap
=4, vgap
=4)
40 sz
.Add(txtl
, flag
=wx
.ALIGN_CENTER_VERTICAL
)
41 sz
.Add(self
.txt
, flag
=wx
.ALIGN_CENTER_VERTICAL
)
43 sz
.Add(fgl
, flag
=wx
.ALIGN_CENTER_VERTICAL
)
44 sz
.Add(fgb
, flag
=wx
.ALIGN_CENTER_VERTICAL
)
46 sz
.Add(bgl
, flag
=wx
.ALIGN_CENTER_VERTICAL
)
47 sz
.Add(bgb
, flag
=wx
.ALIGN_CENTER_VERTICAL
)
49 sz
.Add(self
.fontl
, flag
=wx
.ALIGN_CENTER_VERTICAL
)
50 sz
.Add(fontb
, flag
=wx
.ALIGN_CENTER_VERTICAL
)
52 sz
.Add(self
.dirl
, flag
=wx
.ALIGN_CENTER_VERTICAL
)
53 sz
.Add(dirb
, flag
=wx
.ALIGN_CENTER_VERTICAL
)
55 sz
.Add(fpsl
, flag
=wx
.ALIGN_CENTER_VERTICAL
)
56 sz
.Add(fps
, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALIGN_LEFT
)
58 sz
.Add(ppfl
, flag
=wx
.ALIGN_CENTER_VERTICAL
)
59 sz
.Add(ppf
, flag
=wx
.ALIGN_CENTER_VERTICAL|wx
.ALIGN_LEFT
)
61 sz2
= wx
.BoxSizer(wx
.VERTICAL
)
62 sz2
.Add(self
.ticker
, flag
=wx
.EXPAND|wx
.ALL
, border
=5)
63 sz2
.Add(sz
, flag
=wx
.EXPAND|wx
.ALL
, proportion
=1, border
=25)
65 sz2
.SetSizeHints(self
)
68 self
.Bind(wx
.EVT_BUTTON
, self
.OnChangeTickDirection
, dirb
)
69 self
.Bind(wx
.EVT_BUTTON
, self
.OnChangeTickFont
, fontb
)
70 self
.Bind(wx
.EVT_TEXT
, self
.OnText
, self
.txt
)
71 self
.Bind(csel
.EVT_COLOURSELECT
, self
.ChangeTickFGColor
, fgb
)
72 self
.Bind(csel
.EVT_COLOURSELECT
, self
.ChangeTickBGColor
, bgb
)
73 self
.Bind(wx
.EVT_SCROLL
, self
.ChangeFPS
, fps
)
74 self
.Bind(wx
.EVT_SCROLL
, self
.ChangePPF
, ppf
)
77 self
.SetTickDirection("rtl")
78 self
.SetTickFont(self
.ticker
.GetFont())
79 self
.ticker
.SetText(self
.txt
.GetValue())
82 def SetTickFont(self
, font
):
83 """Sets ticker font, updates label"""
84 self
.ticker
.SetFont(font
)
85 self
.fontl
.SetLabel("Font: %s"%(self
.ticker
.GetFont().GetFaceName()))
89 def OnChangeTickFont(self
, evt
):
91 fd
.EnableEffects(False)
92 fd
.SetInitialFont(self
.ticker
.GetFont())
93 dlg
= wx
.FontDialog(wx
.GetTopLevelParent(self
), fd
)
94 if dlg
.ShowModal() == wx
.ID_OK
:
95 data
= dlg
.GetFontData()
96 self
.SetTickFont(data
.GetChosenFont())
99 def SetTickDirection(self
, dir):
100 """Sets tick direction, updates label"""
101 self
.ticker
.SetDirection(dir)
102 self
.dirl
.SetLabel("Direction: %s"%(self
.ticker
.GetDirection()))
105 def OnChangeTickDirection(self
, dir):
106 if self
.ticker
.GetDirection() == "rtl":
107 self
.SetTickDirection("ltr")
109 self
.SetTickDirection("rtl")
112 def OnText(self
, evt
):
113 """Live update of the ticker text"""
114 self
.ticker
.SetText(self
.txt
.GetValue())
116 def ChangeTickFGColor(self
, evt
):
117 self
.ticker
.SetForegroundColour(evt
.GetValue())
119 def ChangeTickBGColor(self
, evt
):
120 self
.ticker
.SetBackgroundColour(evt
.GetValue())
122 def ChangeFPS(self
, evt
):
123 self
.ticker
.SetFPS(evt
.GetPosition())
125 def ChangePPF(self
, evt
):
126 self
.ticker
.SetPPF(evt
.GetPosition())
129 def ShutdownDemo(self
):
133 #----------------------------------------------------------------------
135 def runTest(frame
, nb
, log
):
136 win
= TestPanel(nb
, log
)
139 #----------------------------------------------------------------------
143 overview
= wx
.lib
.ticker
.__doc
__
147 if __name__
== '__main__':
150 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])