]>
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())
80 def SetTickFont(self
, font
):
81 """Sets ticker font, updates label"""
82 self
.ticker
.SetFont(font
)
83 self
.fontl
.SetLabel("Font: %s"%(self
.ticker
.GetFont().GetFaceName()))
87 def OnChangeTickFont(self
, evt
):
89 fd
.EnableEffects(False)
90 fd
.SetInitialFont(self
.ticker
.GetFont())
91 dlg
= wx
.FontDialog(wx
.GetTopLevelParent(self
), fd
)
92 if dlg
.ShowModal() == wx
.ID_OK
:
93 data
= dlg
.GetFontData()
94 self
.SetTickFont(data
.GetChosenFont())
97 def SetTickDirection(self
, dir):
98 """Sets tick direction, updates label"""
99 self
.ticker
.SetDirection(dir)
100 self
.dirl
.SetLabel("Direction: %s"%(self
.ticker
.GetDirection()))
103 def OnChangeTickDirection(self
, dir):
104 if self
.ticker
.GetDirection() == "rtl":
105 self
.SetTickDirection("ltr")
107 self
.SetTickDirection("rtl")
110 def OnText(self
, evt
):
111 """Live update of the ticker text"""
112 self
.ticker
.SetText(self
.txt
.GetValue())
114 def ChangeTickFGColor(self
, evt
):
115 self
.ticker
.SetForegroundColour(evt
.GetValue())
117 def ChangeTickBGColor(self
, evt
):
118 self
.ticker
.SetBackgroundColour(evt
.GetValue())
120 def ChangeFPS(self
, evt
):
121 self
.ticker
.SetFPS(evt
.GetPosition())
123 def ChangePPF(self
, evt
):
124 self
.ticker
.SetPPF(evt
.GetPosition())
126 #----------------------------------------------------------------------
128 def runTest(frame
, nb
, log
):
129 win
= TestPanel(nb
, log
)
132 #----------------------------------------------------------------------
136 overview
= wx
.lib
.ticker
.__doc
__
140 if __name__
== '__main__':
143 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])