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 *
23 #----------------------------------------------------------------------------
25 class TestColourSelect(wxPanel
):
26 def __init__(self
, parent
, log
):
28 wxPanel
.__init
__(self
, parent
, -1)
29 self
.SetAutoLayout(true
)
30 mainSizer
= wxBoxSizer(wxVERTICAL
)
31 self
.SetSizer(mainSizer
)
32 t
= wxStaticText(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, wxALL
, 3)
37 b
= wxButton(self
, -1, "Show All Colours")
38 EVT_BUTTON(self
, b
.GetId(), self
.OnShowAll
)
39 mainSizer
.Add(b
, 0, wxALL
, 3)
41 buttonSizer
= wxFlexGridSizer(1, 2) # sizer to contain all the example buttons
43 # show a button with all default values
44 self
.colourDefaults
= ColourSelect(self
, -1)
45 EVT_COLOURSELECT(self
.colourDefaults
, self
.colourDefaults
.GetId(), self
.OnSelectColour
)
47 (wxStaticText(self
, -1, "Default Colour/Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL
),
48 (self
.colourDefaults
, 0, wxALL
, 3),
51 # build several examples of buttons with different colours and sizes
53 ("Default Size", (255, 255, 0), wxDefaultSize
, ""),
54 ("Another Size", (255, 0, 255), (60, 20), ""),
55 ("Another Colour", (0, 255, 0), wxDefaultSize
, ""),
56 ("Larger Size", (0, 0, 255), (60, 60), ""),
57 ("With a Label", (127, 0, 255), wxDefaultSize
, "Colour..."),
58 ("Another Colour/Label", (255, 100, 130), (120, -1), "Choose Colour..."),
61 self
.buttonRefs
= [] # for saving references to buttons
63 # build each button and save a reference to it
64 for name
, color
, size
, label
in buttonData
:
65 b
= ColourSelect(self
, -1, label
, color
, size
= size
)
66 EVT_COLOURSELECT(b
, b
.GetId(), self
.OnSelectColour
)
67 self
.buttonRefs
.append((name
, b
)) # store reference to button
69 (wxStaticText(self
, -1, name
), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL
),
73 mainSizer
.Add(buttonSizer
, 0, wxALL
, 3)
76 def OnSelectColour(self
, event
):
77 self
.log
.WriteText("Colour selected: %s" % str(event
.GetValue()))
79 def OnShowAll(self
, event
):
80 # show the state of each button
82 colour
= self
.colourDefaults
.GetColour() # default control value
83 result
.append("Default Colour/Size: " + str(colour
))
85 for name
, button
in self
.buttonRefs
:
86 colour
= button
.GetColour() # get the colour selection button result
87 result
.append(name
+ ": " + str(colour
)) # create string list for easy viewing of results
89 out_result
= string
.joinfields(result
, ', ')
90 self
.log
.WriteText("Colour Results: " + out_result
+ "\n")
92 #---------------------------------------------------------------------------
94 def runTest(frame
, nb
, log
):
95 win
= TestColourSelect(nb
, log
)
98 #---------------------------------------------------------------------------