Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to embed Terminal(urxvt) it the main window.
Forum Updated to NodeBB v4.3 + New Features

How to embed Terminal(urxvt) it the main window.

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 366 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yugapatil
    wrote on last edited by
    #1

    So I've below code, I want to embed the urxvt terminal int the main window.Right now it opens urxvt in different window.
    Please help me,I'm noob in Qt but somehow I've do it.

    from PyQt5 import QtCore, QtGui, QtWidgets
    from PyQt5.QtGui import QMovie
    import os
    import sys
    from PyQt5.QtCore import Qt, QProcess
    from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QPlainTextEdit, QHBoxLayout, QVBoxLayout
    
    
    class Ui_MainWindow(QWidget):
    
        def __init__(self):
            super().__init__()
            #os.system('python3 lpav6dev.py')
        def setupUi(self, MainWindow):
            MainWindow.setObjectName("MainWindow")
            MainWindow.setWindowFlag(QtCore.Qt.FramelessWindowHint)
            MainWindow.resize(1248, 890)
    
            self.centralwidget = QtWidgets.QWidget(MainWindow)
            self.centralwidget.setObjectName("centralwidget")
            self.label3 = QtWidgets.QLabel(self.centralwidget)
            self.label3.setGeometry(QtCore.QRect(136, 142, 800, 600))
            self.label3.setScaledContents(True)
            # self.label3.setObjectName("label3")
            self.movie = QMovie("use/Rebound.gif")
            self.label3.setMovie(self.movie)
            self.movie.start()
    
            self.Back = QtWidgets.QPushButton(self.centralwidget)
            self.Back.setGeometry(QtCore.QRect(110, 80, 65, 65))
            font = QtGui.QFont()
            font.setPointSize(25)
            font.setBold(True)
            font.setWeight(75)
            self.Back.setFont(font)
            self.Back.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
            self.Back.setFocusPolicy(QtCore.Qt.TabFocus)
            self.Back.setStyleSheet("QPushBiutton{\n"
                                    "    background-color: rgb(0, 0, 0);\n"
                                    "}")
            self.Back.setText("")
            icon3 = QtGui.QIcon()
            icon3.addPixmap(QtGui.QPixmap("use/Back.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.Back.setIcon(icon3)
            self.Back.setIconSize(QtCore.QSize(100, 100))
            self.Back.setObjectName("Back")
            self.Back.clicked.connect(MainWindow.close)
            self.Back.clicked.connect(self.onStart)
    
            self.label1 = QtWidgets.QLabel(self.centralwidget)
            self.label1.setGeometry(QtCore.QRect(0, 0, 1250, 900))
            self.label1.setStyleSheet("")
            self.label1.setFrameShape(QtWidgets.QFrame.NoFrame)
            self.label1.setFrameShadow(QtWidgets.QFrame.Plain)
            self.label1.setLineWidth(1)
            self.label1.setText("")
            self.label1.setPixmap(QtGui.QPixmap("use/BlackBG.png"))
            self.label1.setScaledContents(True)
            self.label1.setObjectName("label1")
            '''self.VoiceButton = QtWidgets.QPushButton(self.centralwidget)
            self.VoiceButton.setGeometry(QtCore.QRect(980, 340, 161, 161))
            self.VoiceButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
            self.VoiceButton.setFocusPolicy(QtCore.Qt.ClickFocus)
            self.VoiceButton.setStyleSheet("QPushButton{\n"
    "rgb(0, 0, 0)\n"
    "}")
            self.VoiceButton.setText("")
            icon1 = QtGui.QIcon()
            icon1.addPixmap(QtGui.QPixmap("use/TrainV.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.VoiceButton.setIcon(icon1)
            self.VoiceButton.setIconSize(QtCore.QSize(161, 161))
            self.VoiceButton.setAutoRepeat(True)
            self.VoiceButton.setAutoExclusive(True)
            self.VoiceButton.setDefault(False)
            self.VoiceButton.setObjectName("VoiceButton")'''
    
            self.FaceButton = QtWidgets.QPushButton(self.centralwidget)
            self.FaceButton.setGeometry(QtCore.QRect(990, 650, 160, 120))
            self.FaceButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
            icon2 = QtGui.QIcon()
            icon2.addPixmap(QtGui.QPixmap("use/FaceDetect.gif"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.FaceButton.setIcon(icon2)
            self.FaceButton.setIconSize(QtCore.QSize(180, 120))
            self.FaceButton.setObjectName("FaceButton")
            self.FaceButton.clicked.connect(self.onClick)
    
            self.ExitButton = QtWidgets.QPushButton('close', self.centralwidget)
            self.ExitButton.setGeometry(QtCore.QRect(1040, 90, 60, 60))
            self.ExitButton.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
            self.ExitButton.setFocusPolicy(QtCore.Qt.NoFocus)
            self.ExitButton.setText("")
            icon3 = QtGui.QIcon()
            icon3.addPixmap(QtGui.QPixmap("use/Exit.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self.ExitButton.setIcon(icon3)
            self.ExitButton.setIconSize(QtCore.QSize(60, 60))
            self.ExitButton.setAutoExclusive(True)
            self.ExitButton.setAutoDefault(True)
            self.ExitButton.setObjectName("ExitButton")
            self.ExitButton.clicked.connect(sys.exit)
    
            self.label1.raise_()
            # self.VoiceButton.raise_()
            self.FaceButton.raise_()
            self.ExitButton.raise_()
            self.label3.raise_()
            self.Back.raise_()
            # self.StartButton.raise_()
            MainWindow.setCentralWidget(self.centralwidget)
    
            self.retranslateUi(MainWindow)
            QtCore.QMetaObject.connectSlotsByName(MainWindow)
            #p=QProcess()
            #
            #p.startDetached('python lpav6dev.py')
    
            
        def onStart(self):
            os.system('python HomePage.py')  
              
        def onClick(self):
            
            face=QProcess()
            face.startDetached('python facectrldev.py')
        
        def retranslateUi(self, MainWindow):
            _translate = QtCore.QCoreApplication.translate
            MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
            # self.StartButton.setToolTip(_translate("MainWindow", "Start"))
            # self.VoiceButton.setToolTip(_translate("MainWindow", "Train Your Voice"))
            self.FaceButton.setToolTip(_translate("MainWindow", "Face Detect"))
            self.ExitButton.setToolTip(_translate("MainWindow", "Exit"))
            self.Back.setToolTip(_translate("MainWindow", "MainWindow"))
    class Window(QWidget):
        def __init__(self):
            super().__init__()
            self.process = QProcess(self)
            self.terminal = QWidget(self)
            layout = QVBoxLayout(self)
            layout.addWidget(self.terminal)
            wid = str(int(self.terminal.winId()))
            self.process.start('urxvt', ['-embed', wid])
    
        def closeEvent(self, event):
            self.process.terminate()
            self.process.waitForFinished(1000)
    
    if __name__ == "__main__":
        import sys
        app = QtWidgets.QApplication(sys.argv)
        MainWindow = QtWidgets.QMainWindow()
        ui2 = Ui_MainWindow()
        ui2.setupUi(MainWindow)
        window=Window()
        window.setGeometry(100, 100, 700, 400)
        window.show()
     
        MainWindow.show()
        sys.exit(app.exec_())
       
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you sure you are passing a valid winId value ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved