mirror of
https://github.com/Athemis/PyDSF.git
synced 2025-04-05 14:46:03 +00:00
Custom Navigation; Fix mouse events causing lag
This commit is contained in:
parent
1ef02beebb
commit
07d44ba86e
1 changed files with 36 additions and 13 deletions
|
@ -1,27 +1,50 @@
|
||||||
from PyQt5 import QtWidgets, QtGui, QtCore
|
from PyQt5 import QtWidgets
|
||||||
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
|
from matplotlib.backends.backend_qt5agg import (FigureCanvasQTAgg as
|
||||||
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
|
FigureCanvas)
|
||||||
|
from matplotlib.backends.backend_qt5agg import (NavigationToolbar2QT as
|
||||||
|
NavigationToolbar)
|
||||||
from matplotlib.figure import Figure
|
from matplotlib.figure import Figure
|
||||||
|
|
||||||
|
|
||||||
class MplCanvas(FigureCanvas):
|
class MplCanvas(FigureCanvas):
|
||||||
def __init__(self):
|
def __init__(self, parent=None, width=4, height=5, dpi=100):
|
||||||
self.fig = Figure()
|
self.fig = Figure(figsize=(width, height), dpi=dpi)
|
||||||
self.ax = self.fig.add_subplot(111)
|
self.ax = self.fig.add_subplot(111)
|
||||||
FigureCanvas.__init__(self, self.fig)
|
FigureCanvas.__init__(self, self.fig)
|
||||||
FigureCanvas.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
|
self.setParent(parent)
|
||||||
|
FigureCanvas.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding,
|
||||||
|
QtWidgets.QSizePolicy.Expanding)
|
||||||
FigureCanvas.updateGeometry(self)
|
FigureCanvas.updateGeometry(self)
|
||||||
self.setFocusPolicy(QtCore.Qt.StrongFocus)
|
|
||||||
|
# override mouseMoveEvent with non-functional dummy
|
||||||
|
# this will prevent the gui thread to hang while moving the mouse
|
||||||
|
# while a large number of plots is shown simultaniously
|
||||||
|
def mouseMoveEvent(self, event):
|
||||||
|
pass
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.ax.clear()
|
self.ax.clear()
|
||||||
self.fig.clear()
|
self.fig.clear()
|
||||||
|
|
||||||
class MplWidget(QtWidgets.QWidget):
|
|
||||||
def __init__(self, parent = None):
|
class CustomNavigationToolbar(NavigationToolbar):
|
||||||
QtWidgets.QWidget.__init__(self, parent)
|
toolitems = (
|
||||||
|
('Save', 'Save the figure', 'filesave', 'save_figure'),
|
||||||
|
('Subplots', 'Configure subplots', 'subplots', 'configure_subplots'),
|
||||||
|
(None, None, None, None), )
|
||||||
|
|
||||||
|
def __init__(self, canvas, parent, coordinates=True):
|
||||||
|
NavigationToolbar.__init__(self, canvas, parent,
|
||||||
|
coordinates=coordinates)
|
||||||
|
|
||||||
|
|
||||||
|
class MplWidget(QtWidgets.QGraphicsView):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
QtWidgets.QGraphicsView.__init__(self, parent)
|
||||||
self.canvas = MplCanvas()
|
self.canvas = MplCanvas()
|
||||||
self.ntb = NavigationToolbar(self.canvas, self)
|
self.ntb = CustomNavigationToolbar(self.canvas, self,
|
||||||
|
coordinates=False)
|
||||||
self.vbl = QtWidgets.QVBoxLayout()
|
self.vbl = QtWidgets.QVBoxLayout()
|
||||||
self.vbl.addWidget(self.canvas)
|
|
||||||
self.vbl.addWidget(self.ntb)
|
self.vbl.addWidget(self.ntb)
|
||||||
self.setLayout(self.vbl)
|
self.vbl.addWidget(self.canvas)
|
||||||
|
self.setLayout(self.vbl)
|
||||||
|
|
Loading…
Add table
Reference in a new issue