]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ColourSelect.py
WinCE fixes
[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 from wxPython.wx import *
20 from wxPython.lib.colourselect import *
21
22 #----------------------------------------------------------------------------
23
24 class TestColourSelect(wxPanel):
25 def __init__(self, parent, log):
26 self.log = log
27 wxPanel.__init__(self, parent, -1)
28 self.SetAutoLayout(True)
29 mainSizer = wxBoxSizer(wxVERTICAL)
30 self.SetSizer(mainSizer)
31 t = wxStaticText(self, -1,
32 "This example uses a colour selection control based on the wxButton\n"
33 "and wxColourDialog Classes. Click Button to get Colour Values")
34 mainSizer.Add(t, 0, wxALL, 3)
35
36 b = wxButton(self, -1, "Show All Colours")
37 EVT_BUTTON(self, b.GetId(), self.OnShowAll)
38 mainSizer.Add(b, 0, wxALL, 3)
39
40 buttonSizer = wxFlexGridSizer(1, 2) # sizer to contain all the example buttons
41
42 # show a button with all default values
43 self.colourDefaults = ColourSelect(self, -1)
44 EVT_COLOURSELECT(self.colourDefaults, self.colourDefaults.GetId(), self.OnSelectColour)
45 buttonSizer.AddMany([
46 (wxStaticText(self, -1, "Default Colour/Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL),
47 (self.colourDefaults, 0, wxALL, 3),
48 ])
49
50 # build several examples of buttons with different colours and sizes
51 buttonData = [
52 ("Default Size", (255, 255, 0), wxDefaultSize, ""),
53 ("Another Size", (255, 0, 255), (60, 20), ""),
54 ("Another Colour", (0, 255, 0), wxDefaultSize, ""),
55 ("Larger Size", (0, 0, 255), (60, 60), ""),
56 ("With a Label", (127, 0, 255), wxDefaultSize, "Colour..."),
57 ("Another Colour/Label", (255, 100, 130), (120, -1), "Choose Colour..."),
58 ]
59
60 self.buttonRefs = [] # for saving references to buttons
61
62 # build each button and save a reference to it
63 for name, color, size, label in buttonData:
64 b = ColourSelect(self, -1, label, color, size = size)
65 EVT_COLOURSELECT(b, b.GetId(), self.OnSelectColour)
66 self.buttonRefs.append((name, b)) # store reference to button
67 buttonSizer.AddMany([
68 (wxStaticText(self, -1, name), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL),
69 (b, 0, wxALL, 3),
70 ])
71
72 mainSizer.Add(buttonSizer, 0, wxALL, 3)
73 self.Layout()
74
75 def OnSelectColour(self, event):
76 self.log.WriteText("Colour selected: %s" % str(event.GetValue()))
77
78 def OnShowAll(self, event):
79 # show the state of each button
80 result = []
81 colour = self.colourDefaults.GetColour() # default control value
82 result.append("Default Colour/Size: " + str(colour))
83
84 for name, button in self.buttonRefs:
85 colour = button.GetColour() # get the colour selection button result
86 result.append(name + ": " + str(colour)) # create string list for easy viewing of results
87
88 out_result = ', '.join(result)
89 self.log.WriteText("Colour Results: " + out_result + "\n")
90
91 #---------------------------------------------------------------------------
92
93 def runTest(frame, nb, log):
94 win = TestColourSelect(nb, log)
95 return win
96
97 #---------------------------------------------------------------------------
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 overview = """\
114
115 """