fixed the obvious “first hack” bugs

This commit is contained in:
alterNERDtive 2020-12-05 17:59:14 +01:00
parent d310c51149
commit d0700eed02
2 changed files with 14 additions and 13 deletions

3
.gitignore vendored
View file

@ -1 +1,2 @@
build/**
build/
__pycache__/

24
load.py
View file

@ -2,8 +2,9 @@ import tkinter as tk
import logging
import l10n
import functools
import os
from typing import Optional, Tuple
from typing import Optional, Tuple, Dict, Any
from config import appname
plugin_name = os.path.basename(os.path.dirname(__file__))
@ -14,8 +15,8 @@ _ = functools.partial(l10n.Translations.translate, context=__file__)
label: Optional[tk.Label]
status: Optional[tk.Label]
main: float
reservoir: float
main_tank: Optional[float] = None
reservoir: Optional[float] = None
def plugin_start3(plugin_dir) -> None:
logger.debug('fuelstatus plugin loaded')
@ -24,8 +25,7 @@ def plugin_stop() -> None:
pass
def prefs_changed(cmdr: str, is_beta: bool) -> None:
global label, status
label = tk.Label(parent, text=_("Fuel levels:"))
update_status()
def plugin_app(parent) -> Tuple[tk.Label,tk.Label]:
global label, status
@ -35,25 +35,25 @@ def plugin_app(parent) -> Tuple[tk.Label,tk.Label]:
return (label, status)
def dashboard_entry(cmdr: str, is_beta: bool, entry: Dict[str, Any]) -> None:
global main, reservoir
main = None
global main_tank, reservoir
main_tank = None
reservoir = None
if "Fuel" in entry:
if "FuelMain" in entry["Fuel"]:
main = entry["Fuel"]["FuelMain"]
main_tank = entry["Fuel"]["FuelMain"]
if "FuelReservoir" in entry["Fuel"]:
reservoir = entry["Fuel"]["FuelReservoir"]
update_status()
def update_status() -> None:
global label, status, main, reservoir
global label, status
label["text"] = f'{_("Fuel levels")}:'
if main is None or reservoir is None:
if main is None and reservoir is None:
if main_tank is None or reservoir is None:
if main_tank is None and reservoir is None:
status["text"] = _("waiting for data …")
else:
# maybe add error handling for this weird edge case, should it ever exist …
status["text"] = _("ERROR")
logger.error("One of main tank and reservoir fuel levels is None, the other isnt … WTF?")
else:
status["text"] = f'{round(main,3)}t ({_("main")}), {round(reservoir,3)}t ({_("reservoir")})'
status["text"] = f'{round(main_tank,3)}t ({_("main")}), {round(reservoir,3)}t ({_("reservoir")})'