From 828d797a86c9a15a5d1f4f430f7970bc4bff4340 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Mon, 24 Feb 2020 13:16:17 +0100 Subject: [PATCH] Improvy proves. --- data.py | 17 ++++++++++++++--- main.py | 7 +++---- report.py | 10 ++++++---- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/data.py b/data.py index 7f92374..769e79d 100644 --- a/data.py +++ b/data.py @@ -2,7 +2,7 @@ import os import json import base64 import atexit -from datetime import datetime, date, time +from datetime import datetime, date, timedelta from threading import Thread, Event from collections.abc import MutableMapping @@ -114,7 +114,9 @@ class Log: def __init__(self): self._data = Data() - def log(self, task, ptime=datetime.now()): + def log(self, task, ptime=None): + if ptime is None: + ptime = datetime.now() month = self._data.setdefault(ptime.strftime("%Y-%m"), {}) month.setdefault(ptime.strftime("%d"), [])\ .append(f"{ptime.strftime('%H:%M:%S')} {base64.b64encode(task.encode('utf-8')).decode('utf-8')}") @@ -135,6 +137,7 @@ class Log: tmp.append((task, start_time)) ret = [] + dsum = timedelta() for i, t in enumerate(tmp): task, start_time = t if i < len(tmp) - 1: @@ -142,5 +145,13 @@ class Log: else: end_time = datetime.now() duration = end_time - start_time - ret.append((task, start_time, duration)) + dsum += duration + dhours, rem = divmod(duration.seconds, 3600) + dmins, _ = divmod(rem, 60) + ret.append((task, start_time.strftime("%H:%M"), f"{dhours:02d}:{dmins:02d}")) + + ret.append(("", "", "")) + dhours, rem = divmod(dsum.seconds, 3600) + dmins, _ = divmod(rem, 60) + ret.append(("Sum", "", f"{dhours:02d}:{dmins:02d}")) return ret diff --git a/main.py b/main.py index 3ca3d38..ecd721b 100644 --- a/main.py +++ b/main.py @@ -33,7 +33,7 @@ class App: self.taskEdit = TaskEdit(None) self.taskEdit.accepted.connect(self.tasks_edited) - self.report = Report(None) + self.reportDialog = Report(None) @QtCore.Slot() def tasks_edited(self): @@ -80,12 +80,11 @@ class App: signal.signal(signal.SIGTERM, self.sigterm_handler) signal.signal(signal.SIGINT, self.sigterm_handler) self.app.exec_() - sys.exit() @QtCore.Slot() def report(self): - self.report.set_data(self.log.report()) - self.report.show() + self.reportDialog.set_data(self.log.report()) + self.reportDialog.show() @QtCore.Slot() def edit_tasks(self): diff --git a/report.py b/report.py index 9fc242b..05f89af 100644 --- a/report.py +++ b/report.py @@ -43,8 +43,8 @@ class Report(QtWidgets.QDialog): for row, _ in enumerate(data): self.tableWidget.setItem(row, 0, QtWidgets.QTableWidgetItem(data[row][0])) - self.tableWidget.setItem(row, 1, QtWidgets.QTableWidgetItem(str(data[row][1]))) - self.tableWidget.setItem(row, 2, QtWidgets.QTableWidgetItem(str(data[row][2]))) + self.tableWidget.setItem(row, 1, QtWidgets.QTableWidgetItem(data[row][1])) + self.tableWidget.setItem(row, 2, QtWidgets.QTableWidgetItem(data[row][2])) self.tableWidget.resizeColumnsToContents() @@ -53,13 +53,16 @@ class Report(QtWidgets.QDialog): min_width += self.header.sectionSize(i) self.tableWidget.setMinimumWidth(min_width * 1.33) self.header.setSectionResizeMode(QtWidgets.QHeaderView.Stretch) + if self.tableWidget.rowCount() > 4: + self.tableWidget.setMinimumHeight(min((self.tableWidget.rowCount() + 2) * self.tableWidget.rowHeight(0), + self.tableWidget.screen().size().height() * 0.8)) @QtCore.Slot() def new_task(self): l = self.list.stringList() l.append("") self.list.setStringList(l) - i = self.list.index(len(l)-1) + i = self.list.index(len(l) - 1) self.tableView.setCurrentIndex(i) self.tableView.edit(i) @@ -77,4 +80,3 @@ class Report(QtWidgets.QDialog): @tasks.setter def tasks(self, tasks): self.list.setStringList(tasks) -