-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectDetails.py
110 lines (86 loc) · 3.6 KB
/
ProjectDetails.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QTableView, QPushButton, QAbstractItemView, QToolBar, QLabel, QHBoxLayout
from PySide6.QtCore import QAbstractTableModel, Qt
from Helper.Utils import Utils
from PySide6.QtWidgets import QApplication, QMainWindow, QTableWidget, QTableWidgetItem, QPushButton, QVBoxLayout, QHBoxLayout, QWidget
from Helper.Utils import Utils
class Table(QTableWidget):
def __init__(self, project_array):
super().__init__()
header = project_array[0]
data = project_array[1]
self.setColumnCount(len(header))
self.setHorizontalHeaderLabels(header)
self.populate(data)
def populate(self, data):
self.setRowCount(0) # clear the table
self.setRowCount(len(data))
for row in range(len(data)):
for col in range(len(data[row])):
item = QTableWidgetItem(str(data[row][col]))
self.setItem(row, col, item)
def add_row(self, row_data):
row = self.rowCount()
self.setRowCount(row+1)
for col in range(len(row_data)):
item = QTableWidgetItem(str(row_data[col]))
self.setItem(row, col, item)
def replace_row(self, row_num, row_data):
for col in range(len(row_data)):
item = QTableWidgetItem(str(row_data[col]))
self.setItem(row_num, col, item)
def mouseDoubleClickEvent(self, event):
row = self.currentRow()
self.selectRow(row)
event.accept()
self.result_callback(row)
def set_result_callback(self, callback):
self.result_callback = callback
class History(QMainWindow):
def __init__(self):
super().__init__()
self.button = QLabel('History', self)
class ProjectDetails(QMainWindow):
def __init__(self, project_array):
super().__init__()
self.table = Table(project_array)
self.save_button = QPushButton('Save Project')
self.render_button = QPushButton('Render')
self.commit_button = QPushButton('Commit')
# self.table_view.doubleClicked.connect(self.edit_row)
button_layout = QHBoxLayout()
button_layout.addWidget(self.save_button)
button_layout.addWidget(self.render_button)
button_layout.addWidget(self.commit_button)
layout = QVBoxLayout()
layout.addWidget(self.table)
layout.addLayout(button_layout)
central_widget = QWidget()
central_widget.setLayout(layout)
self.setCentralWidget(central_widget)
def add_new_row(self, new_row_data):
self.table.add_row(new_row_data)
def get_rows(self):
rows = []
for row in range(self.table.rowCount()):
row_values = []
for column in range(self.table.columnCount()):
item = self.table.item(row, column)
if item is not None:
row_values.append(item.text())
else:
row_values.append('')
rows.append(row_values)
return rows
def replace_table(self, new_table_data):
self.table.populate(new_table_data)
def replace_row(self, row_num, new_row_data):
self.table.replace_row(row_num, new_row_data)
def set_result_callback(self, callback):
self.table.set_result_callback(callback)
# if __name__ == '__main__':
# data = Utils.projectToArray('test.json')
# app = QApplication(sys.argv)
# window = ProjectDetails(data)
# window.show()
# sys.exit(app.exec())