-
Notifications
You must be signed in to change notification settings - Fork 3
/
pythena.py
executable file
·249 lines (214 loc) · 8.54 KB
/
pythena.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
#! /usr/bin/env python
#
from PyQt5 import QtWidgets as qw, QtGui as qg
from argparse import ArgumentParser
from json import load
from subprocess import Popen, PIPE
from re import match
from sys import argv
from os import path
# parse arguments
argparser = ArgumentParser(description='Runs the GUI for configuring an athinput file')
argparser.add_argument('-r', '--run',
action='store_true',
help='executes the athena command and plots the tab files on run',
default=False)
args = argparser.parse_args()
# building gui
with open('athena_problems.json') as problems_json:
problems = load(problems_json)
athena_problems = list([])
athena_problems = list(problems['athenak'])
class MainWindow(qw.QMainWindow):
def __init__(self):
super().__init__()
self.radio_groups = []
self.windows = []
page_layout = qw.QVBoxLayout()
radio_layout = qw.QHBoxLayout()
exe_layout = qw.QHBoxLayout()
load_layout = qw.QHBoxLayout()
predef_layout = qw.QHBoxLayout()
self.current_athena = 'athena'
toolbar = self.addToolBar('ToolBar')
launch_action = qw.QAction('Launch', self)
launch_action.setToolTip('Launch the parameter configurator')
launch_action.triggered.connect(self.launch)
toolbar.addAction(launch_action)
toolbar.addSeparator()
help_action = qw.QAction('Help', self)
help_action.setToolTip('Open help menu')
help_action.triggered.connect(self.help)
toolbar.addAction(help_action)
toolbar.addSeparator()
quit_action = qw.QAction('Quit', self)
quit_action.setToolTip('Exit the program')
quit_action.triggered.connect(self.quit)
toolbar.addAction(quit_action)
def browse(t):
file = qw.QFileDialog.getOpenFileName(self, "Select File", "")[0]
t.setText(file)
if False:
label = qw.QLabel('Athena Version: [deprecating]')
radio_layout.addWidget(label)
label.setStyleSheet("font-weight: bold")
radio_layout.addStretch()
rbtn = qw.QRadioButton('Athena')
#rbtn.setChecked(True)
rbtn.toggled.connect(lambda: self.switch('athena'))
radio_layout.addWidget(rbtn)
rbtn = qw.QRadioButton('AthenaK')
rbtn.setChecked(True)
rbtn.toggled.connect(lambda: self.switch('athenak'))
radio_layout.addWidget(rbtn)
rbtn = qw.QRadioButton('AthenaC')
rbtn.toggled.connect(lambda: self.switch('athenac'))
radio_layout.addWidget(rbtn)
if False:
label = qw.QLabel('Athena Executable: [deprecating]')
exe_layout.addWidget(label)
label.setStyleSheet("font-weight: bold")
btn = qw.QPushButton(self)
btn.setText("browse")
self.exe = qw.QLineEdit(self)
btn.clicked.connect(lambda: browse(self.exe))
self.exe.setFixedWidth(250)
self.exe.setText('athenak/build/src/athena')
exe_layout.addStretch()
exe_layout.addWidget(btn)
exe_layout.addWidget(self.exe)
self.athena = self.exe.text()
else:
self.athena = 'athenak/build/src/athena'
print("athena:",self.athena)
btn_group = qw.QButtonGroup()
self.load_radio = qw.QRadioButton('Load Problem:')
self.load_radio.setStyleSheet('font-weight: bold')
self.load_radio.setChecked(True)
load_layout.addWidget(self.load_radio)
load_layout.addStretch()
btn = qw.QPushButton(self)
btn.setText("browse")
self.problem = qw.QLineEdit(self)
btn.clicked.connect(lambda: browse(self.problem))
self.problem.setFixedWidth(250)
self.problem.setText('linear_wave_hydro.athinput')
load_layout.addWidget(btn)
load_layout.addWidget(self.problem)
self.predef_radio = qw.QRadioButton('Predefined Problem: [TBD]')
self.predef_radio.setStyleSheet('font-weight: bold')
predef_layout.addWidget(self.predef_radio)
self.combo = qw.QComboBox()
self.combo.addItems(athena_problems)
predef_layout.addStretch()
predef_layout.addWidget(self.combo)
btn_group.addButton(self.load_radio)
btn_group.addButton(self.predef_radio)
self.radio_groups.append(btn_group)
page_layout.addLayout(radio_layout)
page_layout.addLayout(exe_layout)
page_layout.addLayout(load_layout)
page_layout.addLayout(predef_layout)
# checkbox
if False:
self.reconfig = qw.QCheckBox('Reconfigure Executable')
page_layout.addWidget(self.reconfig)
else:
print("no reconfig needed for athenak")
widget = qw.QWidget()
widget.setLayout(page_layout)
scroll = qw.QScrollArea() #add scrollbar
scroll.setWidgetResizable(True)
scroll.setWidget(widget)
self.resize(700, 300)
self.setCentralWidget(scroll)
def switch(self, type):
self.combo.clear()
if type == 'athena':
self.combo.addItems(athena_problems)
self.reconfig.setVisible(True)
elif type == 'athenak':
self.combo.addItems(athenak_problems)
self.reconfig.setVisible(False)
else:
self.combo.addItems(athenac_problems)
self.reconfig.setVisible(True)
self.current_athena = type
print("Current athena:",type)
def rebuild(self, problem):
config = None
with open(problem) as file:
line = file.readline()
while line:
m = match('config[^=]+=(.+)', line)
if m:
config = m.group(1)
break
line = file.readline()
w = ConfigWindow(config)
w.show()
w.run()
w.close()
def launch(self):
problem = problems[self.current_athena][self.combo.currentText()] if self.predef_radio.isChecked() else self.problem.text()
cmd = './pythena_run.py %s -x %s %s' % (problem,
self.athena,
'-r' if args.run else '')
print(cmd)
try:
if not path.exists(problem):
raise FileNotFoundError
Popen(cmd.split())
except Exception as e:
print(e)
def help(self):
w = HelpWindow()
self.windows.append(w)
w.show()
def quit(self):
self.close()
# deprecate
class ConfigWindow(qw.QWidget):
def __init__(self, config):
super().__init__()
self.config = config
self.setWindowTitle('Rebuilding Executable')
self.main_layout = qw.QVBoxLayout()
bash_label = qw.QLabel('./reconfig.sh ' + self.config)
bash_label.setStyleSheet('font-weight: bold')
bash_label.setFont(qg.QFont('Courier New', 10))
self.main_layout.addWidget(bash_label)
self.txt = qw.QLabel()
self.txt.setFont(qg.QFont('Courier New', 10))
self.main_layout.addWidget(self.txt)
self.setLayout(self.main_layout)
def run(self):
p = Popen(['./reconfig.sh', self.config], stdout=PIPE)
line = p.stdout.readline()
while line:
self.txt.setText(line.decode())
qg.QGuiApplication.processEvents()
line = p.stdout.readline()
class HelpWindow(qw.QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Help')
self.main_layout = qw.QVBoxLayout()
self.add_label('Athena Version:', '\tThe version of Athena (must match the version of the executable) to be used')
self.add_label('Athena Executable:', '\tEither the path or the name of the Athena executable. If only a name is given, then it is assumed that the executable is in /usr/bin.')
self.add_label('Selecting Problems:', '\tA problem can either be selected from the list of predefined problems or a custom problem can be chosen. Use the radio buttons to choose which method to use.')
self.setLayout(self.main_layout)
def add_label(self, s1, s2):
txt = qw.QLabel(s1)
txt.setStyleSheet('font-weight: bold')
self.main_layout.addWidget(txt)
self.main_layout.addWidget(qw.QLabel(s2))
app = qw.QApplication(argv)
main = MainWindow()
main.show()
try:
#print('opening window')
exit(app.exec())
except:
#print('closing window')
pass