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