-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathpyqt5_execute_pytecplot.py
More file actions
94 lines (78 loc) · 2.97 KB
/
pyqt5_execute_pytecplot.py
File metadata and controls
94 lines (78 loc) · 2.97 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
"""
Creates a graphical user interface (GUI) that allows you to enter and execute PyTecplot commands
without having to create a *.py file. The GUI will also display any output created from the Python
script.
usage:
> python -O pyqt5_execute_pytecplot.py
Necessary modules
-----------------
tecplot
The PyTecplot package
https://pypi.org/project/pytecplot/
PyQt5
Python bindings for the Qt cross platform application toolkit
https://pypi.org/project/PyQt5/
Description
-----------
To run this script, first "Accept connections" in the Tecplot 360 user interface via
the "Scripting>PyTecplot Connections..." dialog
Running this script will launch a PyQt5 GUI that can accept PyTecplot commands. When
"Execute" is pressed in the GUI, the Python commands are saved to a temporary file,
then executed, saving you the effort of creating a file yourself. Output from the script
is displayed in the lower window of the GUI.
"""
import sys
import os
import tempfile
import tecplot as tp
from PyQt5 import QtWidgets, QtGui
from subprocess import Popen, PIPE
class ExecutePyTecplot(QtWidgets.QWidget):
def __init__(self):
super(ExecutePyTecplot, self).__init__()
self.initUI()
def initUI(self):
self.python_command_textEdit = QtWidgets.QTextEdit()
boilerPlate = """import tecplot as tp
from tecplot.constant import *
tp.session.connect()
frame = tp.active_frame()
plot = frame.plot()
dataset = frame.dataset
"""
self.python_command_textEdit.setPlainText(boilerPlate)
addExecutePyTecplot_Button = QtWidgets.QPushButton("Execute")
addExecutePyTecplot_Button.clicked.connect(self.execute_python_command_CB)
self.result_textEdit = QtWidgets.QTextEdit()
vbox = QtWidgets.QVBoxLayout()
vbox.addWidget(self.python_command_textEdit)
vbox.addWidget(addExecutePyTecplot_Button)
vbox.addWidget(self.result_textEdit)
self.setLayout(vbox)
self.setGeometry(300, 300, 1600, 1200)
self.setWindowTitle('PyTecplot Runner')
self.show()
def execute_python_command_CB(self, *a):
cmd = self.python_command_textEdit.toPlainText()
try:
temp_file = tempfile.NamedTemporaryFile(delete=False)
temp_file.write(cmd.encode('utf8'))
temp_file.flush()
p = Popen(['python', '-O', temp_file.name], stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, err = p.communicate(b"SomeString")
rc = p.returncode
if rc == 0:
self.result_textEdit.setPlainText(output.decode('utf8'))
else:
self.result_textEdit.setPlainText(err.decode('utf8'))
except Exception as e:
self.result_textEdit.setPlainText(str(e))
finally:
temp_file.close()
os.unlink(temp_file.name)
if __name__ == '__main__':
tp.session.connect()
app = QtWidgets.QApplication(sys.argv)
ex = ExecutePyTecplot()
res = app.exec_()
sys.exit(res)