Allow for flipped menu
This commit is contained in:
parent
c8cc0883ce
commit
3dd13854cb
@ -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"]
|
||||
|
@ -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"])
|
||||
|
||||
self.menu.addSeparator()
|
||||
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))
|
||||
|
||||
new_action = self.menu.addAction("Import Jira task")
|
||||
new_action.triggered.connect(self.import_task.show)
|
||||
menu_items.append((1, None))
|
||||
|
||||
edit_action = self.menu.addAction("Edit tasks")
|
||||
edit_action.triggered.connect(self.edit_tasks)
|
||||
menu_items.append(("Close", self.app.quit))
|
||||
|
||||
report_action = self.menu.addAction("Report")
|
||||
report_action.triggered.connect(self.reportDialog.show)
|
||||
if self.menu_flipped:
|
||||
menu_items.reverse()
|
||||
|
||||
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 = 0
|
||||
for item in menu_items:
|
||||
if item[0] == 1:
|
||||
self.menu.addSeparator()
|
||||
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)}"')
|
||||
|
Loading…
Reference in New Issue
Block a user