90 lines
3.1 KiB
Python
90 lines
3.1 KiB
Python
import os
|
|
import sys
|
|
import signal
|
|
import logging
|
|
import platform
|
|
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QScrollBar, QGraphicsView, QGraphicsScene, QGraphicsProxyWidget
|
|
from PyQt5.QtCore import Qt, QCoreApplication
|
|
from PyQt5.QtGui import QFont, QScreen
|
|
|
|
import termqt
|
|
from termqt import Terminal, TerminalPOSIXExecIO
|
|
|
|
class ExitOnMessageHandler(logging.Handler):
|
|
def emit(self, record):
|
|
if "Spawned process has been killed" in record.getMessage():
|
|
QApplication.quit() # Exit the application gracefully
|
|
|
|
def setup_logger():
|
|
logger = logging.getLogger()
|
|
logger.setLevel(logging.DEBUG)
|
|
handler = logging.StreamHandler()
|
|
formatter = logging.Formatter("[%(asctime)s] > [%(filename)s:%(lineno)d] %(message)s")
|
|
handler.setFormatter(formatter)
|
|
logger.addHandler(handler)
|
|
handler2 = ExitOnMessageHandler()
|
|
logger.addHandler(handler2)
|
|
return logger
|
|
|
|
def create_terminal_app():
|
|
os.environ["XDG_RUNTIME_DIR"] = "/var/tmp/weston"
|
|
os.environ["WAYLAND_DISPLAY"] = "wayland-0"
|
|
os.environ["QT_QPA_PLATFORM"] = "wayland"
|
|
os.environ["QT_WAYLAND_SHELL_INTEGRATION"] = "wl-shell"
|
|
|
|
|
|
QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
|
|
app = QApplication(sys.argv)
|
|
desktop = QApplication.desktop()
|
|
ag = desktop.availableGeometry(desktop.primaryScreen())
|
|
print (ag.width())
|
|
print (ag.height())
|
|
|
|
window = QWidget()
|
|
window.setWindowTitle("termqt on {}".format(platform.system()))
|
|
window.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
|
|
window.setGeometry(0,0, ag.width(), ag.height())
|
|
window.setStyleSheet("background-color: black;")
|
|
window.showFullScreen()
|
|
|
|
scene = QGraphicsScene()
|
|
view = QGraphicsView(scene, window)
|
|
print (window.width())
|
|
print (window.height())
|
|
view.setGeometry(0, 0, window.width(), window.height())
|
|
view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
|
|
layout = QHBoxLayout()
|
|
terminal = Terminal(window.width(), window.height(), logger=setup_logger(), font_size=32)
|
|
|
|
proxy_terminal = scene.addWidget(terminal)
|
|
view.setScene(scene)
|
|
view.rotate(90) # Rotate the view by 90 degrees clockwise
|
|
|
|
window_layout = QHBoxLayout(window)
|
|
window_layout.addWidget(view)
|
|
window_layout.setContentsMargins(0,0,0,0)
|
|
window.setLayout(window_layout)
|
|
|
|
return app, window, terminal
|
|
|
|
def main():
|
|
signal.signal(signal.SIGINT, signal.SIG_DFL) # Enable Ctrl+C
|
|
if len(sys.argv) < 2:
|
|
print("Usage: python start.py '<command>'")
|
|
return
|
|
|
|
command = "bash -c '{}'".format(sys.argv[1])
|
|
app, window, terminal = create_terminal_app()
|
|
platform_name = platform.system()
|
|
terminal_io = TerminalPOSIXExecIO(terminal.col_len, terminal.row_len, command, os.environ, setup_logger())
|
|
terminal_io.stdout_callback = terminal.stdout
|
|
terminal.stdin_callback = terminal_io.write
|
|
terminal.resize_callback = terminal_io.resize
|
|
terminal_io.spawn()
|
|
exit_code = app.exec_()
|
|
sys.exit(exit_code)
|
|
|
|
if __name__ == "__main__":
|
|
main() |