-
Notifications
You must be signed in to change notification settings - Fork 85
/
pyfem_gui.py
285 lines (215 loc) · 10.5 KB
/
pyfem_gui.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
import sys
#import subprocess
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QTextEdit, QFileDialog, QVBoxLayout, QWidget, QToolBar, QMessageBox, QStyle, QSplitter, QHBoxLayout, QTabWidget, QLabel, QComboBox
from PySide6.QtCore import QProcess, Qt, QThread, Signal, QObject
from PySide6.QtGui import QIcon, QAction, QKeySequence
from pyfem.io.InputReader import InputRead
from pyfem.io.OutputManager import OutputManager
from pyfem.solvers.Solver import Solver
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
class EmittingStream(QObject):
text_written = Signal(str)
def write(self, text):
self.text_written.emit(str(text))
def flush(self):
pass
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
class WorkerThread(QThread):
output_signal = Signal(str)
def __init__(self, input_file):
super().__init__()
self.input_file = input_file
def run(self):
self.props,self.globdat = InputRead( self.input_file )
self.solver = Solver ( self.props , self.globdat )
self.output = OutputManager ( self.props , self.globdat )
while self.globdat.active:
self.solver.run( self.props , self.globdat )
self.output.run( self.props , self.globdat )
self.globdat.close()
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("PyFEM")
self.create_menu()
self.create_toolbar()
'''
self.layout = QVBoxLayout()
'''
# Main container widget
main_widget = QWidget()
self.setCentralWidget(main_widget)
# Main horizontal layout with a splitter
main_splitter = QSplitter(Qt.Horizontal)
main_layout = QHBoxLayout(main_widget)
main_layout.addWidget(main_splitter)
# Left panel with tabs
tab_widget = QTabWidget()
tab_widget.setTabPosition(QTabWidget.West)
tab_widget.setFixedWidth(400)
# Adding tabs to the tab widget
tabss = ["Mesh","Elements","Solver","Output"]
for tabs in tabss:
tab = QWidget()
tab_layout = QVBoxLayout()
tab.setLayout(tab_layout)
if tabs == "Solver":
# Add a combo box for solver selection in the Solver tab
solver_label = QLabel("Select a solver:")
combo_box = QComboBox()
combo_box.addItems(["SolverA", "SolverB", "SolverC"])
# Add the label and combo box to the tab layout
tab_layout.addWidget(solver_label)
tab_layout.addWidget(combo_box)
tab_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
tab_layout.setSpacing(5)
else:
# Default content for other tabs
tab_label = QLabel(f"Content for Tab {tabs}")
tab_layout.addWidget(tab_label)
#tab.setLayout(tab_layout)
tab_widget.addTab(tab, f"{tabs}")
main_splitter.addWidget(tab_widget)
# Right side layout with a vertical splitter
right_splitter = QSplitter(Qt.Vertical)
main_splitter.addWidget(right_splitter)
# Image display area
image_area = QLabel("Image Area")
image_area.setMinimumHeight(300)
image_area.setMinimumWidth(900)
image_area.setStyleSheet("background-color: white;")
image_area.setAlignment(Qt.AlignCenter)
right_splitter.addWidget(image_area)
self.output_terminal = QTextEdit()
self.output_terminal.setReadOnly(True)
self.output_terminal.setMinimumHeight(200)
self.output_terminal.setStyleSheet("background-color: black; color: white; font-family: 'Courier New', monospace;")
right_splitter.addWidget(self.output_terminal)
'''
container = QWidget()
container.setLayout(self.layout)
self.setCentralWidget(container)
'''
self.input_file = None
# Set initial sizes of the split panels
#main_splitter.setSizes([300, 900])
#right_splitter.setSizes([600, 300])
self.emitting_stream = EmittingStream()
self.emitting_stream.text_written.connect(self.handle_output)
sys.stdout = self.emitting_stream
sys.stderr = self.emitting_stream
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def create_menu(self):
menu_bar = self.menuBar()
file_menu = menu_bar.addMenu("File")
edit_menu = menu_bar.addMenu("Edit")
run_menu = menu_bar.addMenu("Run")
about_menu = menu_bar.addMenu("About")
new_action = QAction(self.style().standardIcon(QStyle.SP_FileIcon), 'New', self)
new_action.setShortcut(QKeySequence("Ctrl+N"))
new_action.triggered.connect(self.load_file)
file_menu.addAction(new_action)
open_action = QAction(self.style().standardIcon(QStyle.SP_DialogOpenButton), 'Open', self)
open_action.setShortcut(QKeySequence("Ctrl+O"))
open_action.triggered.connect(self.load_file)
file_menu.addAction(open_action)
save_action = QAction(self.style().standardIcon(QStyle.SP_DialogSaveButton), 'Save', self)
save_action.setShortcut(QKeySequence("Ctrl+S"))
save_action.triggered.connect(self.load_file)
file_menu.addAction(save_action)
exit_action = QAction(QIcon.fromTheme("application-exit"), "Exit", self)
exit_action.triggered.connect(self.close)
file_menu.addAction(exit_action)
execute_action = QAction(self.style().standardIcon(QStyle.SP_MediaPlay), "Execute", self)
execute_action.setShortcut(QKeySequence("Ctrl+R"))
execute_action.triggered.connect(self.execute_script)
run_menu.addAction(execute_action)
abort_action = QAction(self.style().standardIcon(QStyle.SP_BrowserStop), "Abort", self)
abort_action.setShortcut(QKeySequence("Ctrl+C"))
abort_action.triggered.connect(self.execute_script)
run_menu.addAction(abort_action)
about_action = QAction("About", self)
about_action.triggered.connect(self.show_about)
about_menu.addAction(about_action)
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def create_toolbar(self):
toolbar = QToolBar("Main Toolbar")
self.addToolBar(toolbar)
new_action = QAction(self.style().standardIcon(QStyle.SP_FileIcon),
'New', self)
new_action.triggered.connect(self.load_file)
toolbar.addAction(new_action)
open_action = QAction(self.style().standardIcon(QStyle.SP_DialogOpenButton),
'Open', self)
open_action.triggered.connect(self.load_file)
toolbar.addAction(open_action)
save_action = QAction(self.style().standardIcon(QStyle.SP_DialogSaveButton),
"Save", self)
save_action.triggered.connect(self.execute_script)
toolbar.addAction(save_action)
execute_action = QAction(self.style().standardIcon(QStyle.SP_MediaPlay),
"Execute", self)
execute_action.triggered.connect(self.execute_script)
toolbar.addAction(execute_action)
abort_action = QAction(self.style().standardIcon(QStyle.SP_BrowserStop),
"Abort", self)
abort_action.triggered.connect(self.execute_script)
toolbar.addAction(abort_action)
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def load_file(self):
file_dialog = QFileDialog()
self.input_file, _ = file_dialog.getOpenFileName(self,
caption = "Open Input File",
dir = "examples",
filter = "PyFEM Input Files (*.pro);;All Files (*.*)")
if self.input_file:
self.output_terminal.append(f"Loaded file: {self.input_file}")
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def execute_script(self):
if not self.input_file:
self.output_terminal.append("Please load an input file first.")
return
self.worker = WorkerThread(self.input_file)
self.worker.output_signal.connect(self.handle_output)
self.worker.start()
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def handle_output(self, text):
self.output_terminal.append( text.rstrip() )
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def update_output(self):
output = self.process.readAllStandardOutput().data().decode()
error = self.process.readAllStandardError().data().decode()
self.output_terminal.append(output)
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
def show_about(self):
QMessageBox.about(self, "About", "PyFEM gui\n\nDeveloped with PySide6.")
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
#window.resize(800, 600)
window.show()
sys.exit(app.exec())