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
|
|
|
|
from new_task import NewTask
|
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
|
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)
|
2020-02-24 15:54:28 +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-16 18:57:09 +00:00
|
|
|
self.new_task = NewTask(None)
|
2021-11-17 02:12:22 +00:00
|
|
|
self.new_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):
|
|
|
|
if self.new_task.task_text:
|
|
|
|
self.tasks.add_jira_task(self.new_task.task_text)
|
|
|
|
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"
|
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
|
2020-02-24 15:54:28 +00:00
|
|
|
if task == "Nothing":
|
2020-02-24 15:22:41 +00:00
|
|
|
return
|
2020-02-20 14:22:40 +00:00
|
|
|
self.log.log(task)
|
2020-02-19 22:12:56 +00:00
|
|
|
self.update_tray_menu()
|
|
|
|
|
|
|
|
def update_tray_menu(self):
|
2021-11-17 02:12:22 +00:00
|
|
|
def add_tasks(tasks):
|
|
|
|
for t in tasks:
|
|
|
|
a = self.menu.addAction(t)
|
|
|
|
a.triggered.connect(partial(self.change_task, t))
|
|
|
|
if t == self.active_task:
|
|
|
|
a.setIcon(QtGui.QIcon.fromTheme("go-next"))
|
|
|
|
|
2020-02-19 22:12:56 +00:00
|
|
|
self.menu.clear()
|
|
|
|
|
2021-11-17 02:12:22 +00:00
|
|
|
add_tasks(self.tasks.tasks)
|
|
|
|
|
|
|
|
self.menu.addSeparator()
|
|
|
|
add_tasks(self.tasks.jira_tasks)
|
|
|
|
|
|
|
|
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):
|
|
|
|
self.new_task.reset_task_text()
|
|
|
|
self.new_task.show()
|
|
|
|
|
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)
|