2001-04-02 01:57:32 -04:00
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
# Name: ColourSelect.py
|
|
|
|
# Purpose: Colour Selection control display testing on panel for wxPython demo
|
|
|
|
#
|
|
|
|
# Author: Lorne White (email: lorne.white@telusplanet.net)
|
|
|
|
#
|
2001-11-30 18:33:32 -05:00
|
|
|
# Version 0.6
|
|
|
|
# Date: Nov 14, 2001
|
2001-04-02 01:57:32 -04:00
|
|
|
# Licence: wxWindows license
|
2002-03-13 17:25:18 -05:00
|
|
|
#
|
2001-11-30 18:33:32 -05:00
|
|
|
# Change Log: Add Label parameter to accommodate updated library code
|
2002-03-13 17:25:18 -05:00
|
|
|
#
|
|
|
|
# Cliff Wells (logiplexsoftware@earthlink.net) 2002/03/11
|
|
|
|
# - added code to demonstrate EVT_COLOURSELECT
|
|
|
|
# - use sizers
|
|
|
|
# - other minor "improvements"
|
2001-04-02 01:57:32 -04:00
|
|
|
#----------------------------------------------------------------------------
|
2003-12-08 20:23:28 -05:00
|
|
|
#
|
2001-04-02 01:57:32 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
import wx
|
|
|
|
import wx.lib.colourselect as csel
|
2001-04-02 01:57:32 -04:00
|
|
|
|
2002-03-13 17:25:18 -05:00
|
|
|
#----------------------------------------------------------------------------
|
2001-04-02 01:57:32 -04:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
class TestColourSelect(wx.Panel):
|
2001-04-02 01:57:32 -04:00
|
|
|
def __init__(self, parent, log):
|
|
|
|
self.log = log
|
2003-12-08 20:23:28 -05:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
2003-03-25 01:35:27 -05:00
|
|
|
self.SetAutoLayout(True)
|
2003-12-08 20:23:28 -05:00
|
|
|
mainSizer = wx.BoxSizer(wx.VERTICAL)
|
2002-03-13 17:25:18 -05:00
|
|
|
self.SetSizer(mainSizer)
|
2003-12-08 20:23:28 -05:00
|
|
|
t = wx.StaticText(self, -1,
|
2002-03-13 17:25:18 -05:00
|
|
|
"This example uses a colour selection control based on the wxButton\n"
|
|
|
|
"and wxColourDialog Classes. Click Button to get Colour Values")
|
2003-12-08 20:23:28 -05:00
|
|
|
mainSizer.Add(t, 0, wx.ALL, 3)
|
2002-03-13 17:25:18 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
b = wx.Button(self, -1, "Show All Colours")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnShowAll, id=b.GetId())
|
|
|
|
mainSizer.Add(b, 0, wx.ALL, 3)
|
2002-03-13 17:25:18 -05:00
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
buttonSizer = wx.FlexGridSizer(1, 2) # sizer to contain all the example buttons
|
2002-03-13 17:25:18 -05:00
|
|
|
|
|
|
|
# show a button with all default values
|
2003-12-08 20:23:28 -05:00
|
|
|
self.colourDefaults = csel.ColourSelect(self, -1)
|
|
|
|
|
2003-12-11 14:55:48 -05:00
|
|
|
self.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour, id=self.colourDefaults.GetId())
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2002-03-13 17:25:18 -05:00
|
|
|
buttonSizer.AddMany([
|
2003-12-08 20:23:28 -05:00
|
|
|
(wx.StaticText(self, -1, "Default Colour/Size"), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL),
|
|
|
|
(self.colourDefaults, 0, wx.ALL, 3),
|
2002-03-13 17:25:18 -05:00
|
|
|
])
|
|
|
|
|
|
|
|
# build several examples of buttons with different colours and sizes
|
|
|
|
buttonData = [
|
2003-12-08 20:23:28 -05:00
|
|
|
("Default Size", (255, 255, 0), wx.DefaultSize, ""),
|
2002-03-13 17:25:18 -05:00
|
|
|
("Another Size", (255, 0, 255), (60, 20), ""),
|
2003-12-08 20:23:28 -05:00
|
|
|
("Another Colour", (0, 255, 0), wx.DefaultSize, ""),
|
2002-03-13 17:25:18 -05:00
|
|
|
("Larger Size", (0, 0, 255), (60, 60), ""),
|
2003-12-08 20:23:28 -05:00
|
|
|
("With a Label", (127, 0, 255), wx.DefaultSize, "Colour..."),
|
2002-03-13 17:25:18 -05:00
|
|
|
("Another Colour/Label", (255, 100, 130), (120, -1), "Choose Colour..."),
|
|
|
|
]
|
|
|
|
|
|
|
|
self.buttonRefs = [] # for saving references to buttons
|
|
|
|
|
|
|
|
# build each button and save a reference to it
|
|
|
|
for name, color, size, label in buttonData:
|
2003-12-08 20:23:28 -05:00
|
|
|
b = csel.ColourSelect(self, -1, label, color, size = size)
|
|
|
|
|
|
|
|
b.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour)
|
2002-03-13 17:25:18 -05:00
|
|
|
self.buttonRefs.append((name, b)) # store reference to button
|
2003-12-08 20:23:28 -05:00
|
|
|
|
2002-03-13 17:25:18 -05:00
|
|
|
buttonSizer.AddMany([
|
2003-12-08 20:23:28 -05:00
|
|
|
(wx.StaticText(self, -1, name), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL),
|
|
|
|
(b, 0, wx.ALL, 3),
|
2002-03-13 17:25:18 -05:00
|
|
|
])
|
|
|
|
|
2003-12-08 20:23:28 -05:00
|
|
|
mainSizer.Add(buttonSizer, 0, wx.ALL, 3)
|
2002-03-13 17:25:18 -05:00
|
|
|
self.Layout()
|
|
|
|
|
|
|
|
def OnSelectColour(self, event):
|
|
|
|
self.log.WriteText("Colour selected: %s" % str(event.GetValue()))
|
|
|
|
|
|
|
|
def OnShowAll(self, event):
|
|
|
|
# show the state of each button
|
|
|
|
result = []
|
|
|
|
colour = self.colourDefaults.GetColour() # default control value
|
|
|
|
result.append("Default Colour/Size: " + str(colour))
|
2001-04-02 01:57:32 -04:00
|
|
|
|
2002-03-13 17:25:18 -05:00
|
|
|
for name, button in self.buttonRefs:
|
|
|
|
colour = button.GetColour() # get the colour selection button result
|
|
|
|
result.append(name + ": " + str(colour)) # create string list for easy viewing of results
|
2001-06-15 17:43:26 -04:00
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
out_result = ', '.join(result)
|
2002-03-13 17:25:18 -05:00
|
|
|
self.log.WriteText("Colour Results: " + out_result + "\n")
|
2001-04-02 03:26:54 -04:00
|
|
|
|
2001-04-02 01:57:32 -04:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestColourSelect(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-11-21 02:36:53 -05:00
|
|
|
overview = """\
|
2004-01-22 18:25:09 -05:00
|
|
|
A coloured button that when clicked allows the user to select a colour from the wxColourDialog.
|
2003-11-21 02:36:53 -05:00
|
|
|
"""
|
2001-04-02 01:57:32 -04:00
|
|
|
|
|
|
|
|
2003-11-21 02:36:53 -05:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
2004-03-04 19:06:33 -05:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
2001-04-02 01:57:32 -04:00
|
|
|
|