]>
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 #----------------------------------------------------------------------------
21 import wx
.lib
.colourselect
as csel
23 #----------------------------------------------------------------------------
25 class TestColourSelect(wx
.Panel
):
26 def __init__(self
, parent
, log
):
28 wx
.Panel
.__init
__(self
, parent
, -1)
29 self
.SetAutoLayout(True)
30 mainSizer
= wx
.BoxSizer(wx
.VERTICAL
)
31 self
.SetSizer(mainSizer
)
32 t
= wx
.StaticText(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, wx
.ALL
, 3)
37 b
= wx
.Button(self
, -1, "Show All Colours")
38 self
.Bind(wx
.EVT_BUTTON
, self
.OnShowAll
, id=b
.GetId())
39 mainSizer
.Add(b
, 0, wx
.ALL
, 3)
41 buttonSizer
= wx
.FlexGridSizer(1, 2) # sizer to contain all the example buttons
43 # show a button with all default values
44 self
.colourDefaults
= csel
.ColourSelect(self
, -1)
46 self
.Bind(csel
.EVT_COLOURSELECT
, self
.OnSelectColour
, id=self
.colourDefaults
.GetId())
49 (wx
.StaticText(self
, -1, "Default Colour/Size"), 0, wx
.ALIGN_RIGHT | wx
.ALIGN_CENTER_VERTICAL
),
50 (self
.colourDefaults
, 0, wx
.ALL
, 3),
53 # build several examples of buttons with different colours and sizes
55 ("Default Size", (255, 255, 0), wx
.DefaultSize
, ""),
56 ("Another Size", (255, 0, 255), (60, 20), ""),
57 ("Another Colour", (0, 255, 0), wx
.DefaultSize
, ""),
58 ("Larger Size", (0, 0, 255), (60, 60), ""),
59 ("With a Label", (127, 0, 255), wx
.DefaultSize
, "Colour..."),
60 ("Another Colour/Label", (255, 100, 130), (120, -1), "Choose Colour..."),
63 self
.buttonRefs
= [] # for saving references to buttons
65 # build each button and save a reference to it
66 for name
, color
, size
, label
in buttonData
:
67 b
= csel
.ColourSelect(self
, -1, label
, color
, size
= size
)
69 b
.Bind(csel
.EVT_COLOURSELECT
, self
.OnSelectColour
)
70 self
.buttonRefs
.append((name
, b
)) # store reference to button
73 (wx
.StaticText(self
, -1, name
), 0, wx
.ALIGN_RIGHT | wx
.ALIGN_CENTER_VERTICAL
),
77 mainSizer
.Add(buttonSizer
, 0, wx
.ALL
, 3)
80 def OnSelectColour(self
, event
):
81 self
.log
.WriteText("Colour selected: %s" % str(event
.GetValue()))
83 def OnShowAll(self
, event
):
84 # show the state of each button
86 colour
= self
.colourDefaults
.GetColour() # default control value
87 result
.append("Default Colour/Size: " + str(colour
))
89 for name
, button
in self
.buttonRefs
:
90 colour
= button
.GetColour() # get the colour selection button result
91 result
.append(name
+ ": " + str(colour
)) # create string list for easy viewing of results
93 out_result
= ', '.join(result
)
94 self
.log
.WriteText("Colour Results: " + out_result
+ "\n")
96 #---------------------------------------------------------------------------
98 def runTest(frame
, nb
, log
):
99 win
= TestColourSelect(nb
, log
)
102 #---------------------------------------------------------------------------
112 if __name__
== '__main__':
115 run
.main(['', os
.path
.basename(sys
.argv
[0])])