secret
Created

  • Download Gist
xembedder.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#!/usr/bin/env python
import sys, atexit
 
from PyQt4.QtCore import *
from PyQt4.QtGui import *
 
WIN_ID = object()
 
class EmbedApp(QX11EmbedContainer):
def __init__(self, cmd, args, parent=None):
super().__init__(parent)
self.cmd = cmd
self.args = args
self.process = QProcess(self)
self.process.finished.connect(lambda c, s: self.close())
atexit.register(self.kill)
def showEvent(self, evt):
args = [a if a is not WIN_ID else str(self.winId()) for a in self.args]
self.process.start(self.cmd, args)
if self.process.error() == QProcess.FailedToStart:
print('process failed to start')
def kill(self):
self.process.kill()
self.process.waitForFinished()
def sizeHint(self):
size = QSize(400, 300)
return size.expandedTo(QApplication.globalStrut())
 
if __name__ == '__main__':
app = QApplication(sys.argv)
w = QWidget()
w.setLayout(QHBoxLayout())
w.layout().addWidget(EmbedApp('xterm', ["-into", WIN_ID]))
w.layout().addWidget(EmbedApp('xterm', ["-into", WIN_ID]))
w.show()
sys.exit(app.exec_())

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.