]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ColourSelect.py
Removed AlignIn after further thought
[wxWidgets.git] / wxPython / demo / ColourSelect.py
CommitLineData
49875c53
RD
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#
572c7069
RD
7# Version 0.6
8# Date: Nov 14, 2001
49875c53 9# Licence: wxWindows license
caa74ba3 10#
572c7069 11# Change Log: Add Label parameter to accommodate updated library code
caa74ba3
RD
12#
13# Cliff Wells (logiplexsoftware@earthlink.net) 2002/03/11
14# - added code to demonstrate EVT_COLOURSELECT
15# - use sizers
16# - other minor "improvements"
49875c53
RD
17#----------------------------------------------------------------------------
18
19from wxPython.wx import *
20from wxPython.lib.colourselect import *
49875c53 21
caa74ba3 22#----------------------------------------------------------------------------
49875c53
RD
23
24class TestColourSelect(wxPanel):
25 def __init__(self, parent, log):
26 self.log = log
27 wxPanel.__init__(self, parent, -1)
1e4a197e 28 self.SetAutoLayout(True)
caa74ba3
RD
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))
49875c53 83
caa74ba3
RD
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
d56cebe7 87
1e4a197e 88 out_result = ', '.join(result)
caa74ba3 89 self.log.WriteText("Colour Results: " + out_result + "\n")
e189b070 90
49875c53
RD
91#---------------------------------------------------------------------------
92
93def 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
113overview = """\
49875c53 114
49875c53 115"""