def test_color_pickle(): from enaml.colors import Color rgba = 1, 2, 3, 4 c = Color(*rgba) print(c.__reduce__()) blob = pickle.dumps(c) c = pickle.loads(blob) assert (c.red, c.green, c.blue, c.alpha) == rgba
def test_color_pickle(): """Test pickling/unpickling color. """ rgba = 1, 2, 3, 4 c = Color(*rgba) print(c.__reduce__()) blob = pickle.dumps(c) c = pickle.loads(blob) assert (c.red, c.green, c.blue, c.alpha) == rgba
def custom_color(index): """ Get the custom color for the given index. The custom colors are shared among all color dialogs. Parameters ---------- index : int The integer index of the custom color. Returns ------- result : Color The custom color for the index. Notes ----- The Application object must exist before calling this method. """ app = Application.instance() assert app is not None, 'the application object does not exist' proxy_cls = app.resolve_proxy_class(ColorDialog) if proxy_cls is not None: return proxy_cls.custom_color(index) return Color(255, 255, 255)
def test_color_initialization(): """Test the different initialization format supported by Color. """ components = [1, 2, 3, 4] c = Color(*components) for name, value in zip(['red', 'green', 'blue', 'alpha'], components): assert getattr(c, name) == value c = Color(alpha=-1) for name in ['red', 'green', 'blue', 'alpha']: assert getattr(c, name) == 0 assert c._tkdata is None get_cached_qcolor(c) assert c._tkdata is not None
def color_icon(color): pixmap = QPixmap(12, 12) if color is None: color = Color(0, 0, 0, 0) pixmap.fill(get_cached_qcolor(color)) icg = IconImage(image=Image(_tkdata=pixmap.toImage())) return Icon(images=[icg])
def test_color_repr(): """Test the repr of Color. """ c = Color(1, 2, 3) print(repr(c)) cbis = eval(repr(c)) for attr in ('red', 'green', 'blue', 'alpha', 'argb'): assert getattr(c, attr) == getattr(cbis, attr)
def test_color_initialization(): """Test the different initialization format supported by Color. """ components = [1, 2, 3, 4] c = Color(*components) for name, value in zip(['red', 'green', 'blue', 'alpha'], components): assert getattr(c, name) == value c = Color(alpha=-1) for name in ['red', 'green', 'blue', 'alpha']: assert getattr(c, name) == 0 assert c._tkdata is None try: from enaml.qt.q_resource_helpers import get_cached_qcolor except Exception: return get_cached_qcolor(c) assert c._tkdata is not None
def color_from_qcolor(q): """ Convert a QColor into an Enaml Color. Parameters ---------- q : QColor The Qt color to convert to Enaml Color. Returns ------- result : Color or None An Enaml Color or None if the QColor is not valid. """ if not q.isValid(): return None return Color(q.red(), q.green(), q.blue(), q.alpha())
def _default_color(self): return Color(0, 0, 0)
def tuple_as_color(tup): r, g, b = tup return Color(int(r * 255), int(g * 255), int(b * 255), 255)