]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/lib/colourselect.py
added missing button state
[wxWidgets.git] / wxPython / wx / lib / colourselect.py
index 6fb0bd7e77c8340ff8cfc5ff5d03b3ce8f09215e..5edba11b673e8689d946f2548f9fd9876ae43bc9 100644 (file)
 # o Updated for 2.5 compatability.
 #
 
+"""
+Provides a `ColourSelect` button that, when clicked, will display a
+colour selection dialog.  The selected colour is displayed on the
+button itself.
+"""
+
 #----------------------------------------------------------------------------
 
 import  wx
@@ -54,7 +60,7 @@ EVT_COLOURSELECT = wx.PyEventBinder(wxEVT_COMMAND_COLOURSELECT, 1)
 #----------------------------------------------------------------------------
 
 class ColourSelect(wx.BitmapButton):
-    def __init__(self, parent, id, label="", colour=wx.BLACK,
+    def __init__(self, parent, id=wx.ID_ANY, label="", colour=wx.BLACK,
                  pos=wx.DefaultPosition, size=wx.DefaultSize,
                  callback=None, style=0):
         if label:
@@ -86,17 +92,31 @@ class ColourSelect(wx.BitmapButton):
         self.SetColour(colour)
 
     def SetColour(self, colour):
-        if type(colour) == type( () ):
-            colour = wxColour(*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 SetLabel(self, label):
+        self.label = label
+
+    def GetLabel(self):
+        return self.label
+
+
     def MakeBitmap(self):
-        bdr = 10
+        bdr = 8
         width, height = self.GetSize()
+
+        # yes, this is weird, but it appears to work around a bug in wxMac
+        if "wxMac" in wx.PlatformInfo and width == height:
+            height -= 1
+            
         bmp = wx.EmptyBitmap(width-bdr, height-bdr)
         dc = wx.MemoryDC()
         dc.SelectObject(bmp)
@@ -124,7 +144,8 @@ class ColourSelect(wx.BitmapButton):
         self.SetBitmapDisabled(bmp)
         self.SetBitmapFocus(bmp)
         self.SetBitmapSelected(bmp)
-
+        self.Refresh()
+        
 
     def OnChange(self):
         wx.PostEvent(self, ColourSelectEvent(self.GetId(), self.GetValue()))
@@ -135,13 +156,12 @@ class ColourSelect(wx.BitmapButton):
         data = wx.ColourData()
         data.SetChooseFull(True)
         data.SetColour(self.colour)
-        dlg = wx.ColourDialog(self.GetParent(), data)
+        dlg = wx.ColourDialog(wx.GetTopLevelParent(self), data)
         changed = dlg.ShowModal() == wx.ID_OK
 
         if changed:
             data = dlg.GetColourData()
             self.SetColour(data.GetColour())
-
         dlg.Destroy()
 
         # moved after dlg.Destroy, since who knows what the callback will do...