From 1502d0df07db6356af0ffd57401d773ee73eaeab Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 23 Jul 2015 12:29:40 -0400 Subject: [PATCH] PRF: throttle qt5 mouse motion events Only accept mouse motion events every 1 / 30 of a second. --- lib/matplotlib/backends/backend_qt5.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index baf76593cc57..ce788cc320e0 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -10,6 +10,8 @@ import matplotlib +import time as ttime + from matplotlib.cbook import is_string_like from matplotlib.backend_bases import FigureManagerBase from matplotlib.backend_bases import FigureCanvasBase @@ -242,6 +244,7 @@ def __init__(self, figure): self._idle = True w, h = self.get_width_height() self.resize(w, h) + self._last_mouse_move_time = 0 def enterEvent(self, event): FigureCanvasBase.enter_notify_event(self, guiEvent=event) @@ -274,6 +277,11 @@ def mouseDoubleClickEvent(self, event): print('button doubleclicked:', event.button()) def mouseMoveEvent(self, event): + cur_time = ttime.time() + if cur_time - self._last_mouse_move_time < 1 / 30: + return + self._last_mouse_move_time = cur_time + x = event.x() # flipy so y=0 is bottom of canvas y = self.figure.bbox.height - event.y()