From 56285caeab77c56cf22e57a3e930b2203f269741 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Wed, 17 Nov 2021 04:27:59 +0100 Subject: [PATCH] Various improvements --- data.py | 2 -- main.py | 25 +++++++++++++++++++------ report.py | 8 ++------ task_completer.py | 8 ++++---- util.py | 6 ++++++ 5 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 util.py diff --git a/data.py b/data.py index ab3d3da..b3a3c88 100644 --- a/data.py +++ b/data.py @@ -51,9 +51,7 @@ class Tasks: return self._jira_tasks def add_jira_task(self, task_name): - print(f"before: {self._jira_tasks}") self._jira_tasks.append(task_name) - print(f"after: {self._jira_tasks}") self._jira_tasks_usage[task_name] = datetime.now() if len(self._jira_tasks_usage) > max_jira_tasks: sorted_tasks = sorted(self._jira_tasks_usage.keys(), key=lambda x: self._jira_tasks_usage[x]) diff --git a/main.py b/main.py index 685e6dd..8bfa6fd 100755 --- a/main.py +++ b/main.py @@ -12,6 +12,7 @@ from exceptions import FimeFrackingException from new_task import NewTask from task_edit import TaskEdit from report import Report +from util import get_screen_height class App: @@ -21,7 +22,7 @@ class App: data = Data() self.tasks = Tasks(data) self.log = Log(data) - self.active_task = self.log.last_log() or "Nothing" + self._active_task = self.log.last_log() or "Nothing" icon = QtGui.QIcon.fromTheme("appointment-new") @@ -57,29 +58,41 @@ class App: @QtCore.Slot() def report_done(self): self.active_task = self.log.last_log() or "Nothing" + + @property + def active_task(self): + return self._active_task + + @active_task.setter + def active_task(self, task): + self._active_task = task + self.tasks.update_jira_task_usage(self._active_task) self.update_tray_menu() def change_task(self, task): self.active_task = task - if task == "Nothing": - return self.log.log(task) - self.update_tray_menu() def update_tray_menu(self): def add_tasks(tasks): + action_height = None for t in tasks: a = self.menu.addAction(t) + action_height = self.menu.actionGeometry(a).height() a.triggered.connect(partial(self.change_task, t)) if t == self.active_task: a.setIcon(QtGui.QIcon.fromTheme("go-next")) + return action_height self.menu.clear() - add_tasks(self.tasks.tasks) + action_height = add_tasks(self.tasks.tasks) + already_taken = (len(self.tasks.tasks) + 4) * action_height + available_space = get_screen_height(self.menu) * 0.8 - already_taken + jira_entry_count = int(available_space // action_height) self.menu.addSeparator() - add_tasks(self.tasks.jira_tasks) + add_tasks(self.tasks.jira_tasks[:jira_entry_count]) self.menu.addSeparator() add_tasks(["Pause"]) diff --git a/report.py b/report.py index 997fa00..c07393c 100644 --- a/report.py +++ b/report.py @@ -5,6 +5,7 @@ from datetime import datetime from PySide2.QtWidgets import QHeaderView from data import Tasks +from util import get_screen_height class Report(QtWidgets.QDialog): @@ -120,13 +121,8 @@ class Report(QtWidgets.QDialog): self.tableWidget.resizeColumnToContents(0) if self.tableWidget.rowCount() > 4: - if hasattr(self.tableWidget, "screen"): - screen_height = self.tableWidget.screen().size().height() - else: - print("unable to detect screen height falling back to default value of 1080") - screen_height = 1080 self.tableWidget.setMinimumHeight(min((self.tableWidget.rowCount() + 2) * self.tableWidget.rowHeight(0), - screen_height * 0.8)) + get_screen_height(self.tableWidget) * 0.8)) def update_prev_next(self): prev, _next = self._report.prev_next_avail() diff --git a/task_completer.py b/task_completer.py index 358dc5b..fec86d1 100644 --- a/task_completer.py +++ b/task_completer.py @@ -24,7 +24,7 @@ class TaskCompleter(QCompleter): self.search_url = os.path.join(self.config.jira_url, "rest/api/2/search") self.text = "" self.response_text = "" - self.model_string_list = [] + self.model_data = set() self.escalate = False self.update_timer = QTimer(self) self.update_timer.timeout.connect(self.process_response) @@ -39,10 +39,10 @@ class TaskCompleter(QCompleter): if result_dict["response_text"] == self.text: if self.text == self.response_text: self.response_text = result_dict["response_text"] - self.model_string_list = result_dict["result"] + self.model_data = set(result_dict["result"]) else: - self.model_string_list += result_dict["result"] - self.model().setStringList(self.model_string_list) + self.model_data = self.model_data.union(set(result_dict["result"])) + self.model().setStringList(self.model_data) self.complete() except Empty: return diff --git a/util.py b/util.py new file mode 100644 index 0000000..012bc77 --- /dev/null +++ b/util.py @@ -0,0 +1,6 @@ +def get_screen_height(qobject): + if hasattr(qobject, "screen"): + return qobject.screen().size().height() + else: + print("unable to detect screen height falling back to default value of 1080") + return 1080