This commit is contained in:
Fabian 2021-11-30 18:38:20 +01:00
parent 2e348e68b4
commit aebdf2d7c9
4 changed files with 20 additions and 43 deletions

View File

@ -290,22 +290,11 @@ class Log:
return None return None
return log[-1][1] return log[-1][1]
def report(self):
return Report(self._data)
def worklog(self):
return Worklog(self._data)
# TODO remove
dEV = False
def summary(lcd: LogCommentsData, pdate: date) -> Tuple[Dict[str, timedelta], timedelta]: def summary(lcd: LogCommentsData, pdate: date) -> Tuple[Dict[str, timedelta], timedelta]:
log = lcd.get_log(pdate) log = lcd.get_log(pdate)
if dEV: if pdate == date.today():
if pdate == date.today(): log.append((datetime.now(), "End"))
log.append((datetime.now(), "End"))
tasks_sums = {} tasks_sums = {}
total_sum = timedelta() total_sum = timedelta()
for i, le in enumerate(log): for i, le in enumerate(log):

View File

@ -13,10 +13,10 @@ except ImportError:
from PySide2 import QtCore, QtWidgets from PySide2 import QtCore, QtWidgets
PYSIDE_6 = False PYSIDE_6 = False
from fime.data import Tasks, Log, Data, LogCommentsData, Worklog from fime.data import Tasks, Log, Data, LogCommentsData, Worklog, Report
from fime.exceptions import FimeException from fime.exceptions import FimeException
from fime.import_task import ImportTask from fime.import_task import ImportTask
from fime.report import Report from fime.report import ReportDialog
from fime.task_edit import TaskEdit from fime.task_edit import TaskEdit
from fime.util import get_screen_height, get_icon from fime.util import get_screen_height, get_icon
@ -29,7 +29,6 @@ class App:
data = Data() data = Data()
self.tasks = Tasks(data) self.tasks = Tasks(data)
lcd = LogCommentsData(data) lcd = LogCommentsData(data)
self.worklogData = Worklog(lcd)
self.log = Log(lcd) self.log = Log(lcd)
self._active_task = self.log.last_log() or "Nothing" self._active_task = self.log.last_log() or "Nothing"
@ -47,11 +46,11 @@ class App:
self.taskEdit = TaskEdit(None) self.taskEdit = TaskEdit(None)
self.taskEdit.accepted.connect(self.tasks_edited) self.taskEdit.accepted.connect(self.tasks_edited)
self.reportDialog = Report(self.tasks, None) self.reportDialog = ReportDialog(self.tasks, Report(lcd), None)
self.reportDialog.accepted.connect(self.report_done) self.reportDialog.accepted.connect(self.log_edited)
self.worklogDialog = WorklogDialog(config, None) self.worklogDialog = WorklogDialog(config, Worklog(lcd), None)
self.worklogDialog.accepted.connect(self.report_done) self.worklogDialog.accepted.connect(self.log_edited)
self.tray = QtWidgets.QSystemTrayIcon() self.tray = QtWidgets.QSystemTrayIcon()
self.tray.setIcon(icon) self.tray.setIcon(icon)
@ -72,7 +71,7 @@ class App:
self.update_tray_menu() self.update_tray_menu()
@QtCore.Slot() @QtCore.Slot()
def report_done(self): def log_edited(self):
self.active_task = self.log.last_log() or "Nothing" self.active_task = self.log.last_log() or "Nothing"
@property @property
@ -123,10 +122,10 @@ class App:
edit_action.triggered.connect(self.edit_tasks) edit_action.triggered.connect(self.edit_tasks)
report_action = self.menu.addAction("Report") report_action = self.menu.addAction("Report")
report_action.triggered.connect(self.report) report_action.triggered.connect(self.reportDialog.show)
worklog_action = self.menu.addAction("Worklog") worklog_action = self.menu.addAction("Worklog")
worklog_action.triggered.connect(self.worklog) worklog_action.triggered.connect(self.worklogDialog.show)
self.menu.addSeparator() self.menu.addSeparator()
@ -149,16 +148,6 @@ class App:
else: else:
self.app.exec_() self.app.exec_()
@QtCore.Slot()
def report(self):
self.reportDialog.set_data(self.log.report())
self.reportDialog.show()
@QtCore.Slot()
def worklog(self):
self.worklogDialog.set_data(self.worklogData)
self.worklogDialog.show()
@QtCore.Slot() @QtCore.Slot()
def new_task_slot(self): def new_task_slot(self):
self.import_task.reset_task_text() self.import_task.reset_task_text()

View File

@ -11,7 +11,7 @@ from fime.data import Tasks, Report
from fime.util import get_screen_height, get_icon, EditStartedDetector from fime.util import get_screen_height, get_icon, EditStartedDetector
class Report(QtWidgets.QDialog): class ReportDialog(QtWidgets.QDialog):
class TaskItemCompleter(EditStartedDetector): class TaskItemCompleter(EditStartedDetector):
def __init__(self, tasks: Tasks, parent=None): def __init__(self, tasks: Tasks, parent=None):
super().__init__(parent) super().__init__(parent)
@ -25,9 +25,9 @@ class Report(QtWidgets.QDialog):
editor.setCompleter(completer) editor.setCompleter(completer)
return editor return editor
def __init__(self, tasks: Tasks, parent, *args, **kwargs): def __init__(self, tasks: Tasks, report: Report, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs) super().__init__(parent, *args, **kwargs)
self._report: Optional[Report] = None self._report = report
self._report_data: Optional[List[List[str]]] = None self._report_data: Optional[List[List[str]]] = None
self._changing_items = False self._changing_items = False
self._new_log_task = "" self._new_log_task = ""
@ -41,7 +41,7 @@ class Report(QtWidgets.QDialog):
self.tableWidget.setColumnCount(3) self.tableWidget.setColumnCount(3)
self.tableWidget.setHorizontalHeaderLabels(["Task", "Start time", "Duration"]) self.tableWidget.setHorizontalHeaderLabels(["Task", "Start time", "Duration"])
self.tableWidget.cellChanged.connect(self.cell_changed) self.tableWidget.cellChanged.connect(self.cell_changed)
taskItemCompleter = Report.TaskItemCompleter(tasks, self) taskItemCompleter = ReportDialog.TaskItemCompleter(tasks, self)
taskItemCompleter.editStarted.connect(self.disable_buttons) taskItemCompleter.editStarted.connect(self.disable_buttons)
taskItemCompleter.editFinished.connect(self.enable_buttons) taskItemCompleter.editFinished.connect(self.enable_buttons)
self.tableWidget.setItemDelegateForColumn(0, taskItemCompleter) self.tableWidget.setItemDelegateForColumn(0, taskItemCompleter)
@ -97,8 +97,7 @@ class Report(QtWidgets.QDialog):
layout.addLayout(blayout) layout.addLayout(blayout)
self.setLayout(layout) self.setLayout(layout)
def set_data(self, data: Report): def showEvent(self, _):
self._report = data
self.update_title() self.update_title()
self.refresh_table() self.refresh_table()
self.update_prev_next() self.update_prev_next()

View File

@ -1,6 +1,7 @@
from functools import reduce, partial from functools import reduce, partial
from typing import Optional, List, Tuple from typing import Optional, List, Tuple
from fime.config import Config
from fime.data import Worklog, duration_to_str from fime.data import Worklog, duration_to_str
from fime.progressindicator import ProgressIndicator from fime.progressindicator import ProgressIndicator
from fime.task_completer import TaskCompleter from fime.task_completer import TaskCompleter
@ -92,13 +93,13 @@ class WorklogDialog(QtWidgets.QDialog):
if not self.return_: if not self.return_:
self.edit_finished_row.emit(row) self.edit_finished_row.emit(row)
def __init__(self, config, parent, *args, **kwargs): def __init__(self, config: Config, worklog: Worklog, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs) super().__init__(parent, *args, **kwargs)
self.rest = WorklogRest(config) self.rest = WorklogRest(config)
self._changing_items = False self._changing_items = False
self._worklog: Optional[Worklog] = None self._worklog = worklog
self._worklog_data: List[List[str]] = [] self._worklog_data: List[List[str]] = []
self._statuses: List[Tuple[Status, str]] = [] self._statuses: List[Tuple[Status, str]] = []
self.row_height = None self.row_height = None
@ -170,8 +171,7 @@ class WorklogDialog(QtWidgets.QDialog):
self.update_timer.setInterval(500) self.update_timer.setInterval(500)
self.update_timer.timeout.connect(self.update_statuses) self.update_timer.timeout.connect(self.update_statuses)
def set_data(self, worklog: Worklog): def showEvent(self, _):
self._worklog = worklog
self.rest.purge_cache() self.rest.purge_cache()
self.update_all() self.update_all()