python - PyQt QApplication.aboutToQuit() -
i'm trying catch global quit signal application class subclasses qapplication. here how attempt set in main.
def cleanup(): os.system('rosnode kill -a') sys.exit(0) ## start qt event loop if __name__ == '__main__': app = application(sys.argv) app.abouttoquit.connect(cleanup) app.exec_()
the issue doesn't seem catch signal have apparently connected.
edit
i'm using pyqtgraph, preferably there way catch global window closes?
# main application class application(qtgui.qapplication): def __init__(self, args): qtgui.qapplication.__init__(self, args) self.plot = pg.plot(title="uwb") self.raw_signal = self.plot.plot() self.filtered_signal = self.plot.plot() # start main loop self.listen()
you can override close event when qmainwindow
closed. might useful depending on use case.
# override exit event def closeevent(self, event): cleanup() # close window event.accept()
edit: minimal example works me; 'closing' printed when plot window closed.
import pyqtgraph pg pyqt4 import qtgui import sys # main application class application(qtgui.qapplication): def __init__(self, args): qtgui.qapplication.__init__(self, args) self.plot = pg.plot(title="uwb") def cleanup(self): print 'closing' ## start qt event loop if __name__ == '__main__': app = application(sys.argv) app.abouttoquit.connect(app.cleanup) sys.exit(app.exec_())
Comments
Post a Comment