Search for PyQt4 Embedded Widget

I wrote an application that, among other things, runs some “backend processes” to do some things. These subprocesses are likely to fail or unexpected behavior, as they should work in rather difficult conditions, so I prefer to control them completely for the operator.

NOTE. . I execute these processes using a subprocessmodule-based class , instead QProcess, to have some more control functionality during the current process.

I am currently using a widget QPlainTextEditto which I am adding standard output / error from a subprocess, as well as some buttons to quickly send some common signals (INT, STOP, CONT, KILL, ..) but:

  • In some cases, it would also be useful to send some data. Although this can be done using an input text box, I would rather use 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 console management with automatic scrolling, but it was not guaranteed to work 100% (sometimes the scroll lock does not work as expected, etc.).

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

I found qtermwidget , but it is more focused on processing the shell process (and the Python bindings seem to allow you to run /bin/bashonly) by itself, rather than linking to an existing I / O process.

+3
source share
2 answers

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_())
+4
source

You can try QConsole (http://qconsole.sourceforge.net/). I have not used it, but it looks like what you are looking for.

0
source

Source: https://habr.com/ru/post/1780394/


All Articles