From e0a54ac2bd28340e4dc7a29a593402458b078816 Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Wed, 9 Apr 2025 17:13:24 +0200 Subject: [PATCH] Popups done, Readout Screen prepared, Small fixes --- biogascontrollerapp/biogascontrollerapp.py | 15 ++- .../{settings/settings.kv => about/about.kv} | 6 +- .../{settings/settings.py => about/about.py} | 4 +- biogascontrollerapp/gui/credits/credits.kv | 2 +- biogascontrollerapp/gui/home/home.kv | 4 +- biogascontrollerapp/gui/home/home.py | 23 +++- biogascontrollerapp/gui/main/main.kv | 107 ++++++++++++++++++ biogascontrollerapp/gui/main/main.py | 25 ++++ biogascontrollerapp/gui/popups/popups.kv | 46 ++++---- biogascontrollerapp/gui/popups/popups.py | 51 +++++++-- biogascontrollerapp/gui/program/program.py | 4 + biogascontrollerapp/lib/com.py | 7 +- 12 files changed, 248 insertions(+), 46 deletions(-) rename biogascontrollerapp/gui/{settings/settings.kv => about/about.kv} (94%) rename biogascontrollerapp/gui/{settings/settings.py => about/about.py} (73%) create mode 100644 biogascontrollerapp/gui/main/main.kv create mode 100644 biogascontrollerapp/gui/main/main.py diff --git a/biogascontrollerapp/biogascontrollerapp.py b/biogascontrollerapp/biogascontrollerapp.py index eec58f6..c2fc2c4 100644 --- a/biogascontrollerapp/biogascontrollerapp.py +++ b/biogascontrollerapp/biogascontrollerapp.py @@ -2,6 +2,8 @@ import os import configparser from typing import override +from lib.com import Com + config = configparser.ConfigParser() config.read('./config.ini') @@ -13,12 +15,12 @@ else: # Load kivy modules -from kivy.core.window import Window, Config +# from kivy.core.window import Window, Config from kivy.uix.screenmanager import ScreenManager from kivy.app import App # Load other libraries -import threading +# import threading # Store the current app version app_version = f"{config['Info']['version']}{config['Info']['subVersion']}" @@ -29,7 +31,8 @@ app_version = f"{config['Info']['version']}{config['Info']['subVersion']}" from gui.home.home import HomeScreen from gui.credits.credits import CreditsScreen -from gui.settings.settings import SettingsScreen +from gui.about.about import AboutScreen +from gui.main.main import MainScreen #----------------# # Screen Manager # @@ -41,11 +44,13 @@ class BiogasControllerApp(App): @override def build(self): + com = Com(); self.icon = './BiogasControllerAppLogo.png' self.title = 'BiogasControllerApp-' + app_version - self.screen_manager.add_widget(HomeScreen(name='home')) + self.screen_manager.add_widget(HomeScreen(com, name='home')) + self.screen_manager.add_widget(MainScreen(com, name='main')) self.screen_manager.add_widget(CreditsScreen(name='credits')) - self.screen_manager.add_widget(SettingsScreen(name='settings')) + self.screen_manager.add_widget(AboutScreen(name='about')) return self.screen_manager if __name__ == "__main__": diff --git a/biogascontrollerapp/gui/settings/settings.kv b/biogascontrollerapp/gui/about/about.kv similarity index 94% rename from biogascontrollerapp/gui/settings/settings.kv rename to biogascontrollerapp/gui/about/about.kv index b1354a7..7b7a06a 100644 --- a/biogascontrollerapp/gui/settings/settings.kv +++ b/biogascontrollerapp/gui/about/about.kv @@ -1,5 +1,5 @@ -: - name: "settings" +: + name: "about" canvas.before: Color: rgba: (50,50,50,0.2) @@ -9,7 +9,7 @@ GridLayout: cols: 1 Label: - text: "Settings" + text: "About" font_size: 40 color: (0, 113, 0, 1) bold: True diff --git a/biogascontrollerapp/gui/settings/settings.py b/biogascontrollerapp/gui/about/about.py similarity index 73% rename from biogascontrollerapp/gui/settings/settings.py rename to biogascontrollerapp/gui/about/about.py index 0251b1c..180e7cf 100644 --- a/biogascontrollerapp/gui/settings/settings.py +++ b/biogascontrollerapp/gui/about/about.py @@ -3,8 +3,8 @@ from kivy.lang import Builder import webbrowser -class SettingsScreen(Screen): +class AboutScreen(Screen): def report_issue(self): webbrowser.open('https://github.com/janishutz/BiogasControllerApp/issues', new=2) -Builder.load_file('./gui/settings/settings.kv') +Builder.load_file('./gui/about/about.kv') diff --git a/biogascontrollerapp/gui/credits/credits.kv b/biogascontrollerapp/gui/credits/credits.kv index 5f879ad..3c3a02f 100644 --- a/biogascontrollerapp/gui/credits/credits.kv +++ b/biogascontrollerapp/gui/credits/credits.kv @@ -12,7 +12,7 @@ size_hint: 0.4, 0.2 pos_hint: {"x":0.3, "y":0.1} on_release: - app.root.current = "settings" + app.root.current = "about" root.manager.transition.direction = "right" GridLayout: cols:1 diff --git a/biogascontrollerapp/gui/home/home.kv b/biogascontrollerapp/gui/home/home.kv index 40a78cb..e9a052c 100644 --- a/biogascontrollerapp/gui/home/home.kv +++ b/biogascontrollerapp/gui/home/home.kv @@ -37,10 +37,10 @@ font_size: 13 pos_hint: {"y": -0.45, "x":0.05} Button: - text: "Settings" + text: "About" font_size: 13 size_hint: 0.07, 0.06 pos_hint: {"x":0.01, "y":0.01} background_color: (50, 0, 0, 0.2) on_release: - root.to_settings() + root.to_about() diff --git a/biogascontrollerapp/gui/home/home.py b/biogascontrollerapp/gui/home/home.py index 4273484..87b01f1 100644 --- a/biogascontrollerapp/gui/home/home.py +++ b/biogascontrollerapp/gui/home/home.py @@ -1,16 +1,29 @@ from kivy.uix.screenmanager import Screen from kivy.lang import Builder - +from gui.popups.popups import QuitPopup, SingleRowPopup, TwoActionPopup +from lib.com import Com class HomeScreen(Screen): + def __init__(self, com: Com, **kw): + self._com = com; + super().__init__(**kw) + def start(self): - pass + if self._com.connect(19200): + self.manager.current = 'main' + self.manager.transition.direction = 'right' + else: + TwoActionPopup().open('Failed to connect', 'Details', self.open_details_popup) + print('ERROR connecting') + + def open_details_popup(self): + print( 'Details' ) def quit(self): - pass + QuitPopup(self._com).open() - def to_settings(self): - self.manager.current = 'settings' + def to_about(self): + self.manager.current = 'about' self.manager.transition.direction = 'down' diff --git a/biogascontrollerapp/gui/main/main.kv b/biogascontrollerapp/gui/main/main.kv new file mode 100644 index 0000000..9c1b1a7 --- /dev/null +++ b/biogascontrollerapp/gui/main/main.kv @@ -0,0 +1,107 @@ +: + on_pre_enter: root.reset() + name: "main" + canvas.before: + Color: + rgba: (50,50,50,0.2) + Rectangle: + size: self.size + pos: self.pos + GridLayout: + FloatLayout: + Label: + pos_hint: {"y":0.4} + text: "READOUT" + font_size: 40 + color: (0, 113, 0, 1) + bold: True + GridLayout: + cols:4 + size_hint: 0.8, 0.3 + pos_hint: {"x":0.1, "y":0.4} + Label: + text: "SENSOR 1: " + font_size: 20 + Label: + id: sonde1 + text: "" + Label: + text: "SENSOR 2: " + font_size: 20 + Label: + id: sonde2 + text: "" + Label: + text: "SENSOR 3: " + font_size: 20 + Label: + id: sonde3 + text: "" + Label: + text: "SENSOR 4: " + font_size: 20 + Label: + id: sonde4 + text: "" + Button: + text: "Start communication" + size_hint: 0.2, 0.1 + pos_hint: {"x": 0.5, "y": 0.05} + background_color: (255, 0, 0, 0.6) + on_release: + root.start() + Button: + text: "End communication" + size_hint: 0.2, 0.1 + pos_hint: {"x": 0.7, "y": 0.05} + background_color: (255, 0, 0, 0.6) + on_release: + root.end() + Button: + text: "Back" + size_hint: 0.3, 0.1 + pos_hint: {"x":0.05, "y":0.05} + background_color: (255, 0, 0, 0.6) + on_release: + root.end() + app.root.current = "home" + root.manager.transition.direction = "left" + ToggleButton: + id: mode_selector + size_hint: 0.15, 0.1 + pos_hint: {"x":0.1, "y":0.2} + text: "Normal Mode" if self.state == "normal" else "Fast Mode" + on_text: root.switch_mode(mode_selector.text) + background_color: (255,0,0,0.6) if self.state == "normal" else (0,0,255,0.6) + Button: + text: "Read Data" + size_hint: 0.15, 0.1 + pos_hint: {"x":0.3, "y":0.2} + background_color: (255, 0, 0, 0.6) + on_release: + root.end() + app.root.current = "read" + root.manager.transition.direction = "down" + Button: + text: "Temperature" + size_hint: 0.15, 0.1 + pos_hint: {"x":0.5, "y":0.2} + background_color: (255, 0, 0, 0.6) + on_release: + root.end() + app.root.current = "temperature" + root.manager.transition.direction = "down" + Button: + text: "Change all Data" + size_hint: 0.15, 0.1 + pos_hint: {"x":0.7, "y":0.2} + background_color: (255, 0, 0, 0.6) + on_release: + root.end() + app.root.current = "program" + root.manager.transition.direction = "down" + Label: + id: frequency + text: "Frequency will appear here" + font_size: 10 + pos_hint: {"x":0.4, "y": 0.3} diff --git a/biogascontrollerapp/gui/main/main.py b/biogascontrollerapp/gui/main/main.py new file mode 100644 index 0000000..ccb8679 --- /dev/null +++ b/biogascontrollerapp/gui/main/main.py @@ -0,0 +1,25 @@ +from kivy.uix.screenmanager import Screen +from kivy.lang import Builder + +from lib.com import Com + + +class MainScreen(Screen): + def __init__(self, com: Com, **kw): + self._com = com; + super().__init__(**kw) + + def start(self): + pass + + def end(self): + pass + + def reset(self): + pass + + def back(self): + pass + + +Builder.load_file('./gui/main/main.kv') diff --git a/biogascontrollerapp/gui/popups/popups.kv b/biogascontrollerapp/gui/popups/popups.kv index 6c6f922..1d212e1 100644 --- a/biogascontrollerapp/gui/popups/popups.kv +++ b/biogascontrollerapp/gui/popups/popups.kv @@ -1,26 +1,10 @@ -: - title: "INFORMATION" - size_hint: 0.7, 0.5 - auto_dismiss: True - GridLayout: - cols: 1 - Label: - id: msg - text_size: self.width, None - GridLayout: - cols: 1 - Button: - text: "Ok" - on_release: - root.dismiss() - -: +: title: "BiogasControllerApp" font_size: 50 size_hint: 0.5, 0.4 auto_dismiss: False GridLayout: - cols:1 + cols: 1 Label: text: "Are you sure you want to leave?" font_size: 20 @@ -38,6 +22,24 @@ on_press: root.dismiss() +: + title: "INFORMATION" + size_hint: 0.7, 0.5 + auto_dismiss: True + GridLayout: + cols: 1 + Label: + id: msg + text: "Message" + text_size: self.width, None + halign: 'center' + GridLayout: + cols: 1 + Button: + text: "Ok" + on_release: + root.dismiss() + : title: "WARNING!" font_size: 50 @@ -49,16 +51,20 @@ id: msg text: "Message" font_size: 20 + halign: 'center' GridLayout: cols:2 Button: id: btn1 text: "Details" on_release: - root.action() + root.action_one() + root.dismiss() Button: + id: btn2 text:"Ok" on_release: + root.action_two() root.dismiss() : @@ -87,8 +93,8 @@ size_hint: 1, 0.7 auto_dismiss: False GridLayout: + cols: 1 Label: - cols:1 id: msg_title text: "title" font_size: 20 diff --git a/biogascontrollerapp/gui/popups/popups.py b/biogascontrollerapp/gui/popups/popups.py index d2728ce..41d5d16 100644 --- a/biogascontrollerapp/gui/popups/popups.py +++ b/biogascontrollerapp/gui/popups/popups.py @@ -1,16 +1,53 @@ +from typing import Callable from kivy.uix.popup import Popup from kivy.lang import Builder +from lib.com import Com -class ThisPopup(Popup): - def start(self): - pass +def empty_func(): + pass + +class QuitPopup(Popup): + def __init__(self, com: Com, **kw): + self._com = com; + super().__init__(**kw) def quit(self): - pass + self._com.close() - def to_settings(self): - pass +class SingleRowPopup(Popup): + def open(self, message, *_args, **kwargs): + self.ids.msg.text = message + return super().open(*_args, **kwargs) +class DualRowPopup(Popup): + def open(self, title: str, message: str, *_args, **kwargs): + self.ids.msg_title.text = title + self.ids.msg_body.text = message + return super().open(*_args, **kwargs) -Builder.load_file('./gui/home/home.kv') +class LargeTrippleRowPopup(Popup): + def open(self, title: str, message: str, details: str, *_args, **kwargs): + self.ids.msg_title.text = title + self.ids.msg_body.text = message + self.ids.msg_extra.text = details + return super().open(*_args, **kwargs) + +class TwoActionPopup(Popup): + def open(self, + message: str, + button_one: str, + action_one: Callable[[], None], + button_two: str = 'Ok', + action_two: Callable[[], None] = empty_func, + *_args, + **kwargs + ): + self.ids.msg.text = message + self.ids.btn1.text = button_one + self.ids.btn2.text = button_two + self.action_one = action_one + self.action_two = action_two + return super().open(*_args, **kwargs) + +Builder.load_file('./gui/popups/popups.kv') diff --git a/biogascontrollerapp/gui/program/program.py b/biogascontrollerapp/gui/program/program.py index 5971a70..3669d49 100644 --- a/biogascontrollerapp/gui/program/program.py +++ b/biogascontrollerapp/gui/program/program.py @@ -3,6 +3,10 @@ from kivy.lang import Builder class HomeScreen(Screen): + def __init__(self, com: Com, **kw): + self._com = com; + super().__init__(**kw) + def start(self): pass diff --git a/biogascontrollerapp/lib/com.py b/biogascontrollerapp/lib/com.py index 279e80d..747ca10 100644 --- a/biogascontrollerapp/lib/com.py +++ b/biogascontrollerapp/lib/com.py @@ -10,11 +10,15 @@ class Com: self._filters = filters if filters != None else [ 'USB-Serial Controller', 'Prolific USB-Serial Controller' ] self._port_override = '' self._baudrate = 19200 + self._err = None def set_port_override(self, override: str) -> None: """Set the port override, to disable port search""" self._port_override = override + def get_error(self) -> serial.SerialException | None: + return self._err + def _connection_check(self) -> bool: if self._serial == None: return self._open() @@ -52,7 +56,8 @@ class Com: if comport == '': try: self._serial = serial.Serial(comport, self._baudrate, timeout=5) - except: + except serial.SerialException as e: + self._err = e return False return True else: