Popups done, Readout Screen prepared, Small fixes

This commit is contained in:
2025-04-09 17:13:24 +02:00
parent 36a3079040
commit e0a54ac2bd
12 changed files with 248 additions and 46 deletions

View File

@@ -2,6 +2,8 @@ import os
import configparser import configparser
from typing import override from typing import override
from lib.com import Com
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read('./config.ini') config.read('./config.ini')
@@ -13,12 +15,12 @@ else:
# Load kivy modules # 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.uix.screenmanager import ScreenManager
from kivy.app import App from kivy.app import App
# Load other libraries # Load other libraries
import threading # import threading
# Store the current app version # Store the current app version
app_version = f"{config['Info']['version']}{config['Info']['subVersion']}" 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.home.home import HomeScreen
from gui.credits.credits import CreditsScreen 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 # # Screen Manager #
@@ -41,11 +44,13 @@ class BiogasControllerApp(App):
@override @override
def build(self): def build(self):
com = Com();
self.icon = './BiogasControllerAppLogo.png' self.icon = './BiogasControllerAppLogo.png'
self.title = 'BiogasControllerApp-' + app_version 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(CreditsScreen(name='credits'))
self.screen_manager.add_widget(SettingsScreen(name='settings')) self.screen_manager.add_widget(AboutScreen(name='about'))
return self.screen_manager return self.screen_manager
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -1,5 +1,5 @@
<SettingsScreen>: <AboutScreen>:
name: "settings" name: "about"
canvas.before: canvas.before:
Color: Color:
rgba: (50,50,50,0.2) rgba: (50,50,50,0.2)
@@ -9,7 +9,7 @@
GridLayout: GridLayout:
cols: 1 cols: 1
Label: Label:
text: "Settings" text: "About"
font_size: 40 font_size: 40
color: (0, 113, 0, 1) color: (0, 113, 0, 1)
bold: True bold: True

View File

@@ -3,8 +3,8 @@ from kivy.lang import Builder
import webbrowser import webbrowser
class SettingsScreen(Screen): class AboutScreen(Screen):
def report_issue(self): def report_issue(self):
webbrowser.open('https://github.com/janishutz/BiogasControllerApp/issues', new=2) webbrowser.open('https://github.com/janishutz/BiogasControllerApp/issues', new=2)
Builder.load_file('./gui/settings/settings.kv') Builder.load_file('./gui/about/about.kv')

View File

@@ -12,7 +12,7 @@
size_hint: 0.4, 0.2 size_hint: 0.4, 0.2
pos_hint: {"x":0.3, "y":0.1} pos_hint: {"x":0.3, "y":0.1}
on_release: on_release:
app.root.current = "settings" app.root.current = "about"
root.manager.transition.direction = "right" root.manager.transition.direction = "right"
GridLayout: GridLayout:
cols:1 cols:1

View File

@@ -37,10 +37,10 @@
font_size: 13 font_size: 13
pos_hint: {"y": -0.45, "x":0.05} pos_hint: {"y": -0.45, "x":0.05}
Button: Button:
text: "Settings" text: "About"
font_size: 13 font_size: 13
size_hint: 0.07, 0.06 size_hint: 0.07, 0.06
pos_hint: {"x":0.01, "y":0.01} pos_hint: {"x":0.01, "y":0.01}
background_color: (50, 0, 0, 0.2) background_color: (50, 0, 0, 0.2)
on_release: on_release:
root.to_settings() root.to_about()

View File

@@ -1,16 +1,29 @@
from kivy.uix.screenmanager import Screen from kivy.uix.screenmanager import Screen
from kivy.lang import Builder from kivy.lang import Builder
from gui.popups.popups import QuitPopup, SingleRowPopup, TwoActionPopup
from lib.com import Com
class HomeScreen(Screen): class HomeScreen(Screen):
def __init__(self, com: Com, **kw):
self._com = com;
super().__init__(**kw)
def start(self): 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): def quit(self):
pass QuitPopup(self._com).open()
def to_settings(self): def to_about(self):
self.manager.current = 'settings' self.manager.current = 'about'
self.manager.transition.direction = 'down' self.manager.transition.direction = 'down'

View File

@@ -0,0 +1,107 @@
<MainScreen>:
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}

View File

@@ -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')

View File

@@ -1,26 +1,10 @@
<SingleRowPopUp>: <QuitPopup>:
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()
<QuitPopUp>:
title: "BiogasControllerApp" title: "BiogasControllerApp"
font_size: 50 font_size: 50
size_hint: 0.5, 0.4 size_hint: 0.5, 0.4
auto_dismiss: False auto_dismiss: False
GridLayout: GridLayout:
cols:1 cols: 1
Label: Label:
text: "Are you sure you want to leave?" text: "Are you sure you want to leave?"
font_size: 20 font_size: 20
@@ -38,6 +22,24 @@
on_press: on_press:
root.dismiss() root.dismiss()
<SingleRowPopup>:
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()
<TwoActionPopup>: <TwoActionPopup>:
title: "WARNING!" title: "WARNING!"
font_size: 50 font_size: 50
@@ -49,16 +51,20 @@
id: msg id: msg
text: "Message" text: "Message"
font_size: 20 font_size: 20
halign: 'center'
GridLayout: GridLayout:
cols:2 cols:2
Button: Button:
id: btn1 id: btn1
text: "Details" text: "Details"
on_release: on_release:
root.action() root.action_one()
root.dismiss()
Button: Button:
id: btn2
text:"Ok" text:"Ok"
on_release: on_release:
root.action_two()
root.dismiss() root.dismiss()
<DualRowPopup>: <DualRowPopup>:
@@ -87,8 +93,8 @@
size_hint: 1, 0.7 size_hint: 1, 0.7
auto_dismiss: False auto_dismiss: False
GridLayout: GridLayout:
cols: 1
Label: Label:
cols:1
id: msg_title id: msg_title
text: "title" text: "title"
font_size: 20 font_size: 20

View File

@@ -1,16 +1,53 @@
from typing import Callable
from kivy.uix.popup import Popup from kivy.uix.popup import Popup
from kivy.lang import Builder from kivy.lang import Builder
from lib.com import Com
class ThisPopup(Popup): def empty_func():
def start(self):
pass pass
class QuitPopup(Popup):
def __init__(self, com: Com, **kw):
self._com = com;
super().__init__(**kw)
def quit(self): def quit(self):
pass self._com.close()
def to_settings(self): class SingleRowPopup(Popup):
pass 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')

View File

@@ -3,6 +3,10 @@ from kivy.lang import Builder
class HomeScreen(Screen): class HomeScreen(Screen):
def __init__(self, com: Com, **kw):
self._com = com;
super().__init__(**kw)
def start(self): def start(self):
pass pass

View File

@@ -10,11 +10,15 @@ class Com:
self._filters = filters if filters != None else [ 'USB-Serial Controller', 'Prolific USB-Serial Controller' ] self._filters = filters if filters != None else [ 'USB-Serial Controller', 'Prolific USB-Serial Controller' ]
self._port_override = '' self._port_override = ''
self._baudrate = 19200 self._baudrate = 19200
self._err = None
def set_port_override(self, override: str) -> None: def set_port_override(self, override: str) -> None:
"""Set the port override, to disable port search""" """Set the port override, to disable port search"""
self._port_override = override self._port_override = override
def get_error(self) -> serial.SerialException | None:
return self._err
def _connection_check(self) -> bool: def _connection_check(self) -> bool:
if self._serial == None: if self._serial == None:
return self._open() return self._open()
@@ -52,7 +56,8 @@ class Com:
if comport == '': if comport == '':
try: try:
self._serial = serial.Serial(comport, self._baudrate, timeout=5) self._serial = serial.Serial(comport, self._baudrate, timeout=5)
except: except serial.SerialException as e:
self._err = e
return False return False
return True return True
else: else: