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 #----------------------------------------------------------------------------
19 from wxPython
.wx
import *
20 from wxPython
.lib
.colourselect
import *
22 #----------------------------------------------------------------------------
24 class TestColourSelect(wxPanel
):
25 def __init__(self
, parent
, log
):
27 wxPanel
.__init
__(self
, parent
, -1)
28 self
.SetAutoLayout(True)
29 mainSizer
= wxBoxSizer(wxVERTICAL
)
30 self
.SetSizer(mainSizer
)
31 t
= wxStaticText(self
, -1,
32 "This example uses a colour selection control based on the wxButton\n"
33 "and wxColourDialog Classes. Click Button to get Colour Values")
34 mainSizer
.Add(t
, 0, wxALL
, 3)
36 b
= wxButton(self
, -1, "Show All Colours")
37 EVT_BUTTON(self
, b
.GetId(), self
.OnShowAll
)
38 mainSizer
.Add(b
, 0, wxALL
, 3)
40 buttonSizer
= wxFlexGridSizer(1, 2) # sizer to contain all the example buttons
42 # show a button with all default values
43 self
.colourDefaults
= ColourSelect(self
, -1)
44 EVT_COLOURSELECT(self
.colourDefaults
, self
.colourDefaults
.GetId(), self
.OnSelectColour
)
46 (wxStaticText(self
, -1, "Default Colour/Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL
),
47 (self
.colourDefaults
, 0, wxALL
, 3),
50 # build several examples of buttons with different colours and sizes
52 ("Default Size", (255, 255, 0), wxDefaultSize
, ""),
53 ("Another Size", (255, 0, 255), (60, 20), ""),
54 ("Another Colour", (0, 255, 0), wxDefaultSize
, ""),
55 ("Larger Size", (0, 0, 255), (60, 60), ""),
56 ("With a Label", (127, 0, 255), wxDefaultSize
, "Colour..."),
57 ("Another Colour/Label", (255, 100, 130), (120, -1), "Choose Colour..."),
60 self
.buttonRefs
= [] # for saving references to buttons
62 # build each button and save a reference to it
63 for name
, color
, size
, label
in buttonData
:
64 b
= ColourSelect(self
, -1, label
, color
, size
= size
)
65 EVT_COLOURSELECT(b
, b
.GetId(), self
.OnSelectColour
)
66 self
.buttonRefs
.append((name
, b
)) # store reference to button
68 (wxStaticText(self
, -1, name
), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL
),
72 mainSizer
.Add(buttonSizer
, 0, wxALL
, 3)
75 def OnSelectColour(self
, event
):
76 self
.log
.WriteText("Colour selected: %s" % str(event
.GetValue()))
78 def OnShowAll(self
, event
):
79 # show the state of each button
81 colour
= self
.colourDefaults
.GetColour() # default control value
82 result
.append("Default Colour/Size: " + str(colour
))
84 for name
, button
in self
.buttonRefs
:
85 colour
= button
.GetColour() # get the colour selection button result
86 result
.append(name
+ ": " + str(colour
)) # create string list for easy viewing of results
88 out_result
= ', '.join(result
)
89 self
.log
.WriteText("Colour Results: " + out_result
+ "\n")
91 #---------------------------------------------------------------------------
93 def runTest(frame
, nb
, log
):
94 win
= TestColourSelect(nb
, log
)
97 #---------------------------------------------------------------------------