Fix graph error and make colors configurable
This commit is contained in:
parent
dd56d192cc
commit
c3103d3b11
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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")
|
||||
|
||||
|
||||
|
36
screen.py
36
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()
|
||||
|
20
styles/base.conf
Normal file
20
styles/base.conf
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
}
|
@ -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;}
|
||||
|
Loading…
x
Reference in New Issue
Block a user