3 Copyright (C) 2002 Michael Gilfix <mgilfix@eecs.tufts.edu>
5 This file is part of wxPyColourChooser.
7 This version of wxPyColourChooser is open source; you can redistribute it
8 and/or modify it under the licensed terms.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 # 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
16 # o 2.5 compatability update.
21 class PyColourBox(wx
.Panel
):
22 """A Colour Selection Box
24 The Colour selection box implements button like behavior but contains
25 a solid-filled, coloured sub-box. Placing the colour in a sub-box allows
26 for filling in the main panel's background for a high-lighting effect.
28 def __init__(self
, parent
, id, colour
=(0, 0, 0), size
=(25, 20)):
29 """Creates a new colour box instance and initializes the colour
31 wx
.Panel
.__init
__(self
, parent
, id, size
=size
)
33 self
.colour_box
= wx
.Panel(self
, -1, style
=wx
.SIMPLE_BORDER
)
35 sizer
= wx
.GridSizer(1, 1)
36 sizer
.Add(self
.colour_box
, 0, wx
.ALIGN_CENTER_VERTICAL | wx
.ALIGN_CENTER_HORIZONTAL
)
37 sizer
.SetItemMinSize(self
.colour_box
, size
[0] - 5, size
[1] - 5)
38 self
.SetAutoLayout(True)
42 self
.real_bg
= self
.GetBackgroundColour()
43 self
.SetColourTuple(colour
)
45 def GetColourBox(self
):
46 """Returns a reference to the internal box object containing the
47 color. This function is useful for setting up event handlers for
49 return self
.colour_box
52 """Returns a wxColour object indicating the box's current colour."""
53 return self
.colour_box
.GetBackgroundColour()
55 def SetColour(self
, colour
):
56 """Accepts a wxColour object and sets the box's current color."""
57 self
.colour_box
.SetBackgroundColour(colour
)
58 self
.colour_box
.Refresh()
60 def SetColourTuple(self
, colour
):
61 """Sets the box's current couple to the given tuple."""
63 self
.colour_box
.SetBackgroundColour(wx
.Colour(*self
.colour
))
67 self
.colour_box
.Update()
69 def SetHighlight(self
, val
):
70 """Accepts a boolean 'val' toggling the box's highlighting."""
71 # XXX This code has been disabled for now until I can figure out
72 # how to get this to work reliably across all platforms.
74 #A wxColourPtr is returned in windows, making this difficult
75 red
=(self
.real_bg
.Red() - 45) % 255
76 green
=(self
.real_bg
.Green() - 45) % 255
77 blue
=(self
.real_bg
.Blue() - 45) % 255
78 new_colour
= wx
.Colour(red
, green
, blue
)
79 self
.SetBackgroundColour(new_colour
)
81 self
.SetBackgroundColour(self
.real_bg
)