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).
to_qpainterpath_and_beyond
Tyler Goodlet 2020-11-16 10:18:15 -05:00
parent bfcf5170dc
commit 9572280553
1 changed files with 16 additions and 0 deletions

View File

@ -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,