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