]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/colourchooser/pycolourbox.py
Added wxGetKeyState
[wxWidgets.git] / wxPython / wx / lib / colourchooser / pycolourbox.py
1 """
2 wxPyColourChooser
3 Copyright (C) 2002 Michael Gilfix <mgilfix@eecs.tufts.edu>
4
5 This file is part of wxPyColourChooser.
6
7 This version of wxPyColourChooser 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
19 import wx
20
21 class PyColourBox(wx.Panel):
22 """A Colour Selection Box
23
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.
27 """
28 def __init__(self, parent, id, colour=(0, 0, 0), size=(25, 20)):
29 """Creates a new colour box instance and initializes the colour
30 content."""
31 wx.Panel.__init__(self, parent, id, size=size)
32
33 self.colour_box = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)
34
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)
39 self.SetSizer(sizer)
40 self.Layout()
41
42 self.real_bg = self.GetBackgroundColour()
43 self.SetColourTuple(colour)
44
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
48 the box."""
49 return self.colour_box
50
51 def GetColour(self):
52 """Returns a wxColour object indicating the box's current colour."""
53 return self.colour_box.GetBackgroundColour()
54
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()
59
60 def SetColourTuple(self, colour):
61 """Sets the box's current couple to the given tuple."""
62 self.colour = colour
63 self.colour_box.SetBackgroundColour(wx.Colour(*self.colour))
64
65 def Update(self):
66 wx.Panel.Update(self)
67 self.colour_box.Update()
68
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.
73 if val:
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)
80 else:
81 self.SetBackgroundColour(self.real_bg)
82 self.Refresh()