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