]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/colourchooser/pycolourbox.py
reSWIGged
[wxWidgets.git] / wxPython / wx / lib / colourchooser / pycolourbox.py
1 """
2 PyColourChooser
3 Copyright (C) 2002 Michael Gilfix <mgilfix@eecs.tufts.edu>
4
5 This file is part of PyColourChooser.
6
7 This version of PyColourChooser is open source; you can redistribute it
8 and/or modify it under the licensed terms.
9
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.
13 """
14 # 12/14/2003 - Jeff Grimmett (grimmtooth@softhome.net)
15 #
16 # o 2.5 compatability update.
17 #
18 # 12/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
19 #
20 # o wxPyColorChooser -> PyColorChooser
21 # o wxPyColourChooser -> PyColourChooser
22 #
23
24 import wx
25
26 class PyColourBox(wx.Panel):
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."""
36 wx.Panel.__init__(self, parent, id, size=size)
37
38 self.colour_box = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)
39
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)
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
68 self.colour_box.SetBackgroundColour(wx.Colour(*self.colour))
69
70 def Update(self):
71 wx.Panel.Update(self)
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
83 new_colour = wx.Colour(red, green, blue)
84 self.SetBackgroundColour(new_colour)
85 else:
86 self.SetBackgroundColour(self.real_bg)
87 self.Refresh()