0

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?

Shriya
  • 27
  • 5
  • 1
    Your question is unclear. Can you clarify exactly what is your "issue"? – musicamante Mar 05 '20 at 13:34
  • I rephrased my original question with a few additional details and some modifications. Could you take a second look at it? – Shriya Mar 06 '20 at 08:54
  • Why are you setting again a new central widget?! – musicamante Mar 06 '20 at 10:32
  • I removed the central widget. But the terminal doesn't open in the TextEdit like I specify it to ```self.outputRMachineTextEdit = QtWidgets.QTabWidget() self.gridLayout_6.addWidget(self.outputRMachineTextEdit) self.outputRMachineTextEdit.addTab(EmbTerminal(), "EmbTerminal") ``` – Shriya Mar 06 '20 at 12:39
  • Please update the question with the edited code, also please be careful about [code formatting and indentation](https://meta.stackexchange.com/a/22189). – musicamante Mar 06 '20 at 13:31
  • I have added the updated code. I've made sure there are no indentation errors too. – Shriya Mar 06 '20 at 14:06
  • There are still indentation errors. Always check the preview. That said: 1. How can you expect to show the terminal in a QTextEdit? It doesn't make any sense; 2. Even if it did (and it really doesn't), it wouldn't work anyway, since you're creating the terminal in a *new* QWidget, then you add it as a tab to a *new* QTabWidget, and finally you're adding that tab widget to the main layout. 3. Provide the .ui file – musicamante Mar 06 '20 at 15:01
  • Unfortunately, the professor wants the terminal to open in the TextEdit. The TextEdit displays the output of certain commands given by the user. He believes that if the user wants to connect to the server, he can use the terminal which will pop up in place of the output TextEdit. If this is not possible, how would you suggest I go about this? Is it better for me to open the terminal in an entirely new Tab of the GUI? – Shriya Mar 09 '20 at 08:44
  • By disabling the TextEdit (via ```setVisible(False)```) I was able to open the terminal in place of the TextEdit. Now, I'm facing an issue of exiting the terminal with a click of a button and reverting back to the original design (where the TextEdit is now visible). – Shriya Mar 09 '20 at 10:39
  • Please, stop providing informations at bits and pieces. When you create a question you should provide as much information and background as possible. Also, if you have another problem that is not strictly inherent to the current issue, you should create a new answer. Finally, as I already asked you, please provide the ui file. – musicamante Mar 09 '20 at 11:10

0 Answers0