X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b881fc787d2823bdd8a415080b82feee90804a17..609b563c8b9ade4fcde9160f11c7deaf16a9f7b6:/wxPython/wx/lib/colourselect.py diff --git a/wxPython/wx/lib/colourselect.py b/wxPython/wx/lib/colourselect.py index b96dadd29e..20fb0d0e35 100644 --- a/wxPython/wx/lib/colourselect.py +++ b/wxPython/wx/lib/colourselect.py @@ -86,20 +86,35 @@ 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) + dc.SetFont(self.GetFont()) label = self.GetLabel() # Just make a little colored bitmap dc.SetBackground(wx.Brush(self.colour)) @@ -123,7 +138,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())) @@ -134,13 +150,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...