From 5e8ed17bb38ff992a774b8b3a7858031fa5e59cd Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 7 Oct 2023 16:54:38 +0200 Subject: [PATCH] Added e-ink display mode --- sbapp/main.py | 33 ++++++++++++++++++++++++++++----- sbapp/sideband/core.py | 3 +++ sbapp/ui/layouts.py | 17 ++++++++++++++++- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/sbapp/main.py b/sbapp/main.py index 77fefd5..f47b6f8 100644 --- a/sbapp/main.py +++ b/sbapp/main.py @@ -90,6 +90,9 @@ class SidebandApp(MDApp): SERVICE_TIMEOUT = 30 + EINK_BG_STR = "1,0,0,1" + EINK_BG_ARR = [1,0,0,1] + def __init__(self, **kwargs): super().__init__(**kwargs) self.title = "Sideband" @@ -247,17 +250,26 @@ class SidebandApp(MDApp): else: self.color_reject = colors["DeepOrange"]["800"] self.color_accept = colors["LightGreen"]["700"] + + self.apply_eink_mods() def update_ui_theme(self): if self.sideband.config["dark_ui"]: self.theme_cls.theme_style = "Dark" else: self.theme_cls.theme_style = "Light" + self.apply_eink_mods() self.update_ui_colors() - # for wid in self.root.ids: - # RNS.log("Found: "+str(wid)+str(self.root.ids[wid])) + def apply_eink_mods(self): + if self.sideband.config["eink_mode"]: + if self.root != None: + self.root.md_bg_color = self.theme_cls.bg_light + + else: + if self.root != None: + self.root.md_bg_color = self.theme_cls.bg_darkest def set_bars_colors(self): if RNS.vendor.platformutils.get_platform() == "android": @@ -522,7 +534,10 @@ class SidebandApp(MDApp): from android import activity as a_activity a_activity.bind(on_new_intent=self.on_new_intent) - screen = Builder.load_string(root_layout) + if self.sideband.config["eink_mode"] == True: + screen = Builder.load_string(root_layout.replace("app.theme_cls.bg_darkest", "app.theme_cls.bg_light")) + else: + screen = Builder.load_string(root_layout) return screen @@ -541,14 +556,14 @@ class SidebandApp(MDApp): ) def dl_ok(s): dialog.dismiss() - self.quit_action() + self.quit_action(s) ok_button.bind(on_release=dl_ok) self.final_load_completed = False dialog.open() else: - self.quit_action() + self.quit_action(s) else: self.service_last_available = time.time() @@ -1246,6 +1261,11 @@ class SidebandApp(MDApp): self.sideband.save_configuration() self.update_ui_theme() + def save_eink_mode(sender=None, event=None): + self.sideband.config["eink_mode"] = self.root.ids.settings_eink_mode.active + self.sideband.save_configuration() + self.update_ui_theme() + def save_notifications_on(sender=None, event=None): self.sideband.config["notifications_on"] = self.root.ids.settings_notifications_on.active self.sideband.save_configuration() @@ -1331,6 +1351,9 @@ class SidebandApp(MDApp): self.root.ids.settings_dark_ui.active = self.sideband.config["dark_ui"] self.root.ids.settings_dark_ui.bind(active=save_dark_ui) + self.root.ids.settings_eink_mode.active = self.sideband.config["eink_mode"] + self.root.ids.settings_eink_mode.bind(active=save_eink_mode) + self.root.ids.settings_start_announce.active = self.sideband.config["start_announce"] self.root.ids.settings_start_announce.bind(active=save_start_announce) diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py index 67b7cd0..f0188ad 100644 --- a/sbapp/sideband/core.py +++ b/sbapp/sideband/core.py @@ -234,6 +234,7 @@ class SidebandCore(): self.config["last_lxmf_propagation_node"] = None self.config["nn_home_node"] = None self.config["print_command"] = "lp" + self.config["eink_mode"] = False # Connectivity self.config["connect_transport"] = False @@ -330,6 +331,8 @@ class SidebandCore(): self.config["notifications_on"] = True if not "print_command" in self.config: self.config["print_command"] = "lp" + if not "eink_mode" in self.config: + self.config["eink_mode"] = False if not "connect_transport" in self.config: self.config["connect_transport"] = False diff --git a/sbapp/ui/layouts.py b/sbapp/ui/layouts.py index 91f5691..aa519eb 100644 --- a/sbapp/ui/layouts.py +++ b/sbapp/ui/layouts.py @@ -1100,7 +1100,7 @@ MDNavigationLayout: height: dp(48) MDLabel: - text: "Dark Mode UI" + text: "Dark Mode" font_style: "H6" MDSwitch: @@ -1108,6 +1108,21 @@ MDNavigationLayout: pos_hint: {"center_y": 0.3} active: False + MDBoxLayout: + orientation: "horizontal" + size_hint_y: None + padding: [0,0,dp(24),dp(0)] + height: dp(48) + + MDLabel: + text: "E-Ink Mode" + font_style: "H6" + + MDSwitch: + id: settings_eink_mode + pos_hint: {"center_y": 0.3} + active: False + MDBoxLayout: orientation: "horizontal" size_hint_y: None