3 Copyright (C) 2002 Michael Gilfix <mgilfix@eecs.tufts.edu>
5 This file is part of PyColourChooser.
7 This version of PyColourChooser 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.
18 # 12/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
20 # o wxPyColorChooser -> PyColorChooser
21 # o wxPyColourChooser -> PyColourChooser
26 class PyColourBox(wx
.Panel
):
27 """A Colour Selection Box
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.
33 def __init__(self
, parent
, id, colour
=(0, 0, 0), size
=(25, 20)):
34 """Creates a new colour box instance and initializes the colour
36 wx
.Panel
.__init
__(self
, parent
, id, size
=size
)
38 self
.colour_box
= wx
.Panel(self
, -1, style
=wx
.SIMPLE_BORDER
)
40 sizer
= wx
.GridSizer(1, 1)
41 sizer
.Add(self
.colour_box
, 0, wx
.ALIGN_CENTER_VERTICAL | wx
.ALIGN_CENTER_HORIZONTAL
)
42 sizer
.SetItemMinSize(self
.colour_box
, size
[0] - 5, size
[1] - 5)
43 self
.SetAutoLayout(True)
47 self
.real_bg
= self
.GetBackgroundColour()
48 self
.SetColourTuple(colour
)
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
54 return self
.colour_box
57 """Returns a wxColour object indicating the box's current colour."""
58 return self
.colour_box
.GetBackgroundColour()
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()
65 def SetColourTuple(self
, colour
):
66 """Sets the box's current couple to the given tuple."""
68 self
.colour_box
.SetBackgroundColour(wx
.Colour(*self
.colour
))
72 self
.colour_box
.Update()
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.
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
83 new_colour
= wx
.Colour(red
, green
, blue
)
84 self
.SetBackgroundColour(new_colour
)
86 self
.SetBackgroundColour(self
.real_bg
)