def check_color_input(value): """Check a value is a valid colour input. Returns a parsed `RGBColor` instance if so, raises ValueError otherwise. """ value = value.lower() # Trim a leading hash if value.startswith("#"): value = value[1:] if len(value) != 6: raise ValueError( "Color should be six hexadecimal digits, got %r (%s)" % (value, len(value))) if re.sub(r"[a-f0-9]", "", value): raise ValueError("Color should only contain hex characters, got %r" % value) red = int(value[0:2], base=16) green = int(value[2:4], base=16) blue = int(value[4:6], base=16) return RGBColor(red, green, blue)
def __init__(self, color=None): """Initialize with a color (default is black""" Gtk.AspectFrame.__init__(self, xalign=0.5, yalign=0.5, ratio=1.0, obey_child=False) self.set_shadow_type(Gtk.ShadowType.IN) self.drawingarea = Gtk.DrawingArea() self.add(self.drawingarea) if color is None: color = RGBColor(0, 0, 0) self._color = color self.drawingarea.set_size_request(8, 8) self.drawingarea.connect("draw", self._draw_cb)