-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatplotlib_qt_signals.py
More file actions
38 lines (29 loc) · 940 Bytes
/
matplotlib_qt_signals.py
File metadata and controls
38 lines (29 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# coding=utf-8
# Author: Diego Gonzalez Chavez
# email : diegogch@cbpf.br / diego.gonzalez.chavez@gmail.com
import matplotlib
import types
_bk = matplotlib.get_backend()
if _bk == 'Qt5Agg':
from PyQt5 import QtCore
elif _bk == 'Qt4Agg':
from PyQt4 import QtCore
else:
raise(ImportError('Matplotlib backend must Qt4Agg or Qt5Agg'))
class Main_Loop_Caller(QtCore.QObject):
signal = QtCore.pyqtSignal()
def __init__(self, func):
super().__init__()
self.func = func
self.args = list()
self.kwargs = dict()
self.signal.connect(self._target)
def __get__(self, instance, owner):
# Allows the use of the decorator inside classes
return types.MethodType(self, instance)
def _target(self):
self.func(*self.args, **self.kwargs)
def __call__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
self.signal.emit()