From 957228055317a6f06dddfe4712ee0d62805e7d43 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 16 Nov 2020 10:18:15 -0500 Subject: [PATCH] Kill the tractor tree on window close. This makes it so you don't have to ctrl-c kill apps. Add in the experimental openGL support even though I'm pretty sure it's not being used much for curve plotting (but could be wrong). --- piker/ui/_exec.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/piker/ui/_exec.py b/piker/ui/_exec.py index 732db3e2..3e3f57bf 100644 --- a/piker/ui/_exec.py +++ b/piker/ui/_exec.py @@ -26,6 +26,7 @@ from typing import Tuple, Callable, Dict, Any # Qt specific import PyQt5 # noqa +import pyqtgraph as pg from pyqtgraph import QtGui from PyQt5 import QtCore from PyQt5.QtCore import ( @@ -37,6 +38,12 @@ import tractor from outcome import Error +# pyqtgraph global config +# might as well enable this for now? +pg.useOpenGL = True +pg.enableExperimental = True + + # singleton app per actor _qt_app: QtGui.QApplication = None _qt_win: QtGui.QMainWindow = None @@ -67,6 +74,12 @@ class MainWindow(QtGui.QMainWindow): self.setMinimumSize(*self.size) self.setWindowTitle(self.title) + def closeEvent(self, event: 'QCloseEvent') -> None: + """Cancel the root actor asap. + + """ + tractor.current_actor().cancel_soon() + def run_qtractor( func: Callable, @@ -131,6 +144,9 @@ def run_qtractor( instance = main_widget() instance.window = window + # kill the app when root actor terminates + tractor._actor._lifetime_stack.callback(app.quit) + widgets = { 'window': window, 'main': instance,