I am writing a program with PyQT6 to update a progress bar based on output of the pagekite.py file, I'm using QProcess to call the script and a function to handle the output, but the output from the shell when i run the file looks like this:
>>> Hello! This is pagekite.py v1.5.2.201011. [CTRL+C = Stop]
Connecting to front-end relay 00.00.000.00:000 ...
- Relay supports 10 protocols on 23 public ports.
- Raw TCP/IP (HTTP proxied) kites are available.
- To enable more logging, add option: --logfile=/path/to/logfile
~<> Flying localhost:80 as https://test.pagekite.me/
<< pagekite.py [exiting] Good-bye!
But when i get the output of the stdout of QProcess it look like this:
ts=63837a93; t=2022-11-27T14:56:19; ll=7; connect=000.000.00.000:000
ts=63837a94; t=2022-11-27T14:56:20; ll=8; FE=000.000.00.000:000; err=Rejected; proto=http; reason=quota; domain=test.pagekite.me; id=s2
ts=63837a94; t=2022-11-27T14:56:20; ll=9; FE=000.000.00.000:000; ports=79,80,443, ...; protocols=http,http2,http3,https,websocket,irc,finger,httpfinger,raw; raw_ports=virtual
ts=63837a94; t=2022-11-27T14:56:20; ll=a; wrote=484; wbps=114; read=992; eof=1; id=s2
ts=63837a9e; t=2022-11-27T14:56:30; ll=b; FE=000.000.00.000:000; http_ping_ms=693; win=2; uuid=222cf21b34cfd5bed67bace00000d00000dafff0; unbiased_ms=643
ts=63837ab9; t=2022-11-27T14:56:57; ll=c; FE=000.000.00.000:000; http_ping_ms=693; win=2; uuid=222cf21b34cfd5bed67bace00000d00000dafff0; unbiased_ms=64
Here is the code of the program:
import time
import sys
from PyQt6.QtCore import QThread, QProcess
from PyQt6.QtWidgets import (
QApplication,
QDialog,
QDialogButtonBox,
QFormLayout,
QLineEdit,
QVBoxLayout,
QPushButton,
QLabel,
QProgressBar,
)
class ProgressBar(QProgressBar):
def __init__(self, parent=None):
super().__init__(parent)
self.setMaximum(100)
self._active = False
self.setTextVisible(False)
def setBar(self, i):
self.setValue(i)
def changeColor(self, color):
css = """
::chunk {{
background: {0};
}}
""".format(color)
self.setStyleSheet(css)
class Window(QDialog):
def __init__(self):
super().__init__(parent=None)
self.setWindowTitle("QDialog")
dialogLayout = QVBoxLayout()
formLayout = QFormLayout()
confBtn = QPushButton('Configurações')
self.ligarBtn = QPushButton('Iniciar o aplicativo')
statusLbl = QLabel('Desligado')
self.ligado = False
formLayout.addRow(confBtn)
formLayout.addRow(self.ligarBtn)
formLayout.addRow("Status: ", statusLbl)
dialogLayout.addLayout(formLayout)
self.connBar = ProgressBar()
self.connBar.setBar(4)
self.connBar.changeColor('gray')
buttons = QDialogButtonBox()
buttons.addButton('Fechar', QDialogButtonBox.ButtonRole.ActionRole)
dialogLayout.addWidget(self.connBar)
self.ligarBtn.clicked.connect(self.iniciaPageKite)
self.setLayout(dialogLayout)
self.show()
y, x = self.geometry().height(), self.geometry().width()
self.setFixedSize(x, y)
def iniciaPageKite(self):
self.prcs = QProcess()
self.prcs.start('py', ['-2.7', 'pagekite.py', '80', 'test.pagekite.me'])
self.prcs.readyReadStandardOutput.connect(self.pgktOutputHandler)
self.prcs.readyReadStandardOutput.connect(self.pgktErrorHandler)
def defPrgBarPrg(self, val):
self.connBar.setBar(val)
def defPrgBarClr(self, clr):
self.connBar.changeColor(clr)
def pgktOutputHandler(self):
res = self.prcs.readAllStandardOutput()
resc = bytes(res).decode('utf-8')
print(resc)
def pgktErrorHandler(self):
err = self.prcs.readAllStandardError()
errc = bytes(err).decode('utf-8')
print(errc)
if __name__ == "__main__":
app = QApplication([])
window = Window()
app.exec()
sys.exit()
informations:
- python 3.11
- windows 11
- python 2.7 to pagekite
- PyQt6
Sorry for any error or missing information.