How to embed an URxvt terminal in a Pyqt5 GUI?

181 Views Asked by At

I have constructed a GUI in QtChooser and the code for it is written in PyQt5. I have a total of 7 tabs in the GUI, each of which are defined in the QMainWindow class of my code. These definitions contain the codes for each TextEdit, LineEdit, PushButtons, RadioButtons, etc. However, in one the the tabs, I want to embed an external terminal which will open when a particular PushButton is clicked within that tab. I was able to open the Urxvt terminal when the RadioButton is toggled. The issue I'm facing now is to open the terminal specifically in the area of the TextEdit. This is how the original GUI (built in the QtDesigner looks like. I need the terminal to open in the TextEdit below the Output label. But, this is how the terminal opens in the GUI when the code is run This is a part of the updated code:

from PyQt5 import QtCore, QtGui, QtWidgets, uic
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QPushButton, QMessageBox, QAction
from PyQt5.QtCore import QDate, QTime, QDateTime, Qt
import sys
import platform
import os
import subprocess
import time
import re
import textwrap

class EmbTerminal(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(EmbTerminal, self).__init__()
        self.process = QtCore.QProcess(self)
        self.terminal = QtWidgets.QWidget(self)
        layout = QtWidgets.QVBoxLayout(self)
        layout.addWidget(self.terminal)
        # Works also with urxvt:
        self.process.start('urxvt',['-embed', str(int(self.winId())), '-bg', '#000000', '-fg', '#ffffff'])
        self.setFixedSize(539, 308)

class Ui_Dialog(QtWidgets.QMainWindow):
    def __init__(self):
        super(Ui_Dialog, self).__init__()
        #Load GUI from QT5 Designer
        uic.loadUi("S1_mainwindow.ui", self)

def openTerminalCheckBox (self):
        if self.openTerminalRMachineRadioButton.isChecked():
            status = True
            self.commandLineRemoteCommandRMachineLineEdit.setDisabled(True)
            self.commandlineRemoteCommandRMachineLabel.setDisabled(True)
            self.executeRemoteCommandRMachinePushButton.setDisabled(True)
            self.remoteMachineOutputLabel.setText("Terminal")

            self.outputRMachineTextEdit = QtWidgets.QTabWidget()
            self.gridLayout_6.addWidget(self.outputRMachineTextEdit)

            self.outputRMachineTextEdit.addTab(EmbTerminal(), "EmbTerminal")
        else:
            status = False
app = QtWidgets.QApplication(sys.argv) # Create an instance of QtWidgets.QApplication
window = Ui_Dialog()
main = mainWindow()
main.show() # Create an instance of our class
app.exec_()

I need to open the terminal specifically in the QTextEdit which is already been defined in that tab. Do you guys have any suggestions/input?

0

There are 0 best solutions below