]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Ticker.py
Removed unnecessary files, removed or replaced images that we're not
[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
81
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()))
86 self.Layout()
87
88
89 def OnChangeTickFont(self, evt):
90 fd = wx.FontData()
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())
97
98
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()))
103
104
105 def OnChangeTickDirection(self, dir):
106 if self.ticker.GetDirection() == "rtl":
107 self.SetTickDirection("ltr")
108 else:
109 self.SetTickDirection("rtl")
110
111
112 def OnText(self, evt):
113 """Live update of the ticker text"""
114 self.ticker.SetText(self.txt.GetValue())
115
116 def ChangeTickFGColor(self, evt):
117 self.ticker.SetForegroundColour(evt.GetValue())
118
119 def ChangeTickBGColor(self, evt):
120 self.ticker.SetBackgroundColour(evt.GetValue())
121
122 def ChangeFPS(self, evt):
123 self.ticker.SetFPS(evt.GetPosition())
124
125 def ChangePPF(self, evt):
126 self.ticker.SetPPF(evt.GetPosition())
127
128
129 def ShutdownDemo(self):
130 self.ticker.Stop()
131
132
133 #----------------------------------------------------------------------
134
135 def runTest(frame, nb, log):
136 win = TestPanel(nb, log)
137 return win
138
139 #----------------------------------------------------------------------
140
141
142
143 overview = wx.lib.ticker.__doc__
144
145
146
147 if __name__ == '__main__':
148 import sys,os
149 import run
150 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
151