]>
Commit | Line | Data |
---|---|---|
49875c53 RD |
1 | |
2 | #---------------------------------------------------------------------------- | |
3 | # Name: ColourSelect.py | |
4 | # Purpose: Colour Selection control display testing on panel for wxPython demo | |
5 | # | |
6 | # Author: Lorne White (email: lorne.white@telusplanet.net) | |
7 | # | |
572c7069 RD |
8 | # Version 0.6 |
9 | # Date: Nov 14, 2001 | |
49875c53 | 10 | # Licence: wxWindows license |
572c7069 RD |
11 | |
12 | # Change Log: Add Label parameter to accommodate updated library code | |
13 | ||
49875c53 RD |
14 | #---------------------------------------------------------------------------- |
15 | ||
16 | from wxPython.wx import * | |
17 | from wxPython.lib.colourselect import * | |
18 | import string | |
19 | ||
20 | #--------------------------------------------------------------------------- | |
21 | ||
22 | class TestColourSelect(wxPanel): | |
23 | def __init__(self, parent, log): | |
24 | self.log = log | |
25 | wxPanel.__init__(self, parent, -1) | |
26 | ||
27 | wxStaticText(self, -1, "This example uses a colour selection control based on the wxButton and wxColourDialog Classes. Click Button to get Colour Values", | |
28 | wxPoint(10, 20), wxSize(400, 60)) | |
29 | ||
30 | self.x_pos = 30 | |
31 | self.y_pos = 100 | |
32 | delta = 40 | |
e189b070 | 33 | |
49875c53 | 34 | mID = NewId() |
e189b070 | 35 | wxButton(self, mID, "Get All Colours", wxPoint(self.x_pos, self.y_pos)) |
49875c53 RD |
36 | EVT_BUTTON(self, mID, self.OnClick) |
37 | self.y_pos = self.y_pos + delta | |
38 | ||
39 | wxStaticText(self, -1, "Default", wxPoint(self.x_pos, self.y_pos), wxSize(-1, -1)) # name | |
d56cebe7 | 40 | self.colour_def = ColourSelect(self, -1, pos=wxPoint(self.x_pos+100, self.y_pos)) # default colour selection control |
49875c53 RD |
41 | |
42 | self.y_pos = self.y_pos + delta | |
43 | colours = [[255, 255, 0], [255, 0, 255], [0, 255, 0], [0, 0, 255]] # list of initial colours for display | |
44 | self.names = names = [ "Default Size", "Another Size", "Another Colour", "Larger"] # display names | |
d56cebe7 | 45 | sizes = [ wxDefaultSize, wxSize(60, 20), wxDefaultSize, wxSize(60, 60)] # button sizes |
49875c53 RD |
46 | self.set_val = [] |
47 | ||
48 | for i in range(len(colours)): | |
49 | wxStaticText(self, -1, names[i], wxPoint(self.x_pos, self.y_pos), wxSize(-1, -1)) # name | |
50 | ||
572c7069 | 51 | val = ColourSelect(self, -1, "", colours[i], wxPoint(self.x_pos+100, self.y_pos), sizes[i]) # colour selection button |
49875c53 RD |
52 | self.set_val.append(val) # store control for reference |
53 | self.y_pos = self.y_pos + delta | |
54 | ||
572c7069 RD |
55 | self.y_pos = self.y_pos - delta |
56 | ColourSelect(self, -1, "Color Label", colours[0], wxPoint(self.x_pos+200, self.y_pos), sizes[0]) # colour selection button | |
57 | ||
d56cebe7 | 58 | |
49875c53 RD |
59 | def OnClick(self, event): |
60 | result = [] | |
61 | colour = self.colour_def.GetColour() # default control value | |
3f0d9059 | 62 | result.append("%s: #%02x%02x%02x" % ("Default", colour[0], colour[1], colour[2])) |
e189b070 | 63 | |
49875c53 RD |
64 | for i in range(len(self.set_val)): |
65 | val = self.set_val[i] | |
66 | colour = val.GetColour() # get the colour selection button result | |
67 | name = self.names[i] | |
3f0d9059 | 68 | result.append("%s: #%02x%02x%02x" % (name, colour[0], colour[1], colour[2])) |
49875c53 | 69 | out_result = string.joinfields(result, ', ') |
3fa82630 | 70 | self.log.WriteText("Colour Results :" + out_result + "\n") |
e189b070 | 71 | |
49875c53 RD |
72 | #--------------------------------------------------------------------------- |
73 | ||
74 | def runTest(frame, nb, log): | |
75 | win = TestColourSelect(nb, log) | |
76 | return win | |
77 | ||
78 | #--------------------------------------------------------------------------- | |
79 | ||
80 | ||
81 | ||
82 | ||
83 | ||
84 | ||
85 | ||
86 | ||
87 | ||
88 | ||
89 | ||
90 | ||
91 | ||
92 | ||
93 | ||
94 | overview = """\ | |
49875c53 | 95 | |
49875c53 | 96 | """ |