Skip to content

Instantly share code, notes, and snippets.

@legendofmiracles
Last active July 4, 2020 16:51
Show Gist options
  • Save legendofmiracles/11f70ce94029b28e5a28d7622c4007e6 to your computer and use it in GitHub Desktop.
Save legendofmiracles/11f70ce94029b28e5a28d7622c4007e6 to your computer and use it in GitHub Desktop.
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QPushButton, QAction, QLineEdit, QMessageBox, QTextEdit
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
import subprocess;
import os;
import pathlib;
class App(QMainWindow):
def __init__(self):
super().__init__()
self.title = 'Yet another bad terminal emulator'
self.left = 100
self.top = 100
self.width = 1920
self.height = 1080
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
# Create textbox
self.textbox = QLineEdit(self)
self.textbox.move(20, 20)
self.textbox.resize(280,40)
self.textbox.returnPressed.connect(self.on_click)
# Create a button in the window
self.button = QPushButton('Run!', self)
self.button.move(20,80)
# connect button to function on_click
self.button.clicked.connect(self.on_click)
# output text box
self.output = QTextEdit(self)
self.output.move(20,120)
self.output.resize(1500,800)
self.output.setReadOnly(True)
self.show()
@pyqtSlot()
def on_click(self):
textboxValue = self.textbox.text().split(" ");
command = [];
exceptions = ["cd", "dir"];
#command.append(textboxValue[0])
cmd_output = "if you see this, then you executed a command without any output, or a command that didn't exist.";
for i in range(len(textboxValue)):
command.append(textboxValue[i])
print(command);
if not command[0] in exceptions:
try:
cmd_output = subprocess.run(command, capture_output=True, text=True);
except:
print("LMAO THAT DOESN'T EXIST")
elif command[0] == exceptions[0]:
if len(command) <= 1:
os.chdir(pathlib.Path.home())
else:
os.chdir(command[1])
elif command[0] == exceptions[1]:
dirs = os.listdir(".")
for file in dirs:
cmd_output = file
else:
cmd_output = "error"
self.textbox.setText("")
print(cmd_output)
if hasattr(cmd_output, 'stdout'):
self.output.setPlainText(cmd_output.stdout)
elif hasattr(cmd_output, 'stderr'):
self.output.setPlainText(cmd_output.stderr)
else:
self.output.setPlainText("no text")
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
@kvbc
Copy link

kvbc commented Jun 14, 2020

thanks now i can hack my school

@emilydaemon
Copy link

thanks now i can hack my school

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment