From 74e974b7abc4c211de967d2d22b2f44172d7fccb Mon Sep 17 00:00:00 2001 From: Faerbit Date: Thu, 29 Sep 2022 19:45:49 +0200 Subject: [PATCH] Refactor TaskEdit dialog --- src/fime/main.py | 9 ++------- src/fime/task_edit.py | 10 +++++----- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/fime/main.py b/src/fime/main.py index 8b13bd2..16f16b2 100755 --- a/src/fime/main.py +++ b/src/fime/main.py @@ -49,7 +49,7 @@ class App: self.import_task = ImportTask(config, None) self.import_task.accepted.connect(self.new_task_imported) - self.taskEdit = TaskEdit(None) + self.taskEdit = TaskEdit(self.tasks, None) self.taskEdit.accepted.connect(self.tasks_edited) self.reportDialog = ReportDialog(self.tasks, Report(lcd), None) @@ -122,7 +122,7 @@ class App: menu_items.append((1, None)) menu_items.append(("Import Jira task", self.import_task.show)) - menu_items.append(("Edit tasks", self.edit_tasks)) + menu_items.append(("Edit tasks", self.taskEdit.show)) menu_items.append(("Report", self.reportDialog.show)) menu_items.append(("Worklog", self.worklogDialog.show)) @@ -161,11 +161,6 @@ class App: else: self.app.exec_() - @QtCore.Slot() - def edit_tasks(self): - self.taskEdit.tasks = self.tasks.tasks - self.taskEdit.show() - def init_logging(): log_dir_path = Path(QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.AppDataLocation)) / "logs" diff --git a/src/fime/task_edit.py b/src/fime/task_edit.py index 07dc593..08c4362 100644 --- a/src/fime/task_edit.py +++ b/src/fime/task_edit.py @@ -3,12 +3,15 @@ try: except ImportError: from PySide2 import QtCore, QtGui, QtWidgets +from fime.data import Tasks from fime.util import get_icon, EditStartedDetector class TaskEdit(QtWidgets.QDialog): - def __init__(self, parent, *args, **kwargs): + def __init__(self, tasks: Tasks, parent, *args, **kwargs): super().__init__(parent, *args, **kwargs) + self._task_data = tasks + self.setWindowTitle("Edit Tasks") self.list = QtCore.QStringListModel() @@ -82,10 +85,7 @@ class TaskEdit(QtWidgets.QDialog): ret = self.list.stringList() return list(filter(None, ret)) # filter empty strings - @tasks.setter - def tasks(self, tasks): - self.list.setStringList(tasks) - def showEvent(self, _): + self.list.setStringList(self._task_data.tasks) self.raise_() self.activateWindow()