Implement start time editing.
This commit is contained in:
parent
233ca3fcee
commit
5b62e8684d
8
data.py
8
data.py
@ -179,14 +179,14 @@ class Report:
|
|||||||
dsum += duration
|
dsum += duration
|
||||||
dhours, rem = divmod(duration.seconds, 3600)
|
dhours, rem = divmod(duration.seconds, 3600)
|
||||||
dmins, _ = divmod(rem, 60)
|
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:
|
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)
|
dhours, rem = divmod(dsum.seconds, 3600)
|
||||||
dmins, _ = divmod(rem, 60)
|
dmins, _ = divmod(rem, 60)
|
||||||
ret.append(("Sum", "", f"{dhours:02d}:{dmins:02d}"))
|
ret.append(["Sum", "", f"{dhours:02d}:{dmins:02d}"])
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def save(self, report):
|
def save(self, report):
|
||||||
|
21
report.py
21
report.py
@ -1,11 +1,14 @@
|
|||||||
from PySide2 import QtCore, QtGui, QtWidgets
|
from PySide2 import QtCore, QtGui, QtWidgets
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
class Report(QtWidgets.QDialog):
|
class Report(QtWidgets.QDialog):
|
||||||
def __init__(self, parent, *args, **kwargs):
|
def __init__(self, parent, *args, **kwargs):
|
||||||
super().__init__(parent, *args, **kwargs)
|
super().__init__(parent, *args, **kwargs)
|
||||||
self._report = None
|
self._report = None
|
||||||
self._report_data = None
|
self._report_data = None
|
||||||
|
self._changing_items = False
|
||||||
|
|
||||||
self.setWindowTitle("Report")
|
self.setWindowTitle("Report")
|
||||||
|
|
||||||
@ -13,6 +16,7 @@ class Report(QtWidgets.QDialog):
|
|||||||
self.tableWidget.verticalHeader().hide()
|
self.tableWidget.verticalHeader().hide()
|
||||||
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.header = QtWidgets.QHeaderView(QtCore.Qt.Orientation.Horizontal)
|
self.header = QtWidgets.QHeaderView(QtCore.Qt.Orientation.Horizontal)
|
||||||
self.tableWidget.setHorizontalHeader(self.header)
|
self.tableWidget.setHorizontalHeader(self.header)
|
||||||
|
|
||||||
@ -56,6 +60,7 @@ class Report(QtWidgets.QDialog):
|
|||||||
def refresh_table(self):
|
def refresh_table(self):
|
||||||
self.tableWidget.setRowCount(len(self._report_data))
|
self.tableWidget.setRowCount(len(self._report_data))
|
||||||
|
|
||||||
|
self._changing_items = True
|
||||||
for row, _ in enumerate(self._report_data):
|
for row, _ in enumerate(self._report_data):
|
||||||
item0 = QtWidgets.QTableWidgetItem(self._report_data[row][0])
|
item0 = QtWidgets.QTableWidgetItem(self._report_data[row][0])
|
||||||
self.tableWidget.setItem(row, 0, item0)
|
self.tableWidget.setItem(row, 0, item0)
|
||||||
@ -67,6 +72,7 @@ class Report(QtWidgets.QDialog):
|
|||||||
item2.setFlags(item2.flags() & QtCore.Qt.ItemIsEnabled)
|
item2.setFlags(item2.flags() & QtCore.Qt.ItemIsEnabled)
|
||||||
if row > len(self._report_data) - 4:
|
if row > len(self._report_data) - 4:
|
||||||
item1.setFlags(item1.flags() & QtCore.Qt.ItemIsEnabled)
|
item1.setFlags(item1.flags() & QtCore.Qt.ItemIsEnabled)
|
||||||
|
self._changing_items = False
|
||||||
|
|
||||||
self.tableWidget.resizeColumnsToContents()
|
self.tableWidget.resizeColumnsToContents()
|
||||||
|
|
||||||
@ -112,3 +118,18 @@ class Report(QtWidgets.QDialog):
|
|||||||
self._report_data = self._report.report()
|
self._report_data = self._report.report()
|
||||||
self.refresh_table()
|
self.refresh_table()
|
||||||
self.update_prev_next()
|
self.update_prev_next()
|
||||||
|
|
||||||
|
@QtCore.Slot()
|
||||||
|
def cell_changed(self, row, column):
|
||||||
|
if self._changing_items:
|
||||||
|
return
|
||||||
|
item = self.tableWidget.item(row, column)
|
||||||
|
try:
|
||||||
|
new_time = datetime.strptime(item.text(), "%H:%M").time()
|
||||||
|
except ValueError:
|
||||||
|
item.setText(self._report_data[row][column])
|
||||||
|
return
|
||||||
|
self._report_data[row][column] = new_time.strftime("%H:%M")
|
||||||
|
self._report.save(self._report_data)
|
||||||
|
self._report_data = self._report.report()
|
||||||
|
self.refresh_table()
|
||||||
|
Loading…
Reference in New Issue
Block a user