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