]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/colourselect.py
c1140a6d71759c081bb2627a691fab3445c41be3
2 #----------------------------------------------------------------------------
3 # Name: ColourSelect.py
4 # Purpose: Colour Box Selection Control
6 # Author: Lorne White, Lorne.White@telusplanet.net
8 # Created: Sept 4, 2001
9 # Licence: wxWindows license
10 #----------------------------------------------------------------------------
12 from wxPython
.wx
import *
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
20 # call back to function if changes made
22 class ColourSelect(wxButton
):
23 def __init__(self
, parent
, position
= wxPoint(20, 20), bcolour
= [0, 0, 0], size
= wxSize(20, 20), callback
= None):
25 self
.callback
= callback
28 self
.b
= b
= wxButton(parent
, mID
, "", position
, size
)
29 EVT_BUTTON(parent
, mID
, self
.OnClick
)
31 self
.SetColourValue(bcolour
)
33 def SetColour(self
, bcolour
):
34 self
.b
.SetBackgroundColour(bcolour
)
36 def SetColourValue(self
, bcolour
):
37 self
.set_colour_val
= wxColor(bcolour
[0], bcolour
[1], bcolour
[2])
38 self
.set_colour
= bcolour
40 self
.b
.SetBackgroundColour(self
.set_colour_val
)
41 self
.b
.SetForegroundColour(wxWHITE
)
43 def SetValue(self
, bcolour
):
44 self
.SetColourValue(bcolour
)
47 return self
.set_colour
50 if self
.callback
!= None:
53 def OnClick(self
, event
):
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
.b
.SetBackgroundColour(bcolour
)