]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/colourselect.py
cef3f4d445ebc2ef905e54d6dfb75e1ca019d2fe
   1 #---------------------------------------------------------------------------- 
   2 # Name:         ColourSelect.py 
   3 # Purpose:      Colour Box Selection Control 
   5 # Author:       Lorne White, Lorne.White@telusplanet.net 
   7 # Created:      Sept 4, 2001 
   8 # Licence:      wxWindows license 
   9 #---------------------------------------------------------------------------- 
  11 from wxPython
.wx 
import * 
  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 
  19 # call back to function if changes made 
  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
) 
  25         self
.callback 
= callback
 
  26         EVT_BUTTON(self
, ID
, self
.OnClick
) 
  27         self
.SetColourValue(bcolour
) 
  30         if hasattr(self
, "set_colour_val"): 
  31             del self
.set_colour_val
 
  33     def SetColour(self
, bcolour
): 
  34         self
.SetBackgroundColour(bcolour
) 
  36     def SetColourValue(self
, bcolour
): 
  37         self
.set_colour_val 
= wxColour(bcolour
[0], bcolour
[1], bcolour
[2]) 
  38         self
.set_colour 
= bcolour
 
  40         self
.SetBackgroundColour(self
.set_colour_val
) 
  41         self
.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
.SetBackgroundColour(bcolour
)