我尚未对此进行专门测试,因为我的Qt5版本太旧,现在无法升级,而从Qt5
5.10开始,startDetached还返回pid以及启动过程中的布尔结果。在我的测试中,在开始等待窗口创建的while周期之前,我手动设置了procId(通过静态QInputBox.getInt())。显然,还有其他方法可以执行此 *** 作(并获取窗口的xid)。
import sysfrom PyQt5 import QtCore, QtGui, QtWidgetsimport gigi.require_version('Wnck', '3.0')from gi.repository import Wnck, Gdkclass Container(QtWidgets.QTabWidget): def __init__(self): QtWidgets.QTabWidget.__init__(self) self.embed('xterm') def embed(self, command, *args): proc = QtCore.QProcess() proc.setProgram(command) proc.setArguments(args) started, procId = proc.startDetached() if not started: QtWidgets.QMessageBox.critical(self, 'Command "{}" not started!') return attempts = 0 while attempts < 10: screen = Wnck.Screen.get_default() screen.force_update() # this is required to ensure that newly mapped window get listed. while Gdk.events_pending(): Gdk.event_get() for w in screen.get_windows(): if w.get_pid() == procId: window = QtGui.QWindow.fromWinId(w.get_xid()) container = QtWidgets.QWidget.createWindowContainer(window, self) self.addTab(container, command) return attempts += 1 QtWidgets.QMessageBox.critical(self, 'Window not found', 'Process started but window not found')app = QtWidgets.QApplication(sys.argv)w = Container()w.show()sys.exit(app.exec_())
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)