Improvy proves.
This commit is contained in:
parent
ba18e2dc95
commit
828d797a86
17
data.py
17
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
|
||||
|
7
main.py
7
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):
|
||||
|
@ -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,6 +53,9 @@ 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):
|
||||
@ -77,4 +80,3 @@ class Report(QtWidgets.QDialog):
|
||||
@tasks.setter
|
||||
def tasks(self, tasks):
|
||||
self.list.setStringList(tasks)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user