From 868c46f7d6f4ddd7b6b9d8448b3daf04a263ecaf Mon Sep 17 00:00:00 2001 From: admar Date: Mon, 29 May 2023 10:46:45 +0200 Subject: [PATCH] Use outline icons when icon color is white --- clock.py | 98 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 79 insertions(+), 19 deletions(-) diff --git a/clock.py b/clock.py index 647bfd1..44a1ece 100644 --- a/clock.py +++ b/clock.py @@ -567,6 +567,9 @@ class MyClockWidget(FloatLayout): widget.saved_attrs = widget.height, widget.size_hint_y, widget.opacity, widget.disabled widget.height, widget.size_hint_y, widget.opacity, widget.disabled = 0, None, 0, True + def is_widget_hidden(self, widget): + return hasattr(widget, 'saved_attrs') + def draw_numbers(self): """ Add number labels when added in widget hierarchy @@ -652,7 +655,7 @@ class MyClockWidget(FloatLayout): def draw_paqi_expectation(self): self.draw_precipitation_paqi_expectation(self.paqi, self.paqi_thresholds, 0.32) - def draw_icon_helper(self, color, img_source, label): + def paint_icon(self, color, img_source, label): c = (int(256 * color[0]), int(256 * color[1]), int(256 * color[2]), int(256)) tmp = Image.new('RGBA', img_source.size, color = c) img_modified = ImageChops.multiply(tmp, img_source) @@ -665,38 +668,89 @@ class MyClockWidget(FloatLayout): icon = self.ids[label] icon.texture = im.texture + def draw_icon_helper(self, x, x_thresholds, x_label, L, color_prev, img): + N = min(L, len(x)) + colors = self.calculate_colors(x[:N], x_thresholds) + color = colors[x.index(max(x[:N]))] + + if color_prev != color: + # Color has changed + if color == [1, 1, 1]: + img = Image.open("icons/" + x_label + "_outline.png") + else: + if color_prev == [1, 1, 1]: + img = Image.open("icons/" + x_label + ".png") + + self.pollen_color_prev = color + self.paint_icon(color, img, "icon_" + x_label) + + return color + def draw_icon_uvi(self): if hasattr(self, 'image_uvi') == False: self.image_uvi = Image.open("icons/uvi.png") - colors = self.calculate_colors(self.uvi[:1], self.uvi_thresholds) - color = colors[0] + if len(self.uvi) == 0: + if self.is_widget_hidden(self.ids["icon_uvi"]) == False: + self.draw_list_curr_frame.append(["self.hide_widget", self.ids["icon_uvi"], True]) + return - if hasattr(self, 'uvi_color_prev') == False or self.uvi_color_prev != color: - self.uvi_color_prev = color - self.draw_icon_helper(color, self.image_uvi, "icon_uvi") + if self.is_widget_hidden(self.ids["icon_uvi"]): + self.draw_list_curr_frame.append(["self.hide_widget", self.ids["icon_uvi"], False]) + + if hasattr(self, 'uvi_color_prev') == False: + self.uvi_color_prev = [] + + if hasattr(self, 'uvi_color') == False: + self.uvi_color = [] + + color = self.draw_icon_helper(self.uvi, self.uvi_thresholds, "uvi", 1, self.uvi_color_prev, self.image_uvi) + self.uvi_color_prev = self.uvi_color + self.uvi_color = color def draw_icon_pollen(self): if hasattr(self, 'image_pollen') == False: self.image_pollen = Image.open("icons/pollen.png") - colors = self.calculate_colors(self.pollen[:12], self.pollen_thresholds) - color = colors[self.pollen.index(max(self.pollen[:12]))] + if len(self.pollen) == 0: + if self.is_widget_hidden(self.ids["icon_pollen"]) == False: + self.draw_list_curr_frame.append(["self.hide_widget", self.ids["icon_pollen"], True]) + return - if hasattr(self, 'pollen_color_prev') == False or self.pollen_color_prev != color: - self.pollen_color_prev = color - self.draw_icon_helper(color, self.image_pollen, "icon_pollen") + if self.is_widget_hidden(self.ids["icon_pollen"]): + self.draw_list_curr_frame.append(["self.hide_widget", self.ids["icon_pollen"], False]) + + if hasattr(self, 'pollen_color_prev') == False: + self.pollen_color_prev = [] + + if hasattr(self, 'pollen_color') == False: + self.pollen_color = [] + + color = self.draw_icon_helper(self.pollen, self.pollen_thresholds, "pollen", 12, self.pollen_color_prev, self.image_pollen) + self.pollen_color_prev = self.pollen_color + self.pollen_color = color def draw_icon_aqi(self): if hasattr(self, 'image_aqi') == False: self.image_aqi = Image.open("icons/aqi.png") - colors = self.calculate_colors(self.aqi[:12], self.aqi_thresholds) - color = colors[self.aqi.index(max(self.aqi[:12]))] + if len(self.aqi) == 0: + if self.is_widget_hidden(self.ids["icon_aqi"]) == False: + self.draw_list_curr_frame.append(["self.hide_widget", self.ids["icon_aqi"], True]) + return - if hasattr(self, 'aqi_color_prev') == False or self.aqi_color_prev != color: - self.aqi_color_prev = color - self.draw_icon_helper(color, self.image_aqi, "icon_aqi") + if self.is_widget_hidden(self.ids["icon_aqi"]): + self.draw_list_curr_frame.append(["self.hide_widget", self.ids["icon_aqi"], False]) + + if hasattr(self, 'aqi_color_prev') == False: + self.aqi_color_prev = [] + + if hasattr(self, 'aqi_color') == False: + self.aqi_color = [] + + color = self.draw_icon_helper(self.aqi, self.aqi_thresholds, "aqi", 12, self.aqi_color_prev, self.image_aqi) + self.aqi_color_prev = self.aqi_color + self.aqi_color = color def draw_icons(self): self.draw_icon_uvi() @@ -1010,10 +1064,16 @@ class MyClockWidget(FloatLayout): self.draw_list_curr_frame.append(["self.hide_widget", self.ids["face_plate"], False]) self.draw_list_curr_frame.append(["self.hide_widget", self.ids["face"], False]) self.draw_list_curr_frame.append(["self.hide_widget", self.ids["hands"], False]) + if self.view == "clock": - self.draw_list_curr_frame.append(["self.hide_widget", self.ids["icon_uvi"], False]) - self.draw_list_curr_frame.append(["self.hide_widget", self.ids["icon_pollen"], False]) - self.draw_list_curr_frame.append(["self.hide_widget", self.ids["icon_aqi"], False]) + if len(self.uvi) > 0: + self.draw_list_curr_frame.append(["self.hide_widget", self.ids["icon_uvi"], False]) + + if len(self.pollen) > 0: + self.draw_list_curr_frame.append(["self.hide_widget", self.ids["icon_pollen"], False]) + + if len(self.aqi) > 0: + self.draw_list_curr_frame.append(["self.hide_widget", self.ids["icon_aqi"], False]) if self.view == "set_alarm": t = self.settings.alarm_time