]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/colourselect.py
17b86199f7dfd336053e14cfb78db0d12e6da876
[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: Feb 25, 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 class ColourSelect:
20 def __init__(self, parent, position = wxPoint(20, 20), bcolour = [0, 0, 0], size = wxSize(20, 20)):
21 self.win = parent
22 if size is None:
23 size = wxSize(20, 20)
24
25 mID = NewId()
26 self.b = b = wxButton(parent, mID, "", position, size)
27 EVT_BUTTON(parent, mID, self.OnClick)
28
29 self.set_colour_val = set_colour = wxColor(bcolour[0], bcolour[1], bcolour[2])
30 b.SetBackgroundColour(set_colour)
31 b.SetForegroundColour(wxWHITE)
32 self.set_colour = bcolour
33
34 def SetColour(self, bcolour):
35 self.b.SetBackgroundColour(bcolour)
36
37 def GetColour(self):
38 return self.set_colour
39
40 def OnClick(self, event):
41 data = wxColourData()
42 data.SetChooseFull(true)
43 data.SetColour(self.set_colour_val)
44 dlg = wxColourDialog(self.win, data)
45 if dlg.ShowModal() == wxID_OK:
46 data = dlg.GetColourData()
47 self.set_colour = set = data.GetColour().Get()
48 self.set_colour_val = bcolour = wxColour(set[0],set[1],set[2])
49 self.b.SetBackgroundColour(bcolour)
50 dlg.Destroy()