2020-02-20 14:22:40 +00:00
|
|
|
from PySide2 import QtCore, QtGui, QtWidgets
|
|
|
|
|
|
|
|
|
|
|
|
class Report(QtWidgets.QDialog):
|
|
|
|
def __init__(self, parent, *args, **kwargs):
|
|
|
|
super().__init__(parent, *args, **kwargs)
|
2020-02-24 14:41:08 +00:00
|
|
|
self._report = None
|
|
|
|
self._report_data = None
|
|
|
|
|
2020-02-20 14:22:40 +00:00
|
|
|
self.setWindowTitle("Report")
|
|
|
|
|
|
|
|
self.tableWidget = QtWidgets.QTableWidget()
|
|
|
|
self.tableWidget.verticalHeader().hide()
|
|
|
|
self.tableWidget.setColumnCount(3)
|
|
|
|
self.tableWidget.setHorizontalHeaderLabels(["Task", "Start time", "Duration"])
|
|
|
|
self.header = QtWidgets.QHeaderView(QtCore.Qt.Orientation.Horizontal)
|
|
|
|
self.tableWidget.setHorizontalHeader(self.header)
|
|
|
|
|
2020-02-24 14:41:08 +00:00
|
|
|
self.previous_button = QtWidgets.QPushButton()
|
|
|
|
self.previous_button.setText("Previous")
|
|
|
|
self.previous_button.setIcon(QtGui.QIcon.fromTheme("arrow-left"))
|
|
|
|
self.previous_button.pressed.connect(self.previous)
|
|
|
|
|
|
|
|
self.next_button = QtWidgets.QPushButton()
|
|
|
|
self.next_button.setText("Next")
|
|
|
|
self.next_button.setIcon(QtGui.QIcon.fromTheme("arrow-right"))
|
|
|
|
self.next_button.pressed.connect(self.next)
|
2020-02-20 14:22:40 +00:00
|
|
|
|
|
|
|
del_button = QtWidgets.QPushButton()
|
|
|
|
del_button.setText("Delete item")
|
|
|
|
del_button.setIcon(QtGui.QIcon.fromTheme("list-remove"))
|
2020-02-24 14:41:08 +00:00
|
|
|
del_button.pressed.connect(self.del_log)
|
2020-02-20 14:22:40 +00:00
|
|
|
|
|
|
|
ok_button = QtWidgets.QPushButton()
|
|
|
|
ok_button.setText("OK")
|
|
|
|
ok_button.setIcon(QtGui.QIcon.fromTheme("dialog-ok-apply"))
|
2020-02-24 14:41:08 +00:00
|
|
|
ok_button.pressed.connect(self._accept)
|
2020-02-20 14:22:40 +00:00
|
|
|
|
|
|
|
blayout = QtWidgets.QHBoxLayout()
|
2020-02-24 14:41:08 +00:00
|
|
|
blayout.addWidget(self.previous_button)
|
|
|
|
blayout.addWidget(self.next_button)
|
2020-02-20 14:22:40 +00:00
|
|
|
blayout.addWidget(del_button)
|
|
|
|
blayout.addWidget(ok_button)
|
|
|
|
|
|
|
|
layout = QtWidgets.QVBoxLayout(self)
|
|
|
|
layout.addWidget(self.tableWidget)
|
|
|
|
layout.addLayout(blayout)
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
|
|
def set_data(self, data):
|
2020-02-24 14:41:08 +00:00
|
|
|
self._report = data
|
|
|
|
self._report_data = self._report.report()
|
|
|
|
self.refresh_table()
|
|
|
|
self.update_prev_next()
|
|
|
|
|
|
|
|
def refresh_table(self):
|
|
|
|
self.tableWidget.setRowCount(len(self._report_data))
|
|
|
|
|
|
|
|
for row, _ in enumerate(self._report_data):
|
|
|
|
item0 = QtWidgets.QTableWidgetItem(self._report_data[row][0])
|
|
|
|
self.tableWidget.setItem(row, 0, item0)
|
|
|
|
item1 = QtWidgets.QTableWidgetItem(self._report_data[row][1])
|
|
|
|
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)
|
2020-02-24 15:54:28 +00:00
|
|
|
if row > len(self._report_data) - 4:
|
2020-02-24 14:41:08 +00:00
|
|
|
item1.setFlags(item1.flags() & QtCore.Qt.ItemIsEnabled)
|
2020-02-20 14:22:40 +00:00
|
|
|
|
|
|
|
self.tableWidget.resizeColumnsToContents()
|
|
|
|
|
|
|
|
min_width = 0
|
|
|
|
for i in range(3):
|
|
|
|
min_width += self.header.sectionSize(i)
|
|
|
|
self.tableWidget.setMinimumWidth(min_width * 1.33)
|
|
|
|
self.header.setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
|
2020-02-24 12:16:17 +00:00
|
|
|
if self.tableWidget.rowCount() > 4:
|
|
|
|
self.tableWidget.setMinimumHeight(min((self.tableWidget.rowCount() + 2) * self.tableWidget.rowHeight(0),
|
|
|
|
self.tableWidget.screen().size().height() * 0.8))
|
2020-02-20 14:22:40 +00:00
|
|
|
|
2020-02-24 14:41:08 +00:00
|
|
|
def update_prev_next(self):
|
|
|
|
prev, _next = self._report.prev_next_avail()
|
|
|
|
self.previous_button.setEnabled(prev)
|
|
|
|
self.next_button.setEnabled(_next)
|
|
|
|
|
|
|
|
@QtCore.Slot()
|
|
|
|
def del_log(self):
|
|
|
|
row = self.tableWidget.currentRow()
|
2020-02-24 15:54:28 +00:00
|
|
|
if row > len(self._report_data) - 4:
|
2020-02-24 14:41:08 +00:00
|
|
|
return
|
|
|
|
del self._report_data[row]
|
|
|
|
self.refresh_table()
|
|
|
|
|
|
|
|
@QtCore.Slot()
|
|
|
|
def _accept(self):
|
|
|
|
self._report.save(self._report_data)
|
|
|
|
self.accept()
|
|
|
|
|
2020-02-20 14:22:40 +00:00
|
|
|
@QtCore.Slot()
|
2020-02-24 14:41:08 +00:00
|
|
|
def previous(self):
|
|
|
|
self._report.save(self._report_data)
|
|
|
|
self._report.previous()
|
2020-02-24 15:54:28 +00:00
|
|
|
self._report_data = self._report.report()
|
2020-02-24 14:41:08 +00:00
|
|
|
self.refresh_table()
|
|
|
|
self.update_prev_next()
|
2020-02-20 14:22:40 +00:00
|
|
|
|
|
|
|
@QtCore.Slot()
|
2020-02-24 14:41:08 +00:00
|
|
|
def next(self):
|
|
|
|
self._report.save(self._report_data)
|
|
|
|
self._report.next()
|
2020-02-24 15:54:28 +00:00
|
|
|
self._report_data = self._report.report()
|
2020-02-24 14:41:08 +00:00
|
|
|
self.refresh_table()
|
|
|
|
self.update_prev_next()
|