Allow for flipped menu

This commit is contained in:
Fabian 2022-02-02 21:22:50 +01:00
parent c8cc0883ce
commit 3dd13854cb
2 changed files with 34 additions and 24 deletions

View File

@ -42,5 +42,10 @@ class Config:
@property
def tray_theme(self):
val = dequotify(self._configparser.get("DEFAULT", "tray_theme", fallback="dark"))
val = dequotify(self._configparser.get("DEFAULT", "tray_theme", fallback="dark")).lower()
return val if val in ["light", "dark"] else "dark"
@property
def flip_menu(self):
val = dequotify(self._configparser.get("DEFAULT", "flip_menu", fallback="no")).lower()
return val in ["yes", "true", "1"]

View File

@ -38,6 +38,8 @@ class App:
else:
icon = get_icon("appointment-new")
self.menu_flipped = config.flip_menu
self.menu = QtWidgets.QMenu(None)
self.import_task = ImportTask(config, None)
@ -90,48 +92,51 @@ class App:
self.tasks.update_jira_task_usage(task)
def update_tray_menu(self):
def add_tasks(tasks):
for t in tasks:
action = self.menu.addAction(t)
action.triggered.connect(partial(self.change_task, t))
if t == self.active_task:
action.setIcon(get_icon("go-next"))
menu_items = []
tmp_action = self.menu.addAction("tmp")
action_height = self.menu.actionGeometry(tmp_action).height()
def add_tasks(tasks):
for t in tasks:
menu_items.append((t, partial(self.change_task, t)))
self.menu.clear()
add_tasks(self.tasks.tasks)
self.menu.addSeparator()
menu_items.append((1, None))
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)
add_tasks(self.tasks.jira_tasks[-jira_entry_count:])
self.menu.addSeparator()
menu_items.append((1, None))
add_tasks(["Pause"])
if self.active_task == "Nothing":
add_tasks(["Nothing"])
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(("Report", self.reportDialog.show))
menu_items.append(("Worklog", self.worklogDialog.show))
menu_items.append((1, None))
menu_items.append(("Close", self.app.quit))
if self.menu_flipped:
menu_items.reverse()
seps = 0
for item in menu_items:
if item[0] == 1:
self.menu.addSeparator()
new_action = self.menu.addAction("Import Jira task")
new_action.triggered.connect(self.import_task.show)
edit_action = self.menu.addAction("Edit tasks")
edit_action.triggered.connect(self.edit_tasks)
report_action = self.menu.addAction("Report")
report_action.triggered.connect(self.reportDialog.show)
worklog_action = self.menu.addAction("Worklog")
worklog_action.triggered.connect(self.worklogDialog.show)
self.menu.addSeparator()
exit_action = self.menu.addAction("Close")
exit_action.triggered.connect(self.app.quit)
seps += 1
continue
action = self.menu.addAction(item[0])
if item[0] == self.active_task and seps <= 2:
action.setIcon(get_icon("go-next"))
action.triggered.connect(item[1])
def sigterm_handler(self, signo, _frame):
print(f'handling signal "{signal.strsignal(signo)}"')