1#!/usr/bin/env python
2
3import wx
4from wx.lib.ticker import Ticker
5import wx.lib.colourselect as  csel #for easy color selection
6
7#----------------------------------------------------------------------
8
9class TestPanel(wx.Panel):
10    def __init__(self, parent, log):
11        self.log = log
12        wx.Panel.__init__(self, parent, -1)
13
14        self.ticker = Ticker(self)
15
16        # Controls for ...controlling... the ticker.
17        self.txt = wx.TextCtrl(self, value="I am a scrolling ticker!!!!", size=(200,-1))
18        wx.CallAfter(self.txt.SetInsertionPoint, 0)
19        txtl = wx.StaticText(self, label="Ticker text:")
20        fgb = csel.ColourSelect(self, -1, colour=self.ticker.GetForegroundColour())
21        fgl = wx.StaticText(self, label="Foreground Color:")
22        bgb = csel.ColourSelect(self, -1, colour=self.ticker.GetBackgroundColour())
23        bgl = wx.StaticText(self, label="Background Color:")
24        fontb = wx.Button(self, label="Change")
25        self.fontl = wx.StaticText(self)
26        dirb = wx.Button(self, label="Switch")
27        self.dirl = wx.StaticText(self)
28        fpsl = wx.StaticText(self, label="Frames per Second:")
29        fps = wx.Slider(self, value=self.ticker.GetFPS(), minValue=1, maxValue=100,
30                        size=(150,-1),
31                        style=wx.SL_HORIZONTAL|wx.SL_AUTOTICKS|wx.SL_LABELS)
32        fps.SetTickFreq(5)
33        ppfl = wx.StaticText(self, label="Pixels per frame:")
34        ppf = wx.Slider(self, value=self.ticker.GetPPF(), minValue=1, maxValue=10,
35                        size=(150,-1),
36                        style=wx.SL_HORIZONTAL|wx.SL_AUTOTICKS|wx.SL_LABELS)
37
38        # Do layout
39        sz = wx.FlexGridSizer(cols=2, hgap=4, vgap=4)
40
41        sz.Add(txtl, flag=wx.ALIGN_CENTER_VERTICAL)
42        sz.Add(self.txt, flag=wx.ALIGN_CENTER_VERTICAL)
43
44        sz.Add(fgl, flag=wx.ALIGN_CENTER_VERTICAL)
45        sz.Add(fgb, flag=wx.ALIGN_CENTER_VERTICAL)
46
47        sz.Add(bgl, flag=wx.ALIGN_CENTER_VERTICAL)
48        sz.Add(bgb, flag=wx.ALIGN_CENTER_VERTICAL)
49
50        sz.Add(self.fontl, flag=wx.ALIGN_CENTER_VERTICAL)
51        sz.Add(fontb, flag=wx.ALIGN_CENTER_VERTICAL)
52
53        sz.Add(self.dirl, flag=wx.ALIGN_CENTER_VERTICAL)
54        sz.Add(dirb, flag=wx.ALIGN_CENTER_VERTICAL)
55
56        sz.Add(fpsl, flag=wx.ALIGN_CENTER_VERTICAL)
57        sz.Add(fps, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT)
58
59        sz.Add(ppfl, flag=wx.ALIGN_CENTER_VERTICAL)
60        sz.Add(ppf, flag=wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT)
61
62        sz2 = wx.BoxSizer(wx.VERTICAL)
63        sz2.Add(self.ticker, flag=wx.EXPAND|wx.ALL, border=5)
64        sz2.Add(sz, flag=wx.EXPAND|wx.ALL, proportion=1, border=25)
65        self.SetSizer(sz2)
66        sz2.SetSizeHints(self)
67
68        # Bind events
69        self.Bind(wx.EVT_BUTTON, self.OnChangeTickDirection, dirb)
70        self.Bind(wx.EVT_BUTTON, self.OnChangeTickFont, fontb)
71        self.Bind(wx.EVT_TEXT, self.OnText, self.txt)
72        self.Bind(csel.EVT_COLOURSELECT, self.ChangeTickFGColor, fgb)
73        self.Bind(csel.EVT_COLOURSELECT, self.ChangeTickBGColor, bgb)
74        self.Bind(wx.EVT_SCROLL, self.ChangeFPS, fps)
75        self.Bind(wx.EVT_SCROLL, self.ChangePPF, ppf)
76
77        # Set defaults
78        self.SetTickDirection("rtl")
79        self.SetTickFont(self.ticker.GetFont())
80        self.ticker.SetText(self.txt.GetValue())
81
82
83    def SetTickFont(self, font):
84        """Sets ticker font, updates label"""
85        self.ticker.SetFont(font)
86        self.fontl.SetLabel("Font: %s"%(self.ticker.GetFont().GetFaceName()))
87        self.Layout()
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    def SetTickDirection(self, dir):
99        """Sets tick direction, updates label"""
100        self.ticker.SetDirection(dir)
101        self.dirl.SetLabel("Direction: %s"%(self.ticker.GetDirection()))
102
103    def OnChangeTickDirection(self, dir):
104        if self.ticker.GetDirection() == "rtl":
105            self.SetTickDirection("ltr")
106        else:
107            self.SetTickDirection("rtl")
108
109    def OnText(self, evt):
110        """Live update of the ticker text"""
111        self.ticker.SetText(self.txt.GetValue())
112
113    def ChangeTickFGColor(self, evt):
114        self.ticker.SetForegroundColour(evt.GetValue())
115
116    def ChangeTickBGColor(self, evt):
117        self.ticker.SetBackgroundColour(evt.GetValue())
118
119    def ChangeFPS(self, evt):
120        self.ticker.SetFPS(evt.GetPosition())
121
122    def ChangePPF(self, evt):
123        self.ticker.SetPPF(evt.GetPosition())
124
125    def ShutdownDemo(self):
126        self.ticker.Stop()
127
128
129#----------------------------------------------------------------------
130
131def runTest(frame, nb, log):
132    win = TestPanel(nb, log)
133    return win
134
135#----------------------------------------------------------------------
136
137
138
139overview = wx.lib.ticker.__doc__
140
141
142
143if __name__ == '__main__':
144    import sys,os
145    import run
146    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
147
148