0

I have been trying to make a small PyQt4 widget, but i have trouble pasting the subprocess into the textbox of the widget.

self.textEdit_2 = QtGui.QTextEdit(self.tab_Logcat)
self.textEdit_2.setGeometry(QtCore.QRect(0, 0, 781, 731))
self.textEdit_2.setObjectName(_fromUtf8("textEdit_2"))

def paster(self):
    from subprocess import Popen, PIPE
    cat = subprocess.Popen('adb', stdout=PIPE)
    self.textEdit_2.setText(str(cat))

No matter what i try, it paste to the shell insteed. i have looked at the other similar thread How to redirect print result from python shell into qtextedit pyqt?

But it dosent seem to work with subprocess.

Community
  • 1
  • 1
michael
  • 31
  • 7
  • Do you want to append the text printed by the child process to the text widget as soon as the subprocess output becomes available e.g., one line at a time? – jfs Feb 22 '15 at 14:37
  • Well i see the problem, adb.exe is the android tool , i got it working with cat = subprocess.Popen('adb shell', stdout=subprocess.PIPE, shell=True). self.textEdit_2.setText(cat.stdout.read()) but if im gonna use command 'adb logcat' i would have to have the signal open to the text Editbox. – michael Feb 22 '15 at 14:46
  • What is your specific issue? Do you want to create a GUI for adb? Do you want in response to user actions with your GUI (a button pressed, some text entered in a text widget, etc) to send commands to `adb` and display the response in the GUI? – jfs Feb 22 '15 at 15:16
  • yes thats what i wish todo exactly, the example is just for getting subprocess commands in GUI, but exampel adb logcat would halt the app, open a prompt and just paste logcat into GUI when closing prompt – michael Feb 22 '15 at 15:18
  • Given your incorrect code `str(cat)`, creating a GUI for `adb` might be too complex task for you at the moment. Start with simpler tasks: how do you get the stdout as soon as it arrives, how do you display the output in a GUI as soon as it arrives, how do you pass input to the subprocess, how do you pass the input on a button pressed, etc. I would use `QProcess` for that. Once you know how to get output, pass input, response to GUI events, update the GUI; you could use it to create the GUI. – jfs Feb 22 '15 at 16:17
  • from subprocess import Popen, PIPE cat = subprocess.Popen('adb shell ps', stdout=subprocess.PIPE, shell=True) self.textEdit_3.setText(cat.stdout.read()) that works for simple task callback to the GUI, but your saying that it would be better having QProcess, using a signal on You have a exampel of using Qprocess and subprocess, it would help. – michael Feb 22 '15 at 17:05
  • to find an example, just google: qprocess pyqt. If you have *specific* issue, [ask](http://stackoverflow.com/questions/how-to-ask) – jfs Feb 23 '15 at 03:10
  • btw, `.setText(cat.stdout.read())` also does *not* work: it will freeze your GUI (`.read()` blocks until EOF i.e., until `adb` exits in this case). It is not an appropriate way to read output incrementally while the child process is still running. – jfs Feb 23 '15 at 03:20

0 Answers0