From c3103d3b11e54463a93355d8145db164d43f805b Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 5 Dec 2021 20:35:37 -0500 Subject: [PATCH] Fix graph error and make colors configurable --- ks_includes/KlippyGtk.py | 27 +++++++-------------------- ks_includes/widgets/graph.py | 2 +- panels/main_menu.py | 2 -- screen.py | 36 ++++++++++++++++++++++++++++++++++++ styles/base.conf | 20 ++++++++++++++++++++ styles/base.css | 24 ++++++++++++------------ 6 files changed, 76 insertions(+), 35 deletions(-) create mode 100644 styles/base.conf diff --git a/ks_includes/KlippyGtk.py b/ks_includes/KlippyGtk.py index a8aad754..74df3649 100644 --- a/ks_includes/KlippyGtk.py +++ b/ks_includes/KlippyGtk.py @@ -36,26 +36,7 @@ class KlippyGtk: self.header_image_scale_height = 1.4 self.cursor = cursor - self.color_list = { - "extruder": { - "base": 'ff5252', - "hsplit": int('20', 16), - "state": 0 - }, - "bed": { - "base": '1fb0ff', - "hsplit": int('20', 16), - "state": 0 - }, - "fan": { - "colors": ['3DC25A', '58FC7C', '10EB40', '7EF297'], - "state": 0 - }, - "sensor": { - "colors": ['D67600', '830EE3', 'B366F2', 'E06573', 'E38819'], - "state": 0 - } - } + self.color_list = {} # This is set by screen.py init_style() for key in self.color_list: if "base" in self.color_list[key]: @@ -92,6 +73,7 @@ class KlippyGtk: return (self.width - self.get_action_bar_width()) * self.keyboard_ratio def get_temp_color(self, device): + logging.debug("Color list %s" % self.color_list) if device not in self.color_list: return False, False @@ -102,10 +84,15 @@ class KlippyGtk: self.color_list[device]['state'] += 1 color = '{:02X}{:02X}{:02X}'.format(rgb[0], rgb[1], rgb[2]) rgb = [x/255 for x in rgb] + logging.debug("Assigning color: %s %s %s" % (device, rgb, color)) else: colors = self.color_list[device]['colors'] + if self.color_list[device]['state'] >= len(colors): + self.color_list[device]['state'] = 0 color = colors[self.color_list[device]['state'] % len(colors)] rgb = [int(color[i:i+2], 16)/255 for i in range(0, 6, 2)] + self.color_list[device]['state'] += 1 + logging.debug("Assigning color: %s %s %s" % (device, rgb, color)) return rgb, color diff --git a/ks_includes/widgets/graph.py b/ks_includes/widgets/graph.py index 6c85b84a..e4c7be67 100644 --- a/ks_includes/widgets/graph.py +++ b/ks_includes/widgets/graph.py @@ -96,7 +96,7 @@ class HeaterGraph(Gtk.DrawingArea): points_per_pixel = self.max_length / graph_width if points_per_pixel > 3: points_per_pixel = 3 - data_points = graph_width * points_per_pixel + data_points = int(round(graph_width * points_per_pixel, 0)) max_num = math.ceil(self.get_max_num(data_points) * 1.1 / 10) * 10 d_width = 1 / points_per_pixel diff --git a/panels/main_menu.py b/panels/main_menu.py index 85befacc..9f87e9a0 100644 --- a/panels/main_menu.py +++ b/panels/main_menu.py @@ -75,7 +75,6 @@ class MainPanel(MenuPanel): image = "bed" devname = "Heater Bed" class_name = "graph_label_heater_bed" - rgb = [1, 0, 0] rgb, color = self._gtk.get_temp_color("bed") else: s = 1 @@ -84,7 +83,6 @@ class MainPanel(MenuPanel): s += 1 image = "heat-up" class_name = "graph_label_sensor_%s" % s - rgb = [1, 0, 0] rgb, color = self._gtk.get_temp_color("sensor") diff --git a/screen.py b/screen.py index cfb869a0..4b1a1260 100644 --- a/screen.py +++ b/screen.py @@ -448,6 +448,42 @@ class KlipperScreen(Gtk.Window): css_data = css_base_data + css.read() css.close() + f = open(klipperscreendir + "/styles/base.conf") + style_options = json.load(f) + f.close() + + self.gtk.color_list = style_options['graph_colors'] + + if os.path.exists(klipperscreendir + "/styles/%s/style.conf" % (self.theme)): + try: + f = open(klipperscreendir + "/styles/%s/style.conf" % (self.theme)) + style_options.update(json.load(f)) + f.close() + except Exception: + logging.error("Unable to parse custom template conf file.") + + for i in range(len(style_options['graph_colors']['extruder']['colors'])): + num = "" if i == 0 else i+1 + css_data += "\n.graph_label_extruder%s {border-left-color: #%s}" % ( + num, + style_options['graph_colors']['extruder']['colors'][i] + ) + for i in range(len(style_options['graph_colors']['bed']['colors'])): + css_data += "\n.graph_label_heater_bed%s {border-left-color: #%s}" % ( + "" if i+1 == 1 else i+1, + style_options['graph_colors']['bed']['colors'][i] + ) + for i in range(len(style_options['graph_colors']['fan']['colors'])): + css_data += "\n.graph_label_fan_%s {border-left-color: #%s}" % ( + i+1, + style_options['graph_colors']['fan']['colors'][i] + ) + for i in range(len(style_options['graph_colors']['sensor']['colors'])): + css_data += "\n.graph_label_sensor_%s {border-left-color: #%s}" % ( + i+1, + style_options['graph_colors']['sensor']['colors'][i] + ) + css_data = css_data.replace("KS_FONT_SIZE", str(self.gtk.get_font_size())) style_provider = Gtk.CssProvider() diff --git a/styles/base.conf b/styles/base.conf new file mode 100644 index 00000000..b4b678dc --- /dev/null +++ b/styles/base.conf @@ -0,0 +1,20 @@ +{ + "graph_colors": { + "extruder": { + "colors": ["FF5252", "FF7252", "FF9252", "FFB252", "FFD252"], + "state": 0 + }, + "bed": { + "colors": ["1FB0FF"], + "state": 0 + }, + "fan": { + "colors": ["3DC25A", "58FC7C", "10EB40", "7EF297"], + "state": 0 + }, + "sensor": { + "colors": ["D67600", "830EE3", "B366F2", "E06573", "E38819"], + "state": 0 + } + } +} diff --git a/styles/base.css b/styles/base.css index 2c29c314..f839cba5 100644 --- a/styles/base.css +++ b/styles/base.css @@ -449,15 +449,15 @@ popover button { /* Hardcoded values until creation of dynamic CSS updates */ .graph_label_hidden {padding-left: .9em;} /* .4em on top of normal button padding */ -.graph_label_extruder {border-left: .4em solid #ff5252;} -.graph_label_extruder2 {border-left: .4em solid #ff7252;} -.graph_label_heater_bed {border-left: .4em solid #1fb0ff;} -.graph_label_fan_1 {border-left: .4em solid #3DC25A;} -.graph_label_fan_2 {border-left: .4em solid #58FC7C;} -.graph_label_fan_3 {border-left: .4em solid #10EB40;} -.graph_label_fan_4 {border-left: .4em solid #7EF297;} -.graph_label_sensor_1 {border-left: .4em solid #D67600;} -.graph_label_sensor_2 {border-left: .4em solid #830EE3;} -.graph_label_sensor_3 {border-left: .4em solid #B366F2;} -.graph_label_sensor_4 {border-left: .4em solid #E06573;} -.graph_label_sensor_5 {border-left: .4em solid #E38819;} +.graph_label_extruder {border-left-width: .4em; border-left-style: solid;} +.graph_label_extruder2 {border-left-width: .4em; border-left-style: solid;} +.graph_label_heater_bed {border-left-width: .4em; border-left-style: solid;} +.graph_label_fan_1 {border-left-width: .4em; border-left-style: solid;} +.graph_label_fan_2 {border-left-width: .4em; border-left-style: solid;} +.graph_label_fan_3 {border-left-width: .4em; border-left-style: solid;} +.graph_label_fan_4 {border-left-width: .4em; border-left-style: solid;} +.graph_label_sensor_1 {border-left-width: .4em; border-left-style: solid;} +.graph_label_sensor_2 {border-left-width: .4em; border-left-style: solid;} +.graph_label_sensor_3 {border-left-width: .4em; border-left-style: solid;} +.graph_label_sensor_4 {border-left-width: .4em; border-left-style: solid;} +.graph_label_sensor_5 {border-left-width: .4em; border-left-style: solid;}