2020-02-19 22:12:56 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import signal
|
|
|
|
from functools import partial
|
|
|
|
|
|
|
|
from PySide2 import QtCore, QtGui, QtWidgets
|
2021-11-16 18:57:09 +00:00
|
|
|
from PySide2.QtWidgets import QMessageBox
|
2020-02-19 22:12:56 +00:00
|
|
|
|
2021-11-17 02:12:22 +00:00
|
|
|
from data import Tasks, Log, Data
|
2021-11-16 18:57:09 +00:00
|
|
|
from exceptions import FimeFrackingException
|
2021-11-17 03:29:51 +00:00
|
|
|
from import_task import ImportTask
|
2020-02-19 22:12:56 +00:00
|
|
|
from task_edit import TaskEdit
|
2020-02-20 14:22:40 +00:00
|
|
|
from report import Report
|
2021-11-17 03:27:59 +00:00
|
|
|
from util import get_screen_height
|
2020-02-19 22:12:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
class App:
|
|
|
|
def __init__(self):
|
|
|
|
self.app = QtWidgets.QApplication(sys.argv)
|
|
|
|
|
2021-11-17 02:12:22 +00:00
|
|
|
data = Data()
|
|
|
|
self.tasks = Tasks(data)
|
|
|
|
self.log = Log(data)
|
2021-11-17 03:27:59 +00:00
|
|
|
self._active_task = self.log.last_log() or "Nothing"
|
2020-02-19 22:12:56 +00:00
|
|
|
|
|
|
|
icon = QtGui.QIcon.fromTheme("appointment-new")
|
|
|
|
|
|
|
|
self.menu = QtWidgets.QMenu()
|
|
|
|
|
2021-11-17 03:29:51 +00:00
|
|
|
self.import_task = ImportTask(None)
|
|
|
|
self.import_task.accepted.connect(self.new_task_imported)
|
2021-11-16 18:57:09 +00:00
|
|
|
|
|
|
|
self.taskEdit = TaskEdit(None)
|
|
|
|
self.taskEdit.accepted.connect(self.tasks_edited)
|
|
|
|
|
2021-11-17 02:12:22 +00:00
|
|
|
self.reportDialog = Report(self.tasks, None)
|
2021-11-16 18:57:09 +00:00
|
|
|
self.reportDialog.accepted.connect(self.report_done)
|
|
|
|
|
2020-02-19 22:12:56 +00:00
|
|
|
self.tray = QtWidgets.QSystemTrayIcon()
|
|
|
|
self.tray.setIcon(icon)
|
|
|
|
self.tray.setContextMenu(self.menu)
|
|
|
|
self.tray.show()
|
|
|
|
self.tray.setToolTip("fimefracking")
|
|
|
|
self.update_tray_menu()
|
|
|
|
|
2021-11-16 18:57:09 +00:00
|
|
|
@QtCore.Slot()
|
2021-11-17 02:12:22 +00:00
|
|
|
def new_task_imported(self):
|
2021-11-17 03:29:51 +00:00
|
|
|
if self.import_task.task_text:
|
|
|
|
self.tasks.add_jira_task(self.import_task.task_text)
|
2021-11-17 02:12:22 +00:00
|
|
|
self.update_tray_menu()
|
2020-02-20 14:22:40 +00:00
|
|
|
|
2020-02-19 22:12:56 +00:00
|
|
|
@QtCore.Slot()
|
|
|
|
def tasks_edited(self):
|
|
|
|
self.tasks.tasks = self.taskEdit.tasks
|
|
|
|
self.update_tray_menu()
|
|
|
|
|
2020-02-24 14:41:08 +00:00
|
|
|
@QtCore.Slot()
|
|
|
|
def report_done(self):
|
2020-02-24 15:54:28 +00:00
|
|
|
self.active_task = self.log.last_log() or "Nothing"
|
2021-11-17 03:27:59 +00:00
|
|
|
|
|
|
|
@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)
|
2020-02-24 14:41:08 +00:00
|
|
|
self.update_tray_menu()
|
|
|
|
|
2020-02-19 22:12:56 +00:00
|
|
|
def change_task(self, task):
|
2020-02-20 14:22:40 +00:00
|
|
|
self.active_task = task
|
|
|
|
self.log.log(task)
|
2020-02-19 22:12:56 +00:00
|
|
|
|
|
|
|
def update_tray_menu(self):
|
2021-11-17 02:12:22 +00:00
|
|
|
def add_tasks(tasks):
|
2021-11-17 03:27:59 +00:00
|
|
|
action_height = None
|
2021-11-17 02:12:22 +00:00
|
|
|
for t in tasks:
|
|
|
|
a = self.menu.addAction(t)
|
2021-11-17 03:27:59 +00:00
|
|
|
action_height = self.menu.actionGeometry(a).height()
|
2021-11-17 02:12:22 +00:00
|
|
|
a.triggered.connect(partial(self.change_task, t))
|
|
|
|
if t == self.active_task:
|
|
|
|
a.setIcon(QtGui.QIcon.fromTheme("go-next"))
|
2021-11-17 03:27:59 +00:00
|
|
|
return action_height
|
2021-11-17 02:12:22 +00:00
|
|
|
|
2020-02-19 22:12:56 +00:00
|
|
|
self.menu.clear()
|
|
|
|
|
2021-11-17 03:27:59 +00:00
|
|
|
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)
|
2021-11-17 02:12:22 +00:00
|
|
|
|
|
|
|
self.menu.addSeparator()
|
2021-11-17 03:27:59 +00:00
|
|
|
add_tasks(self.tasks.jira_tasks[:jira_entry_count])
|
2021-11-17 02:12:22 +00:00
|
|
|
|
|
|
|
self.menu.addSeparator()
|
|
|
|
add_tasks(["Pause"])
|
|
|
|
if self.active_task == "Nothing":
|
|
|
|
add_tasks(["Nothing"])
|
2020-02-19 22:12:56 +00:00
|
|
|
|
|
|
|
self.menu.addSeparator()
|
|
|
|
|
2021-11-17 02:12:22 +00:00
|
|
|
new_action = self.menu.addAction("Import Jira task")
|
2021-11-16 22:55:58 +00:00
|
|
|
new_action.triggered.connect(self.new_task_slot)
|
2021-11-16 18:57:09 +00:00
|
|
|
|
2021-11-16 22:55:58 +00:00
|
|
|
edit_action = self.menu.addAction("Edit tasks")
|
|
|
|
edit_action.triggered.connect(self.edit_tasks)
|
2020-02-19 22:12:56 +00:00
|
|
|
|
|
|
|
report_action = self.menu.addAction("Report")
|
|
|
|
report_action.triggered.connect(self.report)
|
|
|
|
|
|
|
|
self.menu.addSeparator()
|
|
|
|
|
|
|
|
exit_action = self.menu.addAction("Close")
|
|
|
|
exit_action.triggered.connect(self.app.quit)
|
|
|
|
|
|
|
|
def sigterm_handler(self, _signo, _frame):
|
|
|
|
self.app.quit()
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
timer = QtCore.QTimer()
|
|
|
|
# interrupt event loop regularly for signal handling
|
|
|
|
timer.timeout.connect(lambda: None)
|
|
|
|
timer.start(500)
|
|
|
|
signal.signal(signal.SIGTERM, self.sigterm_handler)
|
|
|
|
signal.signal(signal.SIGINT, self.sigterm_handler)
|
|
|
|
self.app.exec_()
|
|
|
|
|
|
|
|
@QtCore.Slot()
|
|
|
|
def report(self):
|
2020-02-24 12:16:17 +00:00
|
|
|
self.reportDialog.set_data(self.log.report())
|
|
|
|
self.reportDialog.show()
|
2020-02-19 22:12:56 +00:00
|
|
|
|
2021-11-16 22:55:58 +00:00
|
|
|
@QtCore.Slot()
|
|
|
|
def new_task_slot(self):
|
2021-11-17 03:29:51 +00:00
|
|
|
self.import_task.reset_task_text()
|
|
|
|
self.import_task.show()
|
2021-11-16 22:55:58 +00:00
|
|
|
|
2020-02-19 22:12:56 +00:00
|
|
|
@QtCore.Slot()
|
|
|
|
def edit_tasks(self):
|
|
|
|
self.taskEdit.tasks = self.tasks.tasks
|
|
|
|
self.taskEdit.show()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-11-16 18:57:09 +00:00
|
|
|
try:
|
|
|
|
app = App()
|
|
|
|
app.run()
|
|
|
|
except FimeFrackingException as e:
|
|
|
|
QMessageBox.critical(None, "Error", str(e), QMessageBox.Ok)
|