Compare commits
3 Commits
233ca3fcee
...
2d3c06be67
Author | SHA1 | Date | |
---|---|---|---|
|
2d3c06be67 | ||
|
1d3f6384e2 | ||
|
5b62e8684d |
11
data.py
11
data.py
@ -179,14 +179,14 @@ class Report:
|
||||
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([task, start_time.strftime("%H:%M"), f"{dhours:02d}:{dmins:02d}"])
|
||||
else:
|
||||
ret.append((task, start_time.strftime("%H:%M"), ""))
|
||||
ret.append([task, start_time.strftime("%H:%M"), ""])
|
||||
|
||||
ret.append(("", "", ""))
|
||||
ret.append(["", "", ""])
|
||||
dhours, rem = divmod(dsum.seconds, 3600)
|
||||
dmins, _ = divmod(rem, 60)
|
||||
ret.append(("Sum", "", f"{dhours:02d}:{dmins:02d}"))
|
||||
ret.append(["Sum", "", f"{dhours:02d}:{dmins:02d}"])
|
||||
return ret
|
||||
|
||||
def save(self, report):
|
||||
@ -216,3 +216,6 @@ class Report:
|
||||
|
||||
def next(self):
|
||||
self._date = self._date + timedelta(days=1)
|
||||
|
||||
def date(self):
|
||||
return self._date.strftime("%Y-%m-%d")
|
||||
|
77
report.py
77
report.py
@ -1,11 +1,16 @@
|
||||
from PySide2 import QtCore, QtGui, QtWidgets
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class Report(QtWidgets.QDialog):
|
||||
def __init__(self, parent, *args, **kwargs):
|
||||
super().__init__(parent, *args, **kwargs)
|
||||
self._report = None
|
||||
self._report_data = None
|
||||
self._changing_items = False
|
||||
self._new_log_task = ""
|
||||
self._new_log_pos = -1
|
||||
|
||||
self.setWindowTitle("Report")
|
||||
|
||||
@ -13,6 +18,7 @@ class Report(QtWidgets.QDialog):
|
||||
self.tableWidget.verticalHeader().hide()
|
||||
self.tableWidget.setColumnCount(3)
|
||||
self.tableWidget.setHorizontalHeaderLabels(["Task", "Start time", "Duration"])
|
||||
self.tableWidget.cellChanged.connect(self.cell_changed)
|
||||
self.header = QtWidgets.QHeaderView(QtCore.Qt.Orientation.Horizontal)
|
||||
self.tableWidget.setHorizontalHeader(self.header)
|
||||
|
||||
@ -26,6 +32,11 @@ class Report(QtWidgets.QDialog):
|
||||
self.next_button.setIcon(QtGui.QIcon.fromTheme("arrow-right"))
|
||||
self.next_button.pressed.connect(self.next)
|
||||
|
||||
new_button = QtWidgets.QPushButton()
|
||||
new_button.setText("New item")
|
||||
new_button.setIcon(QtGui.QIcon.fromTheme("list-add"))
|
||||
new_button.pressed.connect(self.new_log)
|
||||
|
||||
del_button = QtWidgets.QPushButton()
|
||||
del_button.setText("Delete item")
|
||||
del_button.setIcon(QtGui.QIcon.fromTheme("list-remove"))
|
||||
@ -39,6 +50,7 @@ class Report(QtWidgets.QDialog):
|
||||
blayout = QtWidgets.QHBoxLayout()
|
||||
blayout.addWidget(self.previous_button)
|
||||
blayout.addWidget(self.next_button)
|
||||
blayout.addWidget(new_button)
|
||||
blayout.addWidget(del_button)
|
||||
blayout.addWidget(ok_button)
|
||||
|
||||
@ -49,13 +61,21 @@ class Report(QtWidgets.QDialog):
|
||||
|
||||
def set_data(self, data):
|
||||
self._report = data
|
||||
self._report_data = self._report.report()
|
||||
self.update_title()
|
||||
self.refresh_table()
|
||||
self.update_prev_next()
|
||||
|
||||
def save(self):
|
||||
self._report.save(self._report_data)
|
||||
|
||||
def update_title(self):
|
||||
self.setWindowTitle(f"Report {self._report.date()}")
|
||||
|
||||
def refresh_table(self):
|
||||
self._report_data = self._report.report()
|
||||
self.tableWidget.setRowCount(len(self._report_data))
|
||||
|
||||
self._changing_items = True
|
||||
for row, _ in enumerate(self._report_data):
|
||||
item0 = QtWidgets.QTableWidgetItem(self._report_data[row][0])
|
||||
self.tableWidget.setItem(row, 0, item0)
|
||||
@ -63,10 +83,12 @@ class Report(QtWidgets.QDialog):
|
||||
self.tableWidget.setItem(row, 1, item1)
|
||||
item2 = QtWidgets.QTableWidgetItem(self._report_data[row][2])
|
||||
self.tableWidget.setItem(row, 2, item2)
|
||||
item0.setFlags(item0.flags() & QtCore.Qt.ItemIsEnabled)
|
||||
item2.setFlags(item2.flags() & QtCore.Qt.ItemIsEnabled)
|
||||
if row > len(self._report_data) - 4:
|
||||
if row > len(self._report_data) - 3:
|
||||
item1.setFlags(item1.flags() & QtCore.Qt.ItemIsEnabled)
|
||||
if row > len(self._report_data) - 4:
|
||||
item0.setFlags(item0.flags() & QtCore.Qt.ItemIsEnabled)
|
||||
self._changing_items = False
|
||||
|
||||
self.tableWidget.resizeColumnsToContents()
|
||||
|
||||
@ -90,25 +112,64 @@ class Report(QtWidgets.QDialog):
|
||||
if row > len(self._report_data) - 4:
|
||||
return
|
||||
del self._report_data[row]
|
||||
self.save()
|
||||
self.refresh_table()
|
||||
|
||||
@QtCore.Slot()
|
||||
def new_log(self):
|
||||
after = min(self.tableWidget.currentItem().row(), len(self._report_data) - 4) + 1
|
||||
self._new_log_pos = after
|
||||
self.tableWidget.insertRow(after)
|
||||
self.tableWidget.setCurrentCell(after, 0)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.tableWidget.setItem(after, 0, item)
|
||||
self.tableWidget.editItem(item)
|
||||
|
||||
@QtCore.Slot()
|
||||
def _accept(self):
|
||||
self._report.save(self._report_data)
|
||||
self.save()
|
||||
self.accept()
|
||||
|
||||
@QtCore.Slot()
|
||||
def previous(self):
|
||||
self._report.save(self._report_data)
|
||||
self.save()
|
||||
self._report.previous()
|
||||
self._report_data = self._report.report()
|
||||
self.update_title()
|
||||
self.refresh_table()
|
||||
self.update_prev_next()
|
||||
|
||||
@QtCore.Slot()
|
||||
def next(self):
|
||||
self._report.save(self._report_data)
|
||||
self.save()
|
||||
self._report.next()
|
||||
self._report_data = self._report.report()
|
||||
self.update_title()
|
||||
self.refresh_table()
|
||||
self.update_prev_next()
|
||||
|
||||
@QtCore.Slot()
|
||||
def cell_changed(self, row, column):
|
||||
if self._changing_items:
|
||||
return
|
||||
if column == 2:
|
||||
self.tableWidget.item(row, column).setText(self._report_data[row][column])
|
||||
return
|
||||
item = self.tableWidget.item(row, column)
|
||||
if column == 0:
|
||||
if self._new_log_pos == row:
|
||||
self._new_log_task = self.tableWidget.item(row, column).text() or "Unnamed"
|
||||
else:
|
||||
self._report_data[row][column] = item.text() or "Unnamed"
|
||||
if column == 1:
|
||||
try:
|
||||
new_time = datetime.strptime(item.text(), "%H:%M").time()
|
||||
except ValueError:
|
||||
item.setText(self._report_data[row][column])
|
||||
return
|
||||
if self._new_log_pos == row:
|
||||
self._report_data.insert(row, [self._new_log_task, new_time.strftime("%H:%M"), ""])
|
||||
else:
|
||||
self._report_data[row][column] = new_time.strftime("%H:%M")
|
||||
self._new_log_pos = -1
|
||||
self._new_log_task = ""
|
||||
self.save()
|
||||
self.refresh_table()
|
||||
|
@ -60,4 +60,3 @@ class TaskEdit(QtWidgets.QDialog):
|
||||
@tasks.setter
|
||||
def tasks(self, tasks):
|
||||
self.list.setStringList(tasks)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user