Reputation: 10082
I have a text CLI based script written to test some equipment. Some of the test requires entering back yes/no answers as well as reading the script's output. I want to see if it's feasible to create a PyQT app. that can put a GUI front end on this type of interaction? E.g. when the user clicks a button to run a script, the script is run sending it's output line at a time to a text window on the GUI, and any lines entered from the GUI are also sent down to the script.
TIA, Fred
Upvotes: 0
Views: 590
Reputation: 4097
What is the criteria by which you'll be judging whether it's feasible or not?
It certainly is possible. The QProcess class provides everything that you would need for running and interacting with external processes inside a Qt application. At its core, it can do everything that subprocess
can do (albeit, less conveniently). Here's a contrived usage example:
button = QPushButton('start')
textedit = QTextEdit()
process = QProcess()
button.clicked.connect(on_clicked)
def on_clicked():
process.readyReadStandardOutput.connect(read_ready)
process.start('/bin/sh',
('-c', "while /bin/true; do echo hello world ; sleep 1; done"))
def read_ready(self):
chunk = process.readAllStandardOutput()
textedit.append(str(chunk))
Since you're still at the planning stage, why not consider a tool such as zenity for the GUI part? It could save you a lot of work. Getting a list of checkboxes and sending the output of a command to a textarea becomes a matter of:
parameters=$(
zenity --list --text "Test parameters:" \
--checklist --column "Check" --column "Parameter" \
TRUE "One" TRUE "Two" TRUE "Three" FALSE "Four" \
--separator=":");
# parameters -> One:Two:Three
./instrument-test.py $parameters | zenity --text-info
Best of luck with your project!
Upvotes: 1