-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_window.py
executable file
·267 lines (221 loc) · 10.8 KB
/
main_window.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
import logging
import sys
from drag_list import DragList
from main_widget import MainWidget
from node import Node, NodeDemux
try:
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
except ImportError:
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
logger = logging.getLogger()
logging.basicConfig(level=logging.DEBUG)
class MainWindow(QMainWindow):
ordered_nodes = None
dialog = None
def __init__(self):
super().__init__()
self.main_widget = MainWidget(parent_window=self)
self.setCentralWidget(self.main_widget)
self.statusBar().showMessage('Ready')
self.statusbar_label = QLabel("0/0")
self.statusBar().addPermanentWidget(self.statusbar_label)
menubar = self.menuBar()
self.is_ordered = False
self.setWindowTitle("Data Analysis App")
# add submenus to a menu
file_menu = menubar.addMenu('File')
help_menu = menubar.addMenu('Help')
# add an action with a callback
file_menu.addAction('Quit', self.destroy)
# add separator
file_menu.addSeparator()
toolbar = self.addToolBar('File')
toolbar.setMovable(False)
toolbar.setFloatable(False)
toolbar.setAllowedAreas(
Qt.TopToolBarArea |
Qt.BottomToolBarArea
)
dock = QDockWidget("Tools")
dock_loaders_widget = QWidget(self)
dock_preprocess_widget = QWidget(self)
dock_regression_widget = QWidget(self)
dock_classification_widget = QWidget(self)
dock_clustering_widget = QWidget(self)
dock_visualization_widget = QWidget(self)
dock_demux_widget = QWidget(self)
nodes_list_loaders = DragList()
nodes_list_preprocess = DragList()
nodes_list_regression = DragList()
nodes_list_classification = DragList()
nodes_list_clustering = DragList()
nodes_list_visualization = DragList()
nodes_list_demux = DragList()
nodes_list_loaders.add_items(['Csv Loader', 'Excel Loader', "Xml Loader", "Deserializer"],
icon="icons/input24.png")
nodes_list_preprocess.add_items(['Attribute Remover', 'Filter'], icon="icons/both24.png")
nodes_list_regression.add_items(['Linear Regression'], icon="icons/both24.png")
nodes_list_classification.add_items(['Knn', 'SVM', 'Naive Bayes', 'Decision Tree'], icon="icons/both24.png")
nodes_list_clustering.add_items(['K-Means', "Hierarchical"], icon="icons/both24.png")
nodes_list_visualization.add_items(["Text output", "Scatter plot", "Pie Chart", "Predictor", "Serializer",
"Simple Plot", "Histogram", "Csv Saver"], icon="icons/output24.png")
nodes_list_demux.add_items(["1x2 Demux", "1x3 Demux", "1x4 Demux", "1x5 Demux"], icon="icons/demux.png")
self.addDockWidget(Qt.LeftDockWidgetArea, dock)
tab_widget = QTabWidget()
tab_widget.setMovable(False)
tab_widget.setTabPosition(QTabWidget.West)
tab_widget.resize(100, 100)
dock_layout_loaders = QHBoxLayout()
dock_layout_preprocess = QHBoxLayout()
dock_layout_regression = QHBoxLayout()
dock_layout_classification = QHBoxLayout()
dock_layout_clustering = QHBoxLayout()
dock_layout_visualization = QHBoxLayout()
dock_layout_demux = QHBoxLayout()
dock_loaders_widget.setLayout(dock_layout_loaders)
dock_preprocess_widget.setLayout(dock_layout_preprocess)
dock_regression_widget.setLayout(dock_layout_regression)
dock_classification_widget.setLayout(dock_layout_classification)
dock_clustering_widget.setLayout(dock_layout_clustering)
dock_visualization_widget.setLayout(dock_layout_visualization)
dock_demux_widget.setLayout(dock_layout_demux)
# dock_layout.addWidget(tab_widget)
dock_layout_loaders.addWidget(nodes_list_loaders)
dock_layout_preprocess.addWidget(nodes_list_preprocess)
dock_layout_regression.addWidget(nodes_list_regression)
dock_layout_classification.addWidget(nodes_list_classification)
dock_layout_clustering.addWidget(nodes_list_clustering)
dock_layout_visualization.addWidget(nodes_list_visualization)
dock_layout_demux.addWidget(nodes_list_demux)
tab_widget.addTab(dock_loaders_widget, 'Inputs')
tab_widget.addTab(dock_preprocess_widget, 'Preprocessors')
tab_widget.addTab(dock_regression_widget, 'Regression')
tab_widget.addTab(dock_classification_widget, 'Classification')
tab_widget.addTab(dock_clustering_widget, 'Clustering')
tab_widget.addTab(dock_visualization_widget, 'Output')
tab_widget.addTab(dock_demux_widget, "Demux")
dock.setWidget(tab_widget)
help_menu.addAction('About', self.show_about_dialog)
help_menu.addAction("Credits", self.credits)
help_menu.addAction("Node List", self._log_path)
self.show()
def _log_path(self):
logger.debug(self.main_widget)
logger.debug(self.main_widget.nodes)
logger.debug("There is {} nodes exist on the scene".format(len(self.main_widget.nodes)))
for edge in self.main_widget.edges:
logger.debug("From {} to {}".format(edge.start_socket.node.title, edge.end_socket.node.title))
self.order_path()
logger.debug("Logging the ordered nodes")
for inner_list in self.ordered_nodes:
s = ""
for path in inner_list:
s += "{}-".format(path.title)
logger.debug(s)
def order_path(self):
first_node = None
self.is_ordered = True
self.ordered_nodes = [[]]
for node in self.main_widget.nodes:
if isinstance(node, Node) and node.is_first:
first_node = node
self.append_nodes_by_order(first_node, self.ordered_nodes[0])
def append_nodes_by_order(self, node, lst):
if isinstance(node, Node):
lst.append(node)
if node.is_last:
return
while True:
if not lst[-1].output_socket.has_edge() and not lst[-1].is_last:
QMessageBox.critical(self, "Warning!", "Every path must end with an output socket!")
self.is_ordered = False
return
next_node = lst[-1].output_socket.edge.end_socket.node
if isinstance(next_node, NodeDemux):
copied_lists = []
for i in range(len(next_node.output_sockets) - 1):
copied_lists.append([])
for i, socket in enumerate(next_node.output_sockets):
if i == len(next_node.output_sockets) - 1:
self.append_nodes_by_order(socket.edge.end_socket.node, lst)
else:
for item in lst:
copied_lists[i].append(item)
self.ordered_nodes.append(copied_lists[i])
if not socket.has_edge():
QMessageBox.critical(self, "Warning!", "Every demux sockets must be connected to a node!")
self.is_ordered = False
return
self.append_nodes_by_order(socket.edge.end_socket.node, copied_lists[i])
break
lst.append(next_node)
if next_node.is_last:
break
def feed_next_node(self, node):
for ordered_nodes in self.ordered_nodes:
try:
i = ordered_nodes.index(node)
except ValueError:
continue
ordered_nodes[i + 1].feed(node.output)
def show_about_dialog(self):
QMessageBox.about(
self,
"About",
"This is a data analysis app written in PyQt5."
)
def change_statusbar_text(self):
completed_count = 0
set_of_nodes = set()
for node in self.main_widget.nodes:
if node not in set_of_nodes:
if isinstance(node, Node):
set_of_nodes.add(node)
if node.is_finished:
completed_count += 1
self.statusbar_label.setText("{}/{}".format(completed_count, len(set_of_nodes)))
def credits(self):
self.dialog = QDialog()
self.dialog.setModal(True)
self.dialog.resize(451, 130)
self.dialog.setWindowTitle("Acknowledgements")
widget = QWidget(self.dialog)
widget.setGeometry(QRect(20, 30, 401, 205))
grid_layout = QGridLayout(self.dialog)
vertical_layout = QVBoxLayout()
label = QLabel(self.dialog)
vertical_layout.addWidget(label)
grid_layout.addLayout(vertical_layout, 0, 0, 0, 0)
label.setWordWrap(True)
label.setOpenExternalLinks(True)
label.setText("""
<div>Icons made by:
<a href="https://www.flaticon.com/authors/flat-icons" title="Flat Icons">Flat Icons</a>,
<a href="https://www.flaticon.com/authors/pixel-perfect" title="Pixel perfect">Pixel perfect</a>,
<a href="https://www.flaticon.com/authors/eucalyp" title="Eucalyp">Eucalyp</a>,
<a href="https://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a>,
<a href="https://www.flaticon.com/authors/geotatah" title="geotatah">geotatah</a>,
<a href="https://www.flaticon.com/authors/becris" title="Becris">Becris</a>,
<a href="https://www.flaticon.com/free-icon/scatter-graph_2393904" title="surang">surang</a>,
<a href="https://www.flaticon.com/free-icon/csv_2305939" title="iconixar">iconixar</a>,
<a href="https://smashicons.com/" title="Smashicons">Smashicons</a>,
<a href="https://www.flaticon.com/free-icon/scatter_1449286" title="Kiranshastry">Kiranshastry</a>
from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a></div>
""")
label2 = QLabel(self.dialog)
label2.setText("I would like to appreciate those authors for the icons they provided.")
vertical_layout.addWidget(label2)
button_box = QDialogButtonBox(self.dialog)
button_box.setOrientation(Qt.Horizontal)
button_box.setStandardButtons(QDialogButtonBox.Close)
button_box.button(QDialogButtonBox.Close).clicked.connect(self.dialog.reject)
vertical_layout.addWidget(button_box)
self.dialog.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
mw = MainWindow()
sys.exit(app.exec())