Commit 0747a8ba authored by Matias Guijarro's avatar Matias Guijarro
Browse files

Merge branch 'reduce-image-widget-rendering' into 'master'

[flint] Sync image widget rendering with the user redraw rate

See merge request !2112
parents e3fd944a e5a99929
Pipeline #21952 passed with stages
in 57 minutes and 14 seconds
......@@ -31,7 +31,6 @@ from typing import List
import logging
import numpy
import functools
import gevent.event
......
......@@ -84,6 +84,14 @@ class ScanDataUpdateEvent:
self.__scan = scan
self.__channelNames: Optional[Set[str]] = None
def selectedChannel(self) -> Optional[Channel]:
return self.__channel
def __eq__(self, other):
if not isinstance(other, ScanDataUpdateEvent):
return False
return self.__channel is other.selectedChannel()
def updatedChannelNames(self) -> Set[str]:
if self.__channelNames is None:
channelNames = {c.name() for c in self.iterUpdatedChannels()}
......
......@@ -29,7 +29,6 @@ from bliss.flint.widgets.extended_dock_widget import ExtendedDockWidget
from bliss.flint.widgets.plot_helper import FlintPlot
from bliss.flint.helper import scan_info_helper
from bliss.flint.helper import model_helper
from bliss.flint.utils import signalutils
from bliss.flint.widgets import plot_helper
......@@ -74,7 +73,7 @@ class ImagePlotWidget(ExtendedDockWidget):
self.__plot.getWidgetHandle().installEventFilter(self)
self.__view = plot_helper.ViewManager(self.__plot)
self.__aggregator = signalutils.EventAggregator(self)
self.__aggregator = plot_helper.PlotEventAggregator(self)
self.__refreshManager = plot_helper.RefreshManager(self)
self.__refreshManager.setAggregator(self.__aggregator)
......
......@@ -60,7 +60,7 @@ class McaPlotWidget(ExtendedDockWidget):
self.__plot.getWidgetHandle().installEventFilter(self)
self.__view = plot_helper.ViewManager(self.__plot)
self.__aggregator = signalutils.EventAggregator(self)
self.__aggregator = plot_helper.PlotEventAggregator(self)
self.__refreshManager = plot_helper.RefreshManager(self)
self.__refreshManager.setAggregator(self.__aggregator)
......
......@@ -55,6 +55,34 @@ class MouseMovedEvent(NamedTuple):
yPixel: int
class PlotEventAggregator(signalutils.EventAggregator):
def reduce(self, eventStack: List) -> Tuple[List, List]:
"""Override the method to reduce plot refresh by
removing duplication events.
"""
result = []
# Reduce specific channel events
lastSpecificChannel: Set[object] = set([])
for event in reversed(eventStack):
_callback, args, _kwargs = event
if len(args) == 0:
result.insert(0, event)
continue
e = args[0]
if not isinstance(e, scan_model.ScanDataUpdateEvent):
result.insert(0, event)
continue
channel = e.selectedChannel()
if channel is not None:
if channel in lastSpecificChannel:
continue
else:
lastSpecificChannel.add(channel)
result.insert(0, event)
return result, []
class CheckableKeepAspectRatioAction(PlotAction):
"""QAction controlling X axis log scale on a :class:`.PlotWidget`.
......
"""Testing plot_helper module."""
import typing
from bliss.flint.widgets import plot_helper
from bliss.flint.model import scan_model
class Args(typing.NamedTuple):
args: typing.Tuple
kwargs: typing.Dict
def test_plot_event_aggregator():
aggregator = plot_helper.PlotEventAggregator()
scan = scan_model.Scan()
device = scan_model.Device(scan)
channel = scan_model.Channel(device)
scan.seal()
events = []
def callback(*args, **kwargs):
events.append(Args(args, kwargs))
call = aggregator.callbackTo(callback)
call(scan_model.ScanDataUpdateEvent(scan, channel=channel))
call(scan_model.ScanDataUpdateEvent(scan, channel=channel))
call(scan_model.ScanDataUpdateEvent(scan))
call(scan_model.ScanDataUpdateEvent(scan, channel=channel))
aggregator.flush()
assert len(events) == 2
assert events[0].args[0].selectedChannel() is None
assert events[1].args[0].selectedChannel() is channel
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment