]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ColourSelect.py
New wxDesigner-less version of the MimeTypesManager demo
[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 # 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 #
32
33 import wx
34 import wx.lib.colourselect as csel
35
36 #----------------------------------------------------------------------------
37
38 class TestColourSelect(wx.Panel):
39 def __init__(self, parent, log):
40 self.log = log
41 wx.Panel.__init__(self, parent, -1)
42 self.SetAutoLayout(True)
43 mainSizer = wx.BoxSizer(wx.VERTICAL)
44 self.SetSizer(mainSizer)
45 t = wx.StaticText(self, -1,
46 "This example uses a colour selection control based on the wxButton\n"
47 "and wxColourDialog Classes. Click Button to get Colour Values")
48 mainSizer.Add(t, 0, wx.ALL, 3)
49
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)
53
54 buttonSizer = wx.FlexGridSizer(1, 2) # sizer to contain all the example buttons
55
56 # show a button with all default values
57 self.colourDefaults = csel.ColourSelect(self, -1)
58
59 self.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour, id=self.colourDefaults.GetId())
60
61 buttonSizer.AddMany([
62 (wx.StaticText(self, -1, "Default Colour/Size"), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL),
63 (self.colourDefaults, 0, wx.ALL, 3),
64 ])
65
66 # build several examples of buttons with different colours and sizes
67 buttonData = [
68 ("Default Size", (255, 255, 0), wx.DefaultSize, ""),
69 ("Another Size", (255, 0, 255), (60, 20), ""),
70 ("Another Colour", (0, 255, 0), wx.DefaultSize, ""),
71 ("Larger Size", (0, 0, 255), (60, 60), ""),
72 ("With a Label", (127, 0, 255), wx.DefaultSize, "Colour..."),
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:
80 b = csel.ColourSelect(self, -1, label, color, size = size)
81
82 b.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour)
83 self.buttonRefs.append((name, b)) # store reference to button
84
85 buttonSizer.AddMany([
86 (wx.StaticText(self, -1, name), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL),
87 (b, 0, wx.ALL, 3),
88 ])
89
90 mainSizer.Add(buttonSizer, 0, wx.ALL, 3)
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))
101
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
105
106 out_result = ', '.join(result)
107 self.log.WriteText("Colour Results: " + out_result + "\n")
108
109 #---------------------------------------------------------------------------
110
111 def runTest(frame, nb, log):
112 win = TestColourSelect(nb, log)
113 return win
114
115 #---------------------------------------------------------------------------
116
117
118
119
120 overview = """\
121
122 """
123
124
125 if __name__ == '__main__':
126 import sys,os
127 import run
128 run.main(['', os.path.basename(sys.argv[0])])
129