]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ColourSelect.py
1 #----------------------------------------------------------------------------
2 # Name: ColourSelect.py
3 # Purpose: Colour Selection control display testing on panel for wxPython demo
5 # Author: Lorne White (email: lorne.white@telusplanet.net)
9 # Licence: wxWindows license
11 # Change Log: Add Label parameter to accommodate updated library code
13 # Cliff Wells (logiplexsoftware@earthlink.net) 2002/03/11
14 # - added code to demonstrate EVT_COLOURSELECT
16 # - other minor "improvements"
17 #----------------------------------------------------------------------------
18 # 11/22/2003 - Jeff Grimmett (grimmtooth@softhome.net)
22 # 11/24/2003 - Jeff Grimmett (grimmtooth@softhome.net)
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.
28 # 12/01/2003 - Jeff Grimmett (grimmtooth@softhome.net)
30 # o colourselect lib converted; demo converted to match.
34 import wx
.lib
.colourselect
as csel
36 #----------------------------------------------------------------------------
38 class TestColourSelect(wx
.Panel
):
39 def __init__(self
, parent
, 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)
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)
54 buttonSizer
= wx
.FlexGridSizer(1, 2) # sizer to contain all the example buttons
56 # show a button with all default values
57 self
.colourDefaults
= csel
.ColourSelect(self
, -1)
59 self
.Bind(csel
.EVT_COLOURSELECT
, self
.OnSelectColour
, id=self
.colourDefaults
.GetId())
62 (wx
.StaticText(self
, -1, "Default Colour/Size"), 0, wx
.ALIGN_RIGHT | wx
.ALIGN_CENTER_VERTICAL
),
63 (self
.colourDefaults
, 0, wx
.ALL
, 3),
66 # build several examples of buttons with different colours and sizes
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..."),
76 self
.buttonRefs
= [] # for saving references to buttons
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
)
82 b
.Bind(csel
.EVT_COLOURSELECT
, self
.OnSelectColour
)
83 self
.buttonRefs
.append((name
, b
)) # store reference to button
86 (wx
.StaticText(self
, -1, name
), 0, wx
.ALIGN_RIGHT | wx
.ALIGN_CENTER_VERTICAL
),
90 mainSizer
.Add(buttonSizer
, 0, wx
.ALL
, 3)
93 def OnSelectColour(self
, event
):
94 self
.log
.WriteText("Colour selected: %s" % str(event
.GetValue()))
96 def OnShowAll(self
, event
):
97 # show the state of each button
99 colour
= self
.colourDefaults
.GetColour() # default control value
100 result
.append("Default Colour/Size: " + str(colour
))
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
106 out_result
= ', '.join(result
)
107 self
.log
.WriteText("Colour Results: " + out_result
+ "\n")
109 #---------------------------------------------------------------------------
111 def runTest(frame
, nb
, log
):
112 win
= TestColourSelect(nb
, log
)
115 #---------------------------------------------------------------------------
125 if __name__
== '__main__':
128 run
.main(['', os
.path
.basename(sys
.argv
[0])])