Allow for flipped menu
This commit is contained in:
parent
c8cc0883ce
commit
3dd13854cb
@ -42,5 +42,10 @@ class Config:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def tray_theme(self):
|
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"
|
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:
|
else:
|
||||||
icon = get_icon("appointment-new")
|
icon = get_icon("appointment-new")
|
||||||
|
|
||||||
|
self.menu_flipped = config.flip_menu
|
||||||
|
|
||||||
self.menu = QtWidgets.QMenu(None)
|
self.menu = QtWidgets.QMenu(None)
|
||||||
|
|
||||||
self.import_task = ImportTask(config, None)
|
self.import_task = ImportTask(config, None)
|
||||||
@ -90,48 +92,51 @@ class App:
|
|||||||
self.tasks.update_jira_task_usage(task)
|
self.tasks.update_jira_task_usage(task)
|
||||||
|
|
||||||
def update_tray_menu(self):
|
def update_tray_menu(self):
|
||||||
def add_tasks(tasks):
|
menu_items = []
|
||||||
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"))
|
|
||||||
|
|
||||||
tmp_action = self.menu.addAction("tmp")
|
tmp_action = self.menu.addAction("tmp")
|
||||||
action_height = self.menu.actionGeometry(tmp_action).height()
|
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()
|
self.menu.clear()
|
||||||
add_tasks(self.tasks.tasks)
|
add_tasks(self.tasks.tasks)
|
||||||
|
|
||||||
self.menu.addSeparator()
|
menu_items.append((1, None))
|
||||||
already_taken = (len(self.tasks.tasks) + 4) * action_height
|
already_taken = (len(self.tasks.tasks) + 4) * action_height
|
||||||
available_space = get_screen_height(self.menu) * 0.8 - already_taken
|
available_space = get_screen_height(self.menu) * 0.8 - already_taken
|
||||||
jira_entry_count = int(available_space // action_height)
|
jira_entry_count = int(available_space // action_height)
|
||||||
add_tasks(self.tasks.jira_tasks[-jira_entry_count:])
|
add_tasks(self.tasks.jira_tasks[-jira_entry_count:])
|
||||||
|
|
||||||
self.menu.addSeparator()
|
menu_items.append((1, None))
|
||||||
add_tasks(["Pause"])
|
add_tasks(["Pause"])
|
||||||
if self.active_task == "Nothing":
|
if self.active_task == "Nothing":
|
||||||
add_tasks(["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")
|
menu_items.append((1, None))
|
||||||
new_action.triggered.connect(self.import_task.show)
|
|
||||||
|
|
||||||
edit_action = self.menu.addAction("Edit tasks")
|
menu_items.append(("Close", self.app.quit))
|
||||||
edit_action.triggered.connect(self.edit_tasks)
|
|
||||||
|
|
||||||
report_action = self.menu.addAction("Report")
|
if self.menu_flipped:
|
||||||
report_action.triggered.connect(self.reportDialog.show)
|
menu_items.reverse()
|
||||||
|
|
||||||
worklog_action = self.menu.addAction("Worklog")
|
seps = 0
|
||||||
worklog_action.triggered.connect(self.worklogDialog.show)
|
for item in menu_items:
|
||||||
|
if item[0] == 1:
|
||||||
self.menu.addSeparator()
|
self.menu.addSeparator()
|
||||||
|
seps += 1
|
||||||
exit_action = self.menu.addAction("Close")
|
continue
|
||||||
exit_action.triggered.connect(self.app.quit)
|
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):
|
def sigterm_handler(self, signo, _frame):
|
||||||
print(f'handling signal "{signal.strsignal(signo)}"')
|
print(f'handling signal "{signal.strsignal(signo)}"')
|
||||||
|
Loading…
Reference in New Issue
Block a user