# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2004-2016 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
"""Functions to prepare events to be sent to Plot callback."""
__author__ = ["V.A. Sole", "T. Vincent"]
__license__ = "MIT"
__date__ = "18/02/2016"
import numpy as np
[docs]def prepareDrawingSignal(event, type_, points, parameters=None):
"""See Plot documentation for content of events"""
assert event in ('drawingProgress', 'drawingFinished')
if parameters is None:
parameters = {}
eventDict = {}
eventDict['event'] = event
eventDict['type'] = type_
points = np.array(points, dtype=np.float32)
points.shape = -1, 2
eventDict['points'] = points
eventDict['xdata'] = points[:, 0]
eventDict['ydata'] = points[:, 1]
if type_ in ('rectangle',):
eventDict['x'] = eventDict['xdata'].min()
eventDict['y'] = eventDict['ydata'].min()
eventDict['width'] = eventDict['xdata'].max() - eventDict['x']
eventDict['height'] = eventDict['ydata'].max() - eventDict['y']
eventDict['parameters'] = parameters.copy()
return eventDict
[docs]def prepareMouseSignal(eventType, button, xData, yData, xPixel, yPixel):
"""See Plot documentation for content of events"""
assert eventType in ('mouseMoved', 'mouseClicked', 'mouseDoubleClicked')
assert button in (None, 'left', 'middle', 'right')
return {'event': eventType,
'x': xData,
'y': yData,
'xpixel': xPixel,
'ypixel': yPixel,
'button': button}
[docs]def prepareHoverSignal(label, type_, posData, posPixel, draggable, selectable):
"""See Plot documentation for content of events"""
return {'event': 'hover',
'label': label,
'type': type_,
'x': posData[0],
'y': posData[1],
'xpixel': posPixel[0],
'ypixel': posPixel[1],
'draggable': draggable,
'selectable': selectable}
[docs]def prepareImageSignal(button, label, type_, col, row,
x, y, xPixel, yPixel):
"""See Plot documentation for content of events"""
return {'event': 'imageClicked',
'button': button,
'label': label,
'type': type_,
'col': col,
'row': row,
'x': x,
'y': y,
'xpixel': xPixel,
'ypixel': yPixel}
[docs]def prepareCurveSignal(button, label, type_, xData, yData,
x, y, xPixel, yPixel):
"""See Plot documentation for content of events"""
return {'event': 'curveClicked',
'button': button,
'label': label,
'type': type_,
'xdata': xData,
'ydata': yData,
'x': x,
'y': y,
'xpixel': xPixel,
'ypixel': yPixel}
[docs]def prepareLimitsChangedSignal(sourceObj, xRange, yRange, y2Range):
"""See Plot documentation for content of events"""
return {'event': 'limitsChanged',
'source': id(sourceObj),
'xdata': xRange,
'ydata': yRange,
'y2data': y2Range}