pyqt4 - simple IPython example raises exception on sys.exit() -
i'm doing simple pyside (and pyqt) tutorials in ipython. 1 tutorial creates window sliders demonstrate slots , signals.
when close window of running demo application, see error:
an exception has occurred, use %tb see full traceback. systemexit: 0 exit: use 'exit', 'quit', or ctrl-d. so run %tb , this:
systemexit traceback (most recent call last) /workspaces/scratch/<ipython-input-1-88966dcfb499> in <module>() 33 34 if __name__ == "__main__": ---> 35 main() /workspaces/scratch/<ipython-input-1-88966dcfb499> in main() 29 w.show() 30 app.exec_() ---> 31 sys.exit(0) 32 33 systemexit: 0 if try execute code again, this:
runtimeerror: qapplication instance exists. in case helps, here code:
from pyside.qtcore import * pyside.qtgui import * import sys class mywindow(qwidget): def __init__(self): qwidget.__init__(self, none) vbox = qvboxlayout(self) self.slider1 = qslider(qt.horizontal) self.slider1.setrange(0, 99) self.slider1.setvalue(0) vbox.addwidget(self.slider1) self.slider2 = qslider(qt.horizontal) self.slider2.setrange(0, 99) self.slider2.setvalue(99) vbox.addwidget(self.slider2) self.slider1.valuechanged.connect(self.slider2changed) def slider2changed(self, position): self.slider2.setvalue(self.slider2.maximum() - position) def main(): app = qapplication(sys.argv) w = mywindow() w.show() app.exec_() sys.exit(0) if __name__ == "__main__": main() i not have errors when running code using python:
python myexample.py this error happens when run code in ipython (including notebook or qtconsole or regular ipython terminal).
update: main problem cannot run application again , easily. if try run code again, this:
runtimeerror: qapplication instance exists. that kills fast, interactive nature of ipython :(
what need cause qapplication deleted later in:
app = qapplication(sys.argv) app.abouttoquit.connect(app.deletelater) using code can rerun application many times want in ipython, or anywhere else , every time close qt application, object deleted in python.
Comments
Post a Comment