Add color class and a dict of common colors.
Add a color class and a dictionary of commonly used colors so that we
can use set_color() instead of calling the set_source_rgb() function
with rgb values every time we need to change colors. Also, removed an
unused set_color() function from within graph_edit.py.
Change-Id: I113285f1afcb11cfc3a236bedeb5b885da19eaa9
diff --git a/y2018/control_loops/python/basic_window.py b/y2018/control_loops/python/basic_window.py
index 7caf299..7a34b3a 100644
--- a/y2018/control_loops/python/basic_window.py
+++ b/y2018/control_loops/python/basic_window.py
@@ -4,6 +4,7 @@
from gi.repository import GLib
from gi.repository import Gdk
from gi.repository import GdkX11
+from color import Color, palette
import cairo
identity = cairo.Matrix()
@@ -25,6 +26,11 @@
mainloop = GLib.MainLoop()
+def set_color(cr, color):
+ if color.a == 1.0:
+ cr.set_source_rgb(color.r, color.g, color.b)
+ else:
+ cr.set_source_rgba(color.r, color.g, color.b, color.a)
def quit_main_loop(*args):
mainloop.quit()