3

I wrote an application that, among other things, launches some "backend" processes to do some stuff. These subprocesses are very likely to fail or have unexpected behavior since they have to operate in quite hard conditions, so I prefer to give full control over them to the operator.

NOTE: I am running these processes using a subprocess module based class instead of QProcess to have some more control functionality over the running process.

At the moment, I'm using a QPlainTextEdit widget to which I append standard output/error from the subprocess, plus some buttons to quickly send some common signals (INT, STOP, CONT, KILL, ..), but:

  • In some cases it would be useful to send some input too. Although it could be done with a text input box, I would prefer using something more "professional"
  • Of course, there is no direct way to interpret special control characters, such as color codes, cursor movement, etc..
  • I had to implement an auto-scroll management of the console, but it is not guaranteed 100% to work nicely (sometimes the scroll locking doesn't work as expected, etc.)

So: does anyone know something I could use to accomplish these needs?

I found qtermwidget but it seems more oriented on handling a shell process (and the Python bindings seems to let you run /bin/bash only) by itself than communicating with an already existing process I/O.

gruszczy
  • 40,948
  • 31
  • 128
  • 181
redShadow
  • 6,687
  • 2
  • 31
  • 34
  • @gruszczy: why did you retag from `pyqt4` to `pyqt`? They are two very different Python modules, since `pyqt` was the bindings for the old Qt3 while, of course, PyQt4 is the one for Qt4.. – redShadow Feb 17 '11 at 23:56

2 Answers2

4

Does something like this help?

#!/usr/bin/env python
#-*- coding:utf-8 -*-

import  sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class embterminal(QWidget):

    def __init__(self):
        QWidget.__init__(self)
        self.process = QProcess(self)
        self.terminal = QWidget(self)
        layout = QVBoxLayout(self)
        layout.addWidget(self.terminal)
        self.process.start(
                'xterm',['-into', str(self.terminal.winId())])
        # Works also with urxvt:
        #self.process.start(
                #'urxvt',['-embed', str(self.terminal.winId())])

if __name__ == "__main__":
    app = QApplication(sys.argv)
    main = embterminal()
    main.show()
    sys.exit(app.exec_())
student
  • 1,636
  • 3
  • 29
  • 53
  • Cool, I didn't know it was possible doing that.. it still needs some tweaking (eg. the row count inside the terminal is wrong) but in general seems to be working fine.. – redShadow Feb 08 '13 at 11:58
  • Perhaps you know something about the communicating part and you can help me out with a related question: http://stackoverflow.com/q/14772138/406686 – student Feb 08 '13 at 12:05
  • is it possible to read environment variables to the python application to display info instead of everytime having to type echo command ? – Ciasto piekarz Aug 19 '14 at 06:40
  • The problem with xterm is look and feel. The Xterm look and feel is really bad. – dexterous Oct 14 '15 at 20:02
0

You could try QConsole (http://qconsole.sourceforge.net/). I haven't used it, but it looks like the sort of thing you're looking for.

Optimal Cynic
  • 797
  • 3
  • 6
  • I just tried it, but it seems not to be as cool as the description promises.. I was only able to compile the stand-alone example, and did not find any instruction on how to build a Python module. Also, the example itself seems to be quite buggy, at least when compiled against Qt4 (that will use q3support, as specified on the project page..). I guess that the project focuses more on the TCL imlementation than on the Python one.. – redShadow Dec 15 '10 at 13:38
  • That's a shame. I'm not aware of any others, unfortunately. – Optimal Cynic Dec 16 '10 at 05:11