From d0700eed028094bbaf9a9c33072692ba848448de Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Sat, 5 Dec 2020 17:59:14 +0100 Subject: [PATCH] =?UTF-8?q?fixed=20the=20obvious=20=E2=80=9Cfirst=20hack?= =?UTF-8?q?=E2=80=9D=20bugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- load.py | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index f65519e..3d43339 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -build/** +build/ +__pycache__/ diff --git a/load.py b/load.py index e24dc01..197f1b4 100644 --- a/load.py +++ b/load.py @@ -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 isn’t … 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")})'