-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalgorithm_resimulation.py
More file actions
149 lines (118 loc) · 5.01 KB
/
algorithm_resimulation.py
File metadata and controls
149 lines (118 loc) · 5.01 KB
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
import os
from PyQt5.QtCore import QTimer, QSize, pyqtSignal
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import *
from Algorithm.algorithmtype import ALGORITHM_TYPE
from file_manager import AlgorithmFileManager
from resimulation_manager import ResimulationManager
class AlgorithmResimulation(QWidget):
def __init__(self, serial_manager):
super().__init__()
self.resimulManager = ResimulationManager(sm=serial_manager)
self.serial_manager = serial_manager
self.algoFile = AlgorithmFileManager()
self.files = dict() #Algorithm File List
self.algorithm_checkbox = []
self.outputLabels = dict()
self.filepath = None
self.loadAlgorithmCbx()
self.initUI()
def initUI(self):
self.algorithm_list = QWidget(self)
self.toggleBtn = QPushButton("Step By Step OFF")
self.toggleBtn.setCheckable(True)
self.toggleBtn.setChecked(False) # toggle 초기 상태
self.toggleBtn.toggled.connect(self.changeToggle)
self.toggleBtn.setMinimumSize(QSize(150, 50))
font = QFont()
font.setBold(True)
font.setPointSize(10)
self.toggleBtn.setFont(font)
self.fileBtn = QPushButton("Data File Load")
self.fileBtn.clicked.connect(self.loadDataFile)
self.fileBtn.setMinimumSize(QSize(120, 50))
self.fileBtn.setFont(font)
self.filenameLabel = QLabel("")
self.filenameLabel.setMaximumHeight(50)
self.checkbox_layout = QVBoxLayout()
self.algorithm_list.setLayout(self.checkbox_layout)
for cbx in self.algorithm_checkbox:
self.checkbox_layout.addWidget(cbx)
self.start_btn = QPushButton('Run the selected algorithm', self)
self.start_btn.clicked.connect(self.run)
self.all_btn = QPushButton('Run all', self)
self.all_btn.clicked.connect(self.run_all)
self.stop_btn = QPushButton('Stop and Reset', self)
self.stop_btn.clicked.connect(self.finishAllAlgorithms)
self.stop_btn.setEnabled(False) # 알고리즘 프로세스가 시작해야 활성화됨
layout = QVBoxLayout()
layout.addWidget(self.algorithm_list)
groupbox = QGroupBox('Currently available algorithms')
groupbox.setLayout(layout)
self.weight_layout = QVBoxLayout()
self.weight_layout.addStretch()
self.weight_layout.setSpacing(10)
layout = QVBoxLayout()
layout.addLayout(self.weight_layout)
top_layout = QHBoxLayout() # 알고리즘, 버튼 박스와 분리를 위한 레이아웃
top_layout.addWidget(self.toggleBtn)
top_layout.addWidget(self.fileBtn)
top_layout.addWidget(self.filenameLabel)
top_layout.addStretch() # 버튼 오른쪽 공간 채우기
btn_layout = QVBoxLayout()
btn_layout.addWidget(self.start_btn)
btn_layout.addWidget(self.all_btn)
btn_layout.addWidget(self.stop_btn)
layout1 = QVBoxLayout()
layout1.addLayout(top_layout)
layout1.addWidget(groupbox)
layout1.addLayout(btn_layout)
layout2 = QHBoxLayout()
layout2.addLayout(layout1)
layout2.addLayout(layout)
self.setLayout(layout2)
def changeToggle(self, status):
if status:
self.toggleBtn.setText("Step By Step ON")
self.all_btn.setEnabled(False)
else:
self.toggleBtn.setText("Step By Step OFF")
self.all_btn.setEnabled(True)
def loadDataFile(self):
fname = QFileDialog.getOpenFileName(self)
if not fname[0]:
return
self.filepath = fname[0]
self.filenameLabel.setText(fname[0])
def updateLabel(self):
resbuf = self.procmanager.getResultBufs()
for bname, val in resbuf.items():
if not val.empty():
data = val.get()
print(bname, data)
def loadAlgorithmCbx(self):
for algo_name in ALGORITHM_TYPE.list_all():
self.files[algo_name.name] = algo_name
checkbox = QCheckBox(algo_name.name)
self.algorithm_checkbox.append(checkbox)
def run(self):
if not any(cbx.isChecked() for cbx in self.algorithm_checkbox):
print('No checkbox selected')
return
self.runAlgorithm()
def run_all(self):
for cbx in self.algorithm_checkbox:
cbx.setChecked(True)
self.runAlgorithm()
def runAlgorithm(self):
self.resimulManager.getDataFile(self.filepath)
for cbx in self.algorithm_checkbox:
if cbx.isChecked():
print('run - ', cbx.text())
if cbx.text() in self.files:
print('select algorithm file -> ',cbx.text(), self.files[cbx.text()])
self.resimulManager.addProcess(self.files[cbx.text()])
self.resimulManager.startThread(callback=lambda: self.stop_btn.setEnabled(True))
def finishAllAlgorithms(self):
self.resimulManager.terminate()
self.stop_btn.setEnabled(False)