【发布时间】:2016-10-15 20:28:02
【问题描述】:
我有一个烦人的问题,过去几个月我一直无法解决。基本上,我使用 jupyter/ipython notebook 来调用 pyqt 并显示 3d 几何数据。这就是我将应用程序初始化为对象的方式,在添加了一些多边形和点之后,我调用了 show():
class Figure(object):
'''
Main API functions
'''
def __init__(self):
print "... initializing canvas ..."
self.app = QApplication(sys.argv)
self.app.processEvents()
...
def show(self): #Show
self.GUI = GLWindow(data)
self.app.exec_()
我想通过笔记本单元不断地交互/更新小部件。但是,一旦我在 jupyter notebook 中调用 show() 命令,我就无法再运行任何单元格或更新小部件,因为 notebook 输出排队(?)并被锁定:
#Initialize figure object inside the notebook
fig = plb.figure()
...
fig.show() #Locks out any further jupyter commands while widget on screen
fig.update() #Does not get executed until widget is closed
似乎通过笔记本调用的 .show() 函数放弃了对 python 内核的控制 (?) 但目前尚不清楚如何将其取回,以及如何将其连接到正在显示的小部件。
鼠标和键盘事件确实与小部件交互,但它们使用小部件代码内部的内部函数,例如 mouseMoveEvent():
class GLWindow(QtGui.QWidget):
def __init__(self, fig, parent=None):
QtGui.QWidget.__init__(self, parent)
self.glWidget = GLWidget(fig, parent=self)
...
class GLWidget(QtOpenGL.QGLWidget):
def __init__(self, fig, parent=None):
QtOpenGL.QGLWidget.__init__(self, parent)
...
def mouseMoveEvent(self, event):
buttons = event.buttons()
modifiers = event.modifiers()
dx = event.x() - self.lastPos.x()
dy = event.y() - self.lastPos.y()
...
我已尝试遵循相关建议,但我不明白如何在小部件之外使用连接或事件。
感谢任何帮助,我花了很多时间试图解决这个问题,这很尴尬。猫
【问题讨论】:
标签: events pyqt ipython jupyter