]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Ticker.py
REWRITE wxStringBase::append and wxString::Replace.
[wxWidgets.git] / wxPython / demo / Ticker.py
1
2 import wx
3 from wx.lib.ticker import Ticker
4 import wx.lib.colourselect as csel #for easy color selection
5
6 #----------------------------------------------------------------------
7
8 class TestPanel(wx.Panel):
9 def __init__(self, parent, log):
10 self.log = log
11 wx.Panel.__init__(self, parent, -1)
12
13 self.ticker = Ticker(self)
14
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,
29 size=(150,-1),
30 style=wx.SL_HORIZONTAL|wx.SL_AUTOTICKS|wx.SL_LABELS)
31 fps.SetTickFreq(5)
32 ppfl = wx.StaticText(self, label="Pixels per frame:")
33 ppf = wx.Slider(self, value=self.ticker.GetPPF(), minValue=1, maxValue=10,
34 size=(150,-1),
35 style=wx.SL_HORIZONTAL|wx.SL_AUTOTICKS|wx.SL_LABELS)
36
37 # Do layout
38 sz = wx.FlexGridSizer(cols=2, hgap=4, vgap=4)
39
40 sz.Add(txtl, flag=wx.ALIGN_CENTER_VERTICAL)
41 sz.Add(self.txt, flag=wx.ALIGN_CENTER_VERTICAL)
42
43 sz.Add(fgl, flag=wx.ALIGN_CENTER_VERTICAL)
44 sz.Add(fgb, flag=wx.ALIGN_CENTER_VERTICAL)
45
46 sz.Add(bgl, flag=wx.ALIGN_CENTER_VERTICAL)
47 sz.Add(bgb, flag=wx.ALIGN_CENTER_VERTICAL)
48
49 sz.Add(self.fontl, flag=wx.ALIGN_CENTER_VERTICAL)
50 sz.Add(fontb, flag=wx.ALIGN_CENTER_VERTICAL)
51
52 sz.Add(self.dirl, flag=wx.ALIGN_CENTER_VERTICAL)
53 sz.Add(dirb, flag=wx.ALIGN_CENTER_VERTICAL)
54
55 sz.Add(fpsl, flag=wx.ALIGN_CENTER_VERTICAL)
56 sz.Add(fps, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT)
57
58 sz.Add(ppfl, flag=wx.ALIGN_CENTER_VERTICAL)
59 sz.Add(ppf, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT)
60
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)
64 self.SetSizer(sz2)
65 sz2.SetSizeHints(self)
66
67 # Bind events
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)
75
76 # Set defaults
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()))
84 self.Layout()
85
86
87 def OnChangeTickFont(self, evt):
88 fd = wx.FontData()
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())
95
96
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()))
101
102
103 def OnChangeTickDirection(self, dir):
104 if self.ticker.GetDirection() == "rtl":
105 self.SetTickDirection("ltr")
106 else:
107 self.SetTickDirection("rtl")
108
109
110 def OnText(self, evt):
111 """Live update of the ticker text"""
112 self.ticker.SetText(self.txt.GetValue())
113
114 def ChangeTickFGColor(self, evt):
115 self.ticker.SetForegroundColour(evt.GetValue())
116
117 def ChangeTickBGColor(self, evt):
118 self.ticker.SetBackgroundColour(evt.GetValue())
119
120 def ChangeFPS(self, evt):
121 self.ticker.SetFPS(evt.GetPosition())
122
123 def ChangePPF(self, evt):
124 self.ticker.SetPPF(evt.GetPosition())
125
126
127 def ShutdownDemo(self):
128 self.ticker.Stop()
129
130
131 #----------------------------------------------------------------------
132
133 def runTest(frame, nb, log):
134 win = TestPanel(nb, log)
135 return win
136
137 #----------------------------------------------------------------------
138
139
140
141 overview = wx.lib.ticker.__doc__
142
143
144
145 if __name__ == '__main__':
146 import sys,os
147 import run
148 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
149