我正在使用PyQT5,并且我想在TabWidget内运行一个外部窗口,类似to that,但是此示例仅适用于Windows,并且我想在linux(Ubuntu 14.04)操作系统中运行。我在此thread中也发现了类似的问题,但是答案没有用。还尝试了解决方法here,但也没有用。可以嵌入一个终端,例如this code,但是我不知道如何使用RViz命令执行同样的操作。我下面有一些代码,他使用 wmctrl 来选择RViz(我想嵌入到GUI中的应用程序)窗口ID,然后尝试将其放入“ fromWinID()”类,但是窗口在我的应用程序外部打开,并收到错误消息:
QXcbConnection: XCB error: 3 (BadWindow), sequence: 415, resource id: -1222189812, major code: 7 (ReparentWindow), minor code: 0
QXcbConnection: XCB error: 3 (BadWindow), sequence: 460, resource id: -1222189812, major code: 7 (ReparentWindow), minor code: 0
QXcbConnection: XCB error: 3 (BadWindow), sequence: 461, resource id: -1222189812, major code: 8 (MapWindow), minor code: 0
QXcbConnection: XCB error: 3 (BadWindow), sequence: 463, resource id: -1222189812, major code: 18 (ChangeProperty), minor code: 0
QXcbConnection: XCB error: 3 (BadWindow), sequence: 464, resource id: -1222189812, major code: 12 (ConfigureWindow), minor code: 0
有人可以帮忙吗?
# -*- coding: utf-8 -*-
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
import subprocess
from subprocess import call, Popen, PIPE, check_output
class Container(QtWidgets.QTabWidget):
def __init__(self):
QtWidgets.QTabWidget.__init__(self)
rvizCommand = 'rviz'
# Using Popen instead of Call to dont block the process
subprocess.Popen(rvizCommand, stdout=PIPE,
stdin=PIPE, shell=True)
# wmctrl to find the active hexadecimal
lookForID = "wmctrl -l | grep -i RViz | awk '{print $1}'"
rvizID = subprocess.check_output(lookForID, shell=True)
rvizID = str(rvizID.rstrip("\n"))
print(rvizID)
window = QtGui.QWindow.fromWinId(rvizID)
container = QtWidgets.QWidget.createWindowContainer(window, self)
self.addTab(container, 'RViz')
app = QtWidgets.QApplication(sys.argv)
rviz = Container()
rviz.show()
sys.exit(app.exec_())