]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ColourSelect.py
fixed compile error
[wxWidgets.git] / wxPython / demo / ColourSelect.py
1 #----------------------------------------------------------------------------
2 # Name: ColourSelect.py
3 # Purpose: Colour Selection control display testing on panel for wxPython demo
4 #
5 # Author: Lorne White (email: lorne.white@telusplanet.net)
6 #
7 # Version 0.6
8 # Date: Nov 14, 2001
9 # Licence: wxWindows license
10 #
11 # Change Log: Add Label parameter to accommodate updated library code
12 #
13 # Cliff Wells (logiplexsoftware@earthlink.net) 2002/03/11
14 # - added code to demonstrate EVT_COLOURSELECT
15 # - use sizers
16 # - other minor "improvements"
17 #----------------------------------------------------------------------------
18 #
19
20 import wx
21 import wx.lib.colourselect as csel
22
23 #----------------------------------------------------------------------------
24
25 class TestColourSelect(wx.Panel):
26 def __init__(self, parent, log):
27 self.log = log
28 wx.Panel.__init__(self, parent, -1)
29 self.SetAutoLayout(True)
30 mainSizer = wx.BoxSizer(wx.VERTICAL)
31 self.SetSizer(mainSizer)
32 t = wx.StaticText(self, -1,
33 "This example uses a colour selection control based on the wxButton\n"
34 "and wxColourDialog Classes. Click Button to get Colour Values")
35 mainSizer.Add(t, 0, wx.ALL, 3)
36
37 b = wx.Button(self, -1, "Show All Colours")
38 self.Bind(wx.EVT_BUTTON, self.OnShowAll, id=b.GetId())
39 mainSizer.Add(b, 0, wx.ALL, 3)
40
41 buttonSizer = wx.FlexGridSizer(1, 2) # sizer to contain all the example buttons
42
43 # show a button with all default values
44 self.colourDefaults = csel.ColourSelect(self, -1)
45
46 self.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour, id=self.colourDefaults.GetId())
47
48 buttonSizer.AddMany([
49 (wx.StaticText(self, -1, "Default Colour/Size"), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL),
50 (self.colourDefaults, 0, wx.ALL, 3),
51 ])
52
53 # build several examples of buttons with different colours and sizes
54 buttonData = [
55 ("Default Size", (255, 255, 0), wx.DefaultSize, ""),
56 ("Another Size", (255, 0, 255), (60, 20), ""),
57 ("Another Colour", (0, 255, 0), wx.DefaultSize, ""),
58 ("Larger Size", (0, 0, 255), (60, 60), ""),
59 ("With a Label", (127, 0, 255), wx.DefaultSize, "Colour..."),
60 ("Another Colour/Label", (255, 100, 130), (120, -1), "Choose Colour..."),
61 ]
62
63 self.buttonRefs = [] # for saving references to buttons
64
65 # build each button and save a reference to it
66 for name, color, size, label in buttonData:
67 b = csel.ColourSelect(self, -1, label, color, size = size)
68
69 b.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour)
70 self.buttonRefs.append((name, b)) # store reference to button
71
72 buttonSizer.AddMany([
73 (wx.StaticText(self, -1, name), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL),
74 (b, 0, wx.ALL, 3),
75 ])
76
77 mainSizer.Add(buttonSizer, 0, wx.ALL, 3)
78 self.Layout()
79
80 def OnSelectColour(self, event):
81 self.log.WriteText("Colour selected: %s" % str(event.GetValue()))
82
83 def OnShowAll(self, event):
84 # show the state of each button
85 result = []
86 colour = self.colourDefaults.GetColour() # default control value
87 result.append("Default Colour/Size: " + str(colour))
88
89 for name, button in self.buttonRefs:
90 colour = button.GetColour() # get the colour selection button result
91 result.append(name + ": " + str(colour)) # create string list for easy viewing of results
92
93 out_result = ', '.join(result)
94 self.log.WriteText("Colour Results: " + out_result + "\n")
95
96 #---------------------------------------------------------------------------
97
98 def runTest(frame, nb, log):
99 win = TestColourSelect(nb, log)
100 return win
101
102 #---------------------------------------------------------------------------
103
104
105
106
107 overview = """\
108 A coloured button that when clicked allows the user to select a colour from the wxColourDialog.
109 """
110
111
112 if __name__ == '__main__':
113 import sys,os
114 import run
115 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
116