]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/lib/colourchooser/pycolourbox.py
MaskedEdit patch from Will Sadkin:
[wxWidgets.git] / wxPython / wx / lib / colourchooser / pycolourbox.py
CommitLineData
d14a1e28 1"""
d4b73b1b 2PyColourChooser
d14a1e28 3Copyright (C) 2002 Michael Gilfix <mgilfix@eecs.tufts.edu>
1fded56b 4
d4b73b1b 5This file is part of PyColourChooser.
1fded56b 6
d4b73b1b 7This version of PyColourChooser is open source; you can redistribute it
d14a1e28
RD
8and/or modify it under the licensed terms.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13"""
b881fc78
RD
14# 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
15#
16# o 2.5 compatability update.
17#
d4b73b1b
RD
18# 12/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
19#
20# o wxPyColorChooser -> PyColorChooser
21# o wxPyColourChooser -> PyColourChooser
22#
d14a1e28 23
b881fc78 24import wx
d14a1e28 25
b881fc78 26class PyColourBox(wx.Panel):
d14a1e28
RD
27 """A Colour Selection Box
28
29 The Colour selection box implements button like behavior but contains
30 a solid-filled, coloured sub-box. Placing the colour in a sub-box allows
31 for filling in the main panel's background for a high-lighting effect.
32 """
33 def __init__(self, parent, id, colour=(0, 0, 0), size=(25, 20)):
34 """Creates a new colour box instance and initializes the colour
35 content."""
102e2b26 36 wx.Panel.__init__(self, parent, id, size=size, style=wx.NO_BORDER)
d14a1e28 37
102e2b26 38 self.colour_box = wx.Window(self, -1, style=wx.SIMPLE_BORDER)
d14a1e28 39
b881fc78 40 sizer = wx.GridSizer(1, 1)
f52e0cf4 41 sizer.Add(self.colour_box, 0, wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL)
d14a1e28
RD
42 sizer.SetItemMinSize(self.colour_box, size[0] - 5, size[1] - 5)
43 self.SetAutoLayout(True)
44 self.SetSizer(sizer)
45 self.Layout()
46
47 self.real_bg = self.GetBackgroundColour()
48 self.SetColourTuple(colour)
49
50 def GetColourBox(self):
51 """Returns a reference to the internal box object containing the
52 color. This function is useful for setting up event handlers for
53 the box."""
54 return self.colour_box
55
56 def GetColour(self):
57 """Returns a wxColour object indicating the box's current colour."""
58 return self.colour_box.GetBackgroundColour()
59
60 def SetColour(self, colour):
61 """Accepts a wxColour object and sets the box's current color."""
62 self.colour_box.SetBackgroundColour(colour)
63 self.colour_box.Refresh()
64
65 def SetColourTuple(self, colour):
66 """Sets the box's current couple to the given tuple."""
67 self.colour = colour
b881fc78 68 self.colour_box.SetBackgroundColour(wx.Colour(*self.colour))
d14a1e28
RD
69
70 def Update(self):
b881fc78 71 wx.Panel.Update(self)
d14a1e28
RD
72 self.colour_box.Update()
73
74 def SetHighlight(self, val):
75 """Accepts a boolean 'val' toggling the box's highlighting."""
76 # XXX This code has been disabled for now until I can figure out
77 # how to get this to work reliably across all platforms.
78 if val:
79 #A wxColourPtr is returned in windows, making this difficult
80 red =(self.real_bg.Red() - 45) % 255
81 green =(self.real_bg.Green() - 45) % 255
82 blue =(self.real_bg.Blue() - 45) % 255
b881fc78 83 new_colour = wx.Colour(red, green, blue)
d14a1e28
RD
84 self.SetBackgroundColour(new_colour)
85 else:
86 self.SetBackgroundColour(self.real_bg)
87 self.Refresh()