- return self.set_colour
-
- def SetColour(self, bcolour):
- self.set_colour_val = wxColor(bcolour[0], bcolour[1], bcolour[2])
- self.SetBackgroundColour(self.set_colour_val)
- avg = reduce(lambda a, b: a + b, bcolour) / 3
- fcolour = avg > 128 and (0, 0, 0) or (255, 255, 255)
- self.SetForegroundColour(apply(wxColour, fcolour))
- self.set_colour = bcolour
+ return self.colour
+
+ def SetValue(self, colour):
+ self.SetColour(colour)
+
+ def SetColour(self, colour):
+ if type(colour) == tuple:
+ colour = wx.Colour(*colour)
+ if type(colour) == str:
+ colour = wx.NamedColour(colour)
+
+ self.colour = colour
+ bmp = self.MakeBitmap()
+ self.SetBitmap(bmp)
+
+
+ def MakeBitmap(self):
+ bdr = 10
+ width, height = self.GetSize()
+ bmp = wx.EmptyBitmap(width-bdr, height-bdr)
+ dc = wx.MemoryDC()
+ dc.SelectObject(bmp)
+ dc.SetFont(self.GetFont())
+ label = self.GetLabel()
+ # Just make a little colored bitmap
+ dc.SetBackground(wx.Brush(self.colour))
+ dc.Clear()
+
+ if label:
+ # Add a label to it
+ avg = reduce(lambda a, b: a + b, self.colour.Get()) / 3
+ fcolour = avg > 128 and wx.BLACK or wx.WHITE
+ dc.SetTextForeground(fcolour)
+ dc.DrawLabel(label, (0,0, width-bdr, height-bdr),
+ wx.ALIGN_CENTER)
+
+ dc.SelectObject(wx.NullBitmap)
+ return bmp
+
+
+ def SetBitmap(self, bmp):
+ self.SetBitmapLabel(bmp)
+ self.SetBitmapSelected(bmp)
+ self.SetBitmapDisabled(bmp)
+ self.SetBitmapFocus(bmp)
+ self.SetBitmapSelected(bmp)