Updated contribs from Lorne White

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12779 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2001-11-30 23:33:32 +00:00
parent 68673975c6
commit 572c7069bb
5 changed files with 160 additions and 125 deletions

View File

@@ -4,7 +4,7 @@
#
# Author: Lorne White, Lorne.White@telusplanet.net
#
# Created: Sept 4, 2001
# Created: Feb 25, 2001
# Licence: wxWindows license
#----------------------------------------------------------------------------
@@ -18,44 +18,55 @@ from wxPython.wx import *
# Updates:
# call back to function if changes made
# Cliff Wells, logiplexsoftware@earthlink.net:
# - Made ColourSelect into "is a button" rather than "has a button"
# - Added label parameter and logic to adjust the label colour according to the background
# colour
# - Added id argument
# - Rearranged arguments to more closely follow wx conventions
# - Simplified some of the code
class ColourSelect(wxButton):
def __init__(self, parent, ID, bcolour=[0, 0, 0], pos=wxPoint(20, 20), size=wxSize(20, 20), style=0, callback=None):
wxButton.__init__(self, parent, ID, "", pos, size, style)
self.win = parent
def __init__(self, parent, id, label = "", bcolour=(0, 0, 0),
pos = wxDefaultPosition, size = wxDefaultSize,
callback = None):
wxButton.__init__(self, parent, id, label, pos=pos, size=size)
self.SetColour(bcolour)
self.callback = callback
EVT_BUTTON(self, ID, self.OnClick)
self.SetColourValue(bcolour)
def SetColour(self, bcolour):
self.SetBackgroundColour(bcolour)
def SetColourValue(self, bcolour):
self.set_colour = bcolour
self.SetBackgroundColour(self.Get_wxColour())
self.SetForegroundColour(wxWHITE)
def SetValue(self, bcolour):
self.SetColourValue(bcolour)
EVT_BUTTON(parent, self.GetId(), self.OnClick)
def GetColour(self):
return self.set_colour
def Get_wxColour(self):
return wxColour(self.set_colour[0], self.set_colour[1], self.set_colour[2])
def GetValue(self):
return self.set_colour
def SetColour(self, bcolour):
self.set_colour_val = wxColor(bcolour[0], bcolour[1], bcolour[2])
self.SetBackgroundColour(self.set_colour_val)
avg = reduce(lambda a, b: a + b, bcolour) / 3
fcolour = avg > 128 and (0, 0, 0) or (255, 255, 255)
self.SetForegroundColour(apply(wxColour, fcolour))
self.set_colour = bcolour
def SetValue(self, bcolour):
self.SetColour(bcolour)
def OnChange(self):
if self.callback != None:
if self.callback is not None:
self.callback()
def OnClick(self, event):
data = wxColourData()
data.SetChooseFull(true)
data.SetColour(self.Get_wxColour())
dlg = wxColourDialog(self.win, data)
if dlg.ShowModal() == wxID_OK:
data.SetColour(self.set_colour_val)
dlg = wxColourDialog(self.GetParent(), data)
changed = dlg.ShowModal() == wxID_OK
if changed:
data = dlg.GetColourData()
self.set_colour = set = data.GetColour().Get()
self.SetBackgroundColour(self.Get_wxColour())
self.OnChange()
self.SetColour(data.GetColour().Get())
dlg.Destroy()
if changed:
self.OnChange() # moved after dlg.Destroy, since who knows what the callback will do...