2003-11-12 16:34:20 -05:00
|
|
|
"""
|
|
|
|
wxPyColourChooser
|
|
|
|
Copyright (C) 2002 Michael Gilfix <mgilfix@eecs.tufts.edu>
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
This file is part of wxPyColourChooser.
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
This version of wxPyColourChooser is open source; you can redistribute it
|
|
|
|
and/or modify it under the licensed terms.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
"""
|
2003-12-16 19:34:40 -05:00
|
|
|
# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o 2.5 compatability update.
|
|
|
|
#
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
import wx
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
class PyColourBox(wx.Panel):
|
2003-11-12 16:34:20 -05:00
|
|
|
"""A Colour Selection Box
|
|
|
|
|
|
|
|
The Colour selection box implements button like behavior but contains
|
|
|
|
a solid-filled, coloured sub-box. Placing the colour in a sub-box allows
|
|
|
|
for filling in the main panel's background for a high-lighting effect.
|
|
|
|
"""
|
|
|
|
def __init__(self, parent, id, colour=(0, 0, 0), size=(25, 20)):
|
|
|
|
"""Creates a new colour box instance and initializes the colour
|
|
|
|
content."""
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.Panel.__init__(self, parent, id, size=size)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
self.colour_box = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
sizer = wx.GridSizer(1, 1)
|
|
|
|
sizer.Add(self.colour_box, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
|
2003-11-12 16:34:20 -05:00
|
|
|
sizer.SetItemMinSize(self.colour_box, size[0] - 5, size[1] - 5)
|
|
|
|
self.SetAutoLayout(True)
|
|
|
|
self.SetSizer(sizer)
|
|
|
|
self.Layout()
|
|
|
|
|
|
|
|
self.real_bg = self.GetBackgroundColour()
|
|
|
|
self.SetColourTuple(colour)
|
|
|
|
|
|
|
|
def GetColourBox(self):
|
|
|
|
"""Returns a reference to the internal box object containing the
|
|
|
|
color. This function is useful for setting up event handlers for
|
|
|
|
the box."""
|
|
|
|
return self.colour_box
|
|
|
|
|
|
|
|
def GetColour(self):
|
|
|
|
"""Returns a wxColour object indicating the box's current colour."""
|
|
|
|
return self.colour_box.GetBackgroundColour()
|
|
|
|
|
|
|
|
def SetColour(self, colour):
|
|
|
|
"""Accepts a wxColour object and sets the box's current color."""
|
|
|
|
self.colour_box.SetBackgroundColour(colour)
|
|
|
|
self.colour_box.Refresh()
|
|
|
|
|
|
|
|
def SetColourTuple(self, colour):
|
|
|
|
"""Sets the box's current couple to the given tuple."""
|
|
|
|
self.colour = colour
|
2003-12-16 19:34:40 -05:00
|
|
|
self.colour_box.SetBackgroundColour(wx.Colour(*self.colour))
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
def Update(self):
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.Panel.Update(self)
|
2003-11-12 16:34:20 -05:00
|
|
|
self.colour_box.Update()
|
|
|
|
|
|
|
|
def SetHighlight(self, val):
|
|
|
|
"""Accepts a boolean 'val' toggling the box's highlighting."""
|
|
|
|
# XXX This code has been disabled for now until I can figure out
|
|
|
|
# how to get this to work reliably across all platforms.
|
|
|
|
if val:
|
|
|
|
#A wxColourPtr is returned in windows, making this difficult
|
|
|
|
red =(self.real_bg.Red() - 45) % 255
|
|
|
|
green =(self.real_bg.Green() - 45) % 255
|
|
|
|
blue =(self.real_bg.Blue() - 45) % 255
|
2003-12-16 19:34:40 -05:00
|
|
|
new_colour = wx.Colour(red, green, blue)
|
2003-11-12 16:34:20 -05:00
|
|
|
self.SetBackgroundColour(new_colour)
|
|
|
|
else:
|
|
|
|
self.SetBackgroundColour(self.real_bg)
|
|
|
|
self.Refresh()
|