Advertisement
Guest User

embed_terminal_6.py

a guest
Jun 29th, 2020
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import atexit
  3.  
  4. from PyQt5.QtCore import *
  5. from PyQt5.QtGui import *
  6. from PyQt5.QtWidgets import QApplication, QWidget
  7.  
  8. class XTerm(QWidget):
  9.  
  10.     def __init__(self, parent, xterm_cmd="xterm"):
  11.         QWidget.__init__(self, parent)
  12.         self.xterm_cmd = xterm_cmd
  13.         self.process = QProcess(self)
  14.         self.connect(self.process,
  15.                      pyqtSignal("finished(int, QProcess::ExitStatus)"),
  16.                      self.on_term_close)
  17.         atexit.register(self.kill)
  18.  
  19.     def kill(self):
  20.         self.process.kill()
  21.         self.process.waitForFinished()
  22.  
  23.     def sizeHint(self):
  24.         size = QSize(400, 300)
  25.         return size.expandedTo(QApplication.globalStrut())
  26.  
  27.     def show_term(self):
  28.         args = [
  29.             "-into",
  30.             str(self.winId()),
  31.             "-bg",
  32.             "#000000",  # self.palette().color(QPalette.Background).name(),
  33.             "-fg",
  34.             "#f0f0f0",  # self.palette().color(QPalette.Foreground).name(),
  35.             # border
  36.             "-b", "0",
  37.             "-w", "0",
  38.             # blink cursor
  39.             "-bc",
  40.         ]
  41.         self.process.start(self.xterm_cmd, args)
  42.         if self.process.error() == QProcess.FailedToStart:
  43.             print("xterm not installed")
  44.  
  45.     def on_term_close(self, exit_code, exit_status):
  46.         print("close", exit_code, exit_status)
  47.         self.close()
  48.  
  49. main_frame = XTerm()
  50. main_frame.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement