Beispiel #1
0
 def update_object(self, event):
     """ Handles the user changing the contents of the edit control.
     """
     if not isinstance(event, wx._core.CommandEvent):
         return
     try:
         self.value = w3c_color_database.Find(self.control.GetValue())
         set_color(self)
     except TraitError:
         pass
Beispiel #2
0
 def update_object(self, event):
     """ Handles the user changing the contents of the edit control.
     """
     if not isinstance(event, wx._core.CommandEvent):
         return
     try:
         # The TextCtrl object was saved as self._text_control in init().
         value = self._text_control.GetValue()
         self.value = w3c_color_database.Find(value)
         self.set_color()
     except TraitError:
         pass
Beispiel #3
0
    def OnDrawItem(self, dc, rect, item, flags):

        r = wx.Rect(rect.x, rect.y, rect.width, rect.height)
        r.Deflate(3, 0)
        swatch_size = r.height - 2

        color_name = self.GetString(item)

        dc.DrawText(color_name, r.x + 3,
                    r.y + (r.height - dc.GetCharHeight()) / 2)

        if color_name == 'custom':
            swatch = wx.Rect(r.x + r.width - swatch_size, r.y + 1, swatch_size,
                             swatch_size)
            dc.GradientFillLinear(swatch, wx.Colour(255, 255, 0),
                                  wx.Colour(0, 0, 255))
        else:
            color = w3c_color_database.Find(color_name)

            brush = wx.Brush(color)
            dc.SetBrush(brush)
            dc.DrawRectangle(r.x + r.width - swatch_size, r.y + 1, swatch_size,
                             swatch_size)
Beispiel #4
0
    def color_selected(self, event):
        """
        Event for when color is selected
        """

        color_name = self.choices[event.Selection]

        if color_name == 'custom':
            color_dialog = wx.ColourDialog(self.control)
            result = color_dialog.ShowModal()
            if result == wx.ID_CANCEL:
                return

            color = color_dialog.GetColourData().GetColour()
            self.value = self.factory.from_wx_color(color)
        else:
            try:
                color = w3c_color_database.Find(color_name)
                self.value = self.factory.from_wx_color(color)
            except ValueError:
                pass

        return