]>
Commit | Line | Data |
---|---|---|
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 | 17 | #---------------------------------------------------------------------------- |
8fa876ca RD |
18 | # 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
19 | # | |
20 | # o Updated for V2.5 | |
21 | # | |
22 | # 11/24/2003 - Jeff Grimmett (grimmtooth@softhome.net) | |
23 | # | |
24 | # o Added Bind() handlers to what events can handle it. However, the | |
25 | # colourselect library must be converted before its events can be | |
26 | # bound using the Bind() method. | |
27 | # | |
28 | # 12/01/2003 - Jeff Grimmett (grimmtooth@softhome.net) | |
29 | # | |
30 | # o colourselect lib converted; demo converted to match. | |
31 | # | |
49875c53 | 32 | |
8fa876ca RD |
33 | import wx |
34 | import wx.lib.colourselect as csel | |
49875c53 | 35 | |
caa74ba3 | 36 | #---------------------------------------------------------------------------- |
49875c53 | 37 | |
8fa876ca | 38 | class TestColourSelect(wx.Panel): |
49875c53 RD |
39 | def __init__(self, parent, log): |
40 | self.log = log | |
8fa876ca | 41 | wx.Panel.__init__(self, parent, -1) |
1e4a197e | 42 | self.SetAutoLayout(True) |
8fa876ca | 43 | mainSizer = wx.BoxSizer(wx.VERTICAL) |
caa74ba3 | 44 | self.SetSizer(mainSizer) |
8fa876ca | 45 | t = wx.StaticText(self, -1, |
caa74ba3 RD |
46 | "This example uses a colour selection control based on the wxButton\n" |
47 | "and wxColourDialog Classes. Click Button to get Colour Values") | |
8fa876ca | 48 | mainSizer.Add(t, 0, wx.ALL, 3) |
caa74ba3 | 49 | |
8fa876ca RD |
50 | b = wx.Button(self, -1, "Show All Colours") |
51 | self.Bind(wx.EVT_BUTTON, self.OnShowAll, id=b.GetId()) | |
52 | mainSizer.Add(b, 0, wx.ALL, 3) | |
caa74ba3 | 53 | |
8fa876ca | 54 | buttonSizer = wx.FlexGridSizer(1, 2) # sizer to contain all the example buttons |
caa74ba3 RD |
55 | |
56 | # show a button with all default values | |
8fa876ca RD |
57 | self.colourDefaults = csel.ColourSelect(self, -1) |
58 | ||
59 | self.colourDefaults.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour, self.colourDefaults.GetId()) | |
60 | ||
caa74ba3 | 61 | buttonSizer.AddMany([ |
8fa876ca RD |
62 | (wx.StaticText(self, -1, "Default Colour/Size"), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL), |
63 | (self.colourDefaults, 0, wx.ALL, 3), | |
caa74ba3 RD |
64 | ]) |
65 | ||
66 | # build several examples of buttons with different colours and sizes | |
67 | buttonData = [ | |
8fa876ca | 68 | ("Default Size", (255, 255, 0), wx.DefaultSize, ""), |
caa74ba3 | 69 | ("Another Size", (255, 0, 255), (60, 20), ""), |
8fa876ca | 70 | ("Another Colour", (0, 255, 0), wx.DefaultSize, ""), |
caa74ba3 | 71 | ("Larger Size", (0, 0, 255), (60, 60), ""), |
8fa876ca | 72 | ("With a Label", (127, 0, 255), wx.DefaultSize, "Colour..."), |
caa74ba3 RD |
73 | ("Another Colour/Label", (255, 100, 130), (120, -1), "Choose Colour..."), |
74 | ] | |
75 | ||
76 | self.buttonRefs = [] # for saving references to buttons | |
77 | ||
78 | # build each button and save a reference to it | |
79 | for name, color, size, label in buttonData: | |
8fa876ca RD |
80 | b = csel.ColourSelect(self, -1, label, color, size = size) |
81 | ||
82 | b.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour) | |
caa74ba3 | 83 | self.buttonRefs.append((name, b)) # store reference to button |
8fa876ca | 84 | |
caa74ba3 | 85 | buttonSizer.AddMany([ |
8fa876ca RD |
86 | (wx.StaticText(self, -1, name), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL), |
87 | (b, 0, wx.ALL, 3), | |
caa74ba3 RD |
88 | ]) |
89 | ||
8fa876ca | 90 | mainSizer.Add(buttonSizer, 0, wx.ALL, 3) |
caa74ba3 RD |
91 | self.Layout() |
92 | ||
93 | def OnSelectColour(self, event): | |
94 | self.log.WriteText("Colour selected: %s" % str(event.GetValue())) | |
95 | ||
96 | def OnShowAll(self, event): | |
97 | # show the state of each button | |
98 | result = [] | |
99 | colour = self.colourDefaults.GetColour() # default control value | |
100 | result.append("Default Colour/Size: " + str(colour)) | |
49875c53 | 101 | |
caa74ba3 RD |
102 | for name, button in self.buttonRefs: |
103 | colour = button.GetColour() # get the colour selection button result | |
104 | result.append(name + ": " + str(colour)) # create string list for easy viewing of results | |
d56cebe7 | 105 | |
1e4a197e | 106 | out_result = ', '.join(result) |
caa74ba3 | 107 | self.log.WriteText("Colour Results: " + out_result + "\n") |
e189b070 | 108 | |
49875c53 RD |
109 | #--------------------------------------------------------------------------- |
110 | ||
111 | def runTest(frame, nb, log): | |
112 | win = TestColourSelect(nb, log) | |
113 | return win | |
114 | ||
115 | #--------------------------------------------------------------------------- | |
116 | ||
117 | ||
118 | ||
119 | ||
fbd5dd1d | 120 | overview = """\ |
49875c53 | 121 | |
fbd5dd1d | 122 | """ |
49875c53 RD |
123 | |
124 | ||
fbd5dd1d RD |
125 | if __name__ == '__main__': |
126 | import sys,os | |
127 | import run | |
128 | run.main(['', os.path.basename(sys.argv[0])]) | |
49875c53 | 129 |