]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/ColourSelect.py
Stop the timer when the sample is destroyed
[wxWidgets.git] / wxPython / demo / ColourSelect.py
CommitLineData
49875c53
RD
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#
572c7069
RD
7# Version 0.6
8# Date: Nov 14, 2001
49875c53 9# Licence: wxWindows license
caa74ba3 10#
572c7069 11# Change Log: Add Label parameter to accommodate updated library code
caa74ba3
RD
12#
13# Cliff Wells (logiplexsoftware@earthlink.net) 2002/03/11
14# - added code to demonstrate EVT_COLOURSELECT
15# - use sizers
16# - other minor "improvements"
49875c53 17#----------------------------------------------------------------------------
8fa876ca 18#
49875c53 19
8fa876ca
RD
20import wx
21import wx.lib.colourselect as csel
49875c53 22
caa74ba3 23#----------------------------------------------------------------------------
49875c53 24
8fa876ca 25class TestColourSelect(wx.Panel):
49875c53
RD
26 def __init__(self, parent, log):
27 self.log = log
8fa876ca 28 wx.Panel.__init__(self, parent, -1)
1e4a197e 29 self.SetAutoLayout(True)
8fa876ca 30 mainSizer = wx.BoxSizer(wx.VERTICAL)
caa74ba3 31 self.SetSizer(mainSizer)
8fa876ca 32 t = wx.StaticText(self, -1,
caa74ba3
RD
33 "This example uses a colour selection control based on the wxButton\n"
34 "and wxColourDialog Classes. Click Button to get Colour Values")
8fa876ca 35 mainSizer.Add(t, 0, wx.ALL, 3)
caa74ba3 36
8fa876ca
RD
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)
caa74ba3 40
8fa876ca 41 buttonSizer = wx.FlexGridSizer(1, 2) # sizer to contain all the example buttons
caa74ba3
RD
42
43 # show a button with all default values
8fa876ca
RD
44 self.colourDefaults = csel.ColourSelect(self, -1)
45
372bde9b 46 self.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour, id=self.colourDefaults.GetId())
8fa876ca 47
caa74ba3 48 buttonSizer.AddMany([
8fa876ca
RD
49 (wx.StaticText(self, -1, "Default Colour/Size"), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL),
50 (self.colourDefaults, 0, wx.ALL, 3),
caa74ba3
RD
51 ])
52
53 # build several examples of buttons with different colours and sizes
54 buttonData = [
8fa876ca 55 ("Default Size", (255, 255, 0), wx.DefaultSize, ""),
caa74ba3 56 ("Another Size", (255, 0, 255), (60, 20), ""),
8fa876ca 57 ("Another Colour", (0, 255, 0), wx.DefaultSize, ""),
caa74ba3 58 ("Larger Size", (0, 0, 255), (60, 60), ""),
8fa876ca 59 ("With a Label", (127, 0, 255), wx.DefaultSize, "Colour..."),
caa74ba3
RD
60 ("Another Colour/Label", (255, 100, 130), (120, -1), "Choose Colour..."),
61 ]
62
63 self.buttonRefs = [] # for saving references to buttons
64
65 # build each button and save a reference to it
66 for name, color, size, label in buttonData:
8fa876ca
RD
67 b = csel.ColourSelect(self, -1, label, color, size = size)
68
69 b.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour)
caa74ba3 70 self.buttonRefs.append((name, b)) # store reference to button
8fa876ca 71
caa74ba3 72 buttonSizer.AddMany([
8fa876ca
RD
73 (wx.StaticText(self, -1, name), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL),
74 (b, 0, wx.ALL, 3),
caa74ba3
RD
75 ])
76
8fa876ca 77 mainSizer.Add(buttonSizer, 0, wx.ALL, 3)
caa74ba3
RD
78 self.Layout()
79
80 def OnSelectColour(self, event):
81 self.log.WriteText("Colour selected: %s" % str(event.GetValue()))
82
83 def OnShowAll(self, event):
84 # show the state of each button
85 result = []
86 colour = self.colourDefaults.GetColour() # default control value
87 result.append("Default Colour/Size: " + str(colour))
49875c53 88
caa74ba3
RD
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
d56cebe7 92
1e4a197e 93 out_result = ', '.join(result)
caa74ba3 94 self.log.WriteText("Colour Results: " + out_result + "\n")
e189b070 95
49875c53
RD
96#---------------------------------------------------------------------------
97
98def runTest(frame, nb, log):
99 win = TestColourSelect(nb, log)
100 return win
101
102#---------------------------------------------------------------------------
103
104
105
106
fbd5dd1d 107overview = """\
5c75d209 108A coloured button that when clicked allows the user to select a colour from the wxColourDialog.
fbd5dd1d 109"""
49875c53
RD
110
111
fbd5dd1d
RD
112if __name__ == '__main__':
113 import sys,os
114 import run
8eca4fef 115 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
49875c53 116