How to: Jupyter notebook update PyQt4 widget

736 views
Skip to first unread message

Cat _

unread,
Oct 16, 2016, 3:27:55 AM10/16/16
to Project Jupyter

I have an annoying issue that I have not been able to solve for the past few months. Basically, I'm using jupyter/ipython notebook as an API to call pyqt and display 3d geometric data. This is how I initialize the app into an object and after I add some polygons and points, I call 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_()


The problem is that once I call the show command in the jupyter notebook I can't do live updates to the widget as the notebook input is locked out:


#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


I already have the mouse events working fine (i.e. I can rotate and click on the widget window displaying 3D info) using intrinsic functions like mouseMoveEvent() that are inside the widget code:


    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()
                ...


But I can't figure out how to use events to call the widget app from outside the widget code so the notebook can interact with the app. I've tried to follow a couple of related suggestions, but it is not clear to me how to do this.


Any help is appreciated, I've spent so many hours on trying to fix this it's embarrassing. 

Cat

Thomas Kluyver

unread,
Oct 17, 2016, 7:26:53 AM10/17/16
to Project Jupyter
On 16 October 2016 at 08:27, Cat _ <mite...@gmail.com> wrote:
The problem is that once I call the show command in the jupyter notebook I can't do live updates to the widget as the notebook input is locked out:

IPython has some functionality to integrate with GUI event loops, so that both the GUI and your input can continue to be processed. You'll need the '%gui qt' magic, and a bit of integration as shown here:

https://github.com/ipython/ipython/blob/master/examples/IPython%20Kernel/gui/gui-qt.py

Cat _

unread,
Oct 18, 2016, 12:48:23 AM10/18/16
to Project Jupyter
Takowl

That's it!  It worked, I've been looking to solve this problem for at least 2 months.   

I don't know how to thank you man.  Can I donate some cash to this forum or a charity of your choice... I had posted this as a job on upwork a while back, and nobody jumped in...

So happy this is finally solved... 

Thomas Kluyver

unread,
Oct 18, 2016, 7:16:20 AM10/18/16
to Project Jupyter
On 18 October 2016 at 05:48, Cat _ <mite...@gmail.com> wrote:
I don't know how to thank you man.  Can I donate some cash to this forum or a charity of your choice...

This is part of my job, so no donations necessary! If you want to help, though, you can keep an eye out for questions you know the answer to on this mailing list, on Github or on Stackoverflow. :-)

If you are keen to make a financial donation, both Jupyter and IPython accept donations through the NumFOCUS foundation, which is a US nonprofit. You can make an earmarked donation through http://jupyter.org/donate.html or http://ipython.org/donate.html . This is totally up to you, though!

Thomas

Cat _

unread,
Oct 18, 2016, 2:47:03 PM10/18/16
to Project Jupyter
Super, I made a small donation (I'm a broke student).

Really thanks again for this help.
Cat

Thomas Kluyver

unread,
Oct 18, 2016, 3:46:04 PM10/18/16
to Project Jupyter
Thanks Cat! Best of luck with your studies. :-)

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/737a8d11-44f8-4ab3-85af-f5b2cc2597b8%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages