├── README.md ├── app.py ├── gui.ui └── program.png /README.md: -------------------------------------------------------------------------------- 1 | ## Very basic PyQt terminal emulator 2 | 3 | This is a very basic terminal emulator written in Python PyQt. 4 | It lets you run commands and see output, as the screenshot below: 5 | 6 | ![program](/program.png) 7 | 8 | ## Development 9 | 10 | Developed in Python, 11 | 12 | * https://pythonbasics.org/ 13 | * https://pythonprogramminglanguage.com/ 14 | 15 | Uses PyQt framework 16 | 17 | * https://pythonbasics.org/pyqt/ 18 | * https://pythonprogramminglanguage.com/pyqt/ 19 | 20 | Install PyQt 21 | 22 | * https://pythonbasics.org/install-pyqt/ 23 | * https://pythonprogramminglanguage.com/pyqt5-hello-world/ 24 | 25 | 26 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | # very basic terminal emulator in pyqt 2 | # https://pythonbasics.org/pyqt/ 3 | 4 | from PyQt5 import QtWidgets, uic 5 | from PyQt5.QtWidgets import QMessageBox 6 | from PyQt5.QtWidgets import QMessageBox, QDialog, QFileDialog 7 | import sys 8 | import os 9 | import subprocess 10 | 11 | class Example(QtWidgets.QMainWindow): 12 | def __init__(self): 13 | super(Example, self).__init__() 14 | uic.loadUi('gui.ui', self) 15 | self.lineEdit.returnPressed.connect(self.doCMD) 16 | #self.pushButtonInstall.clicked.connect(self.onClick) 17 | self.working_dir = "." 18 | 19 | def doCMD(self): 20 | cmd = self.lineEdit.text() 21 | self.lineEdit.setText("") 22 | 23 | if "cd " in cmd: 24 | vals = cmd.split(" ") 25 | if vals[1][0] == "/": 26 | self.working_dir = vals[1] 27 | else: 28 | self.working_dir = self.working_dir + "/" + vals[1] 29 | 30 | print(self.working_dir) 31 | subprocess.call(cmd, shell=True, cwd=self.working_dir) 32 | 33 | self.textBrowser.setText( self.textBrowser.toPlainText() + "\n$ " + cmd ) 34 | else: 35 | result = subprocess.check_output(cmd, shell=True, cwd=self.working_dir) 36 | self.textBrowser.setText( self.textBrowser.toPlainText() + "\n$ " + cmd + result.decode("utf-8") ) 37 | 38 | self.textBrowser.verticalScrollBar().setValue(self.textBrowser.verticalScrollBar().maximum()) 39 | 40 | #def onClick(self): 41 | # if len(self.lineEditName.text()) < 1: 42 | # QMessageBox.critical(self, "Install", "Install") 43 | # else: 44 | # os.system("sudo apt-get install " + self.lineEditName.text()) 45 | 46 | app = QtWidgets.QApplication([]) 47 | win = Example() 48 | win.show() 49 | sys.exit(app.exec()) 50 | -------------------------------------------------------------------------------- /gui.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 651 10 | 445 11 | 12 | 13 | 14 | Basic Terminal 15 | 16 | 17 | 18 | ../../../../../../usr/share/icons/gnome/32x32/apps/terminal.png../../../../../../usr/share/icons/gnome/32x32/apps/terminal.png 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | DejaVu Sans Mono 27 | 10 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | Monospace 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 0 47 | 0 48 | 651 49 | 22 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /program.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/petercour/terminal-emulator-example-pyqt/d19f6ac099d07dd36e3d13b6b2b70a7e346c2dcf/program.png --------------------------------------------------------------------------------