mirror of
https://github.com/janishutz/BiogasControllerApp.git
synced 2025-11-25 05:44:23 +00:00
Popups done, Readout Screen prepared, Small fixes
This commit is contained in:
@@ -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__":
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<SettingsScreen>:
|
||||
name: "settings"
|
||||
<AboutScreen>:
|
||||
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
|
||||
@@ -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')
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
|
||||
107
biogascontrollerapp/gui/main/main.kv
Normal file
107
biogascontrollerapp/gui/main/main.kv
Normal 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}
|
||||
25
biogascontrollerapp/gui/main/main.py
Normal file
25
biogascontrollerapp/gui/main/main.py
Normal 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')
|
||||
@@ -1,20 +1,4 @@
|
||||
<SingleRowPopUp>:
|
||||
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>:
|
||||
<QuitPopup>:
|
||||
title: "BiogasControllerApp"
|
||||
font_size: 50
|
||||
size_hint: 0.5, 0.4
|
||||
@@ -38,6 +22,24 @@
|
||||
on_press:
|
||||
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>:
|
||||
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()
|
||||
|
||||
<DualRowPopup>:
|
||||
@@ -87,8 +93,8 @@
|
||||
size_hint: 1, 0.7
|
||||
auto_dismiss: False
|
||||
GridLayout:
|
||||
Label:
|
||||
cols: 1
|
||||
Label:
|
||||
id: msg_title
|
||||
text: "title"
|
||||
font_size: 20
|
||||
|
||||
@@ -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):
|
||||
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')
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user