From 99b327cf3968c49dacfd2136dcab2eb3426e1481 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Thu, 29 Sep 2022 19:58:21 +0200 Subject: [PATCH] Next iteration of preventing misleading data flows --- src/fime/main.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/fime/main.py b/src/fime/main.py index 16f16b2..7492163 100755 --- a/src/fime/main.py +++ b/src/fime/main.py @@ -4,6 +4,7 @@ import signal import sys from functools import partial from pathlib import Path +from typing import Optional from loguru import logger @@ -67,6 +68,8 @@ class App: self.tray.setToolTip("fime") self.update_tray_menu() + self.last_dialog: Optional[QtWidgets.QDialog] = None + @QtCore.Slot() def new_task_imported(self): if self.import_task.task_text: @@ -92,11 +95,21 @@ class App: self.tray.setToolTip(f"{task} - fime") self.update_tray_menu() + def close_open_dialog(self): + if self.last_dialog and self.last_dialog.isVisible(): + self.last_dialog.reject() + def change_task(self, task): + self.close_open_dialog() self.active_task = task self.log.log(task) self.tasks.update_jira_task_usage(task) + def open_new_dialog(self, new_dialog: QtWidgets.QDialog): + self.close_open_dialog() + self.last_dialog = new_dialog + new_dialog.show() + def update_tray_menu(self): menu_items = [] tmp_action = self.menu.addAction("tmp") @@ -121,14 +134,14 @@ class App: add_tasks(["Nothing"]) menu_items.append((1, None)) - menu_items.append(("Import Jira task", self.import_task.show)) - menu_items.append(("Edit tasks", self.taskEdit.show)) - menu_items.append(("Report", self.reportDialog.show)) - menu_items.append(("Worklog", self.worklogDialog.show)) + menu_items.append(("Import Jira task", partial(self.open_new_dialog, self.import_task))) + menu_items.append(("Edit tasks", partial(self.open_new_dialog, self.taskEdit))) + menu_items.append(("Report", partial(self.open_new_dialog, self.reportDialog))) + menu_items.append(("Worklog", partial(self.open_new_dialog, self.worklogDialog))) menu_items.append((1, None)) - menu_items.append(("About", self.about.show)) + menu_items.append(("About", partial(self.open_new_dialog, self.about))) menu_items.append(("Close", self.app.quit)) if self.menu_flipped: