]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/colourselect.py
cef3f4d445ebc2ef905e54d6dfb75e1ca019d2fe
[wxWidgets.git] / wxPython / wxPython / lib / colourselect.py
1 #----------------------------------------------------------------------------
2 # Name: ColourSelect.py
3 # Purpose: Colour Box Selection Control
4 #
5 # Author: Lorne White, Lorne.White@telusplanet.net
6 #
7 # Created: Sept 4, 2001
8 # Licence: wxWindows license
9 #----------------------------------------------------------------------------
10
11 from wxPython.wx import *
12
13 # creates a colour wxButton with selectable color
14 # button click provides a colour selection box
15 # button colour will change to new colour
16 # GetColour method to get the selected colour
17
18 # Updates:
19 # call back to function if changes made
20
21 class ColourSelect(wxButton):
22 def __init__(self, parent, ID, bcolour=[0, 0, 0], pos=wxPoint(20, 20), size=wxSize(20, 20), style=0, callback=None):
23 wxButton.__init__(self, parent, ID, "", pos, size, style)
24 self.win = parent
25 self.callback = callback
26 EVT_BUTTON(self, ID, self.OnClick)
27 self.SetColourValue(bcolour)
28
29 def __del__(self):
30 if hasattr(self, "set_colour_val"):
31 del self.set_colour_val
32
33 def SetColour(self, bcolour):
34 self.SetBackgroundColour(bcolour)
35
36 def SetColourValue(self, bcolour):
37 self.set_colour_val = wxColour(bcolour[0], bcolour[1], bcolour[2])
38 self.set_colour = bcolour
39
40 self.SetBackgroundColour(self.set_colour_val)
41 self.SetForegroundColour(wxWHITE)
42
43 def SetValue(self, bcolour):
44 self.SetColourValue(bcolour)
45
46 def GetColour(self):
47 return self.set_colour
48
49 def OnChange(self):
50 if self.callback != None:
51 self.callback()
52
53 def OnClick(self, event):
54 data = wxColourData()
55 data.SetChooseFull(true)
56 data.SetColour(self.set_colour_val)
57 dlg = wxColourDialog(self.win, data)
58 if dlg.ShowModal() == wxID_OK:
59 data = dlg.GetColourData()
60 self.set_colour = set = data.GetColour().Get()
61 self.set_colour_val = bcolour = wxColour(set[0],set[1],set[2])
62 self.SetBackgroundColour(bcolour)
63 self.OnChange()
64 dlg.Destroy()
65