summaryrefslogtreecommitdiff
path: root/silx/gui/plot/tools/toolbars.py
blob: 28fb7f9a03f133fbdb4c556f21072b1fbffc93f8 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2018 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.
#
# ###########################################################################*/
"""This module provides toolbars that work with :class:`PlotWidget`.
"""

__authors__ = ["T. Vincent"]
__license__ = "MIT"
__date__ = "01/03/2018"


from ... import qt
from .. import actions
from ..PlotWidget import PlotWidget
from .. import PlotToolButtons


class InteractiveModeToolBar(qt.QToolBar):
    """Toolbar with interactive mode actions

    :param parent: See :class:`QWidget`
    :param silx.gui.plot.PlotWidget plot: PlotWidget to control
    :param str title: Title of the toolbar.
    """

    def __init__(self, parent=None, plot=None, title='Plot Interaction'):
        super(InteractiveModeToolBar, self).__init__(title, parent)

        assert isinstance(plot, PlotWidget)

        self._zoomModeAction = actions.mode.ZoomModeAction(
            parent=self, plot=plot)
        self.addAction(self._zoomModeAction)

        self._panModeAction = actions.mode.PanModeAction(
            parent=self, plot=plot)
        self.addAction(self._panModeAction)

    def getZoomModeAction(self):
        """Returns the zoom mode QAction.

        :rtype: PlotAction
        """
        return self._zoomModeAction

    def getPanModeAction(self):
        """Returns the pan mode QAction

        :rtype: PlotAction
        """
        return self._panModeAction


class OutputToolBar(qt.QToolBar):
    """Toolbar providing icons to copy, save and print a PlotWidget

    :param parent: See :class:`QWidget`
    :param silx.gui.plot.PlotWidget plot: PlotWidget to control
    :param str title: Title of the toolbar.
    """

    def __init__(self, parent=None, plot=None, title='Plot Output'):
        super(OutputToolBar, self).__init__(title, parent)

        assert isinstance(plot, PlotWidget)

        self._copyAction = actions.io.CopyAction(parent=self, plot=plot)
        self.addAction(self._copyAction)

        self._saveAction = actions.io.SaveAction(parent=self, plot=plot)
        self.addAction(self._saveAction)

        self._printAction = actions.io.PrintAction(parent=self, plot=plot)
        self.addAction(self._printAction)

    def getCopyAction(self):
        """Returns the QAction performing copy to clipboard of the PlotWidget

        :rtype: PlotAction
        """
        return self._copyAction

    def getSaveAction(self):
        """Returns the QAction performing save to file of the PlotWidget

        :rtype: PlotAction
        """
        return self._saveAction

    def getPrintAction(self):
        """Returns the QAction performing printing of the PlotWidget

        :rtype: PlotAction
        """
        return self._printAction


class ImageToolBar(qt.QToolBar):
    """Toolbar providing PlotAction suited when displaying images

    :param parent: See :class:`QWidget`
    :param silx.gui.plot.PlotWidget plot: PlotWidget to control
    :param str title: Title of the toolbar.
    """

    def __init__(self, parent=None, plot=None, title='Image'):
        super(ImageToolBar, self).__init__(title, parent)

        assert isinstance(plot, PlotWidget)

        self._resetZoomAction = actions.control.ResetZoomAction(
            parent=self, plot=plot)
        self.addAction(self._resetZoomAction)

        self._colormapAction = actions.control.ColormapAction(
            parent=self, plot=plot)
        self.addAction(self._colormapAction)

        self._keepDataAspectRatioButton = PlotToolButtons.AspectToolButton(
            parent=self, plot=plot)
        self.addWidget(self._keepDataAspectRatioButton)

        self._yAxisInvertedButton = PlotToolButtons.YAxisOriginToolButton(
            parent=self, plot=plot)
        self.addWidget(self._yAxisInvertedButton)

    def getResetZoomAction(self):
        """Returns the QAction to reset the zoom.

        :rtype: PlotAction
        """
        return self._resetZoomAction

    def getColormapAction(self):
        """Returns the QAction to control the colormap.

        :rtype: PlotAction
        """
        return self._colormapAction

    def getKeepDataAspectRatioButton(self):
        """Returns the QToolButton controlling data aspect ratio.

        :rtype: QToolButton
        """
        return self._keepDataAspectRatioButton

    def getYAxisInvertedButton(self):
        """Returns the QToolButton controlling Y axis orientation.

        :rtype: QToolButton
        """
        return self._yAxisInvertedButton


class CurveToolBar(qt.QToolBar):
    """Toolbar providing PlotAction suited when displaying curves

    :param parent: See :class:`QWidget`
    :param silx.gui.plot.PlotWidget plot: PlotWidget to control
    :param str title: Title of the toolbar.
    """

    def __init__(self, parent=None, plot=None, title='Image'):
        super(CurveToolBar, self).__init__(title, parent)

        assert isinstance(plot, PlotWidget)

        self._resetZoomAction = actions.control.ResetZoomAction(
            parent=self, plot=plot)
        self.addAction(self._resetZoomAction)

        self._xAxisAutoScaleAction = actions.control.XAxisAutoScaleAction(
            parent=self, plot=plot)
        self.addAction(self._xAxisAutoScaleAction)

        self._yAxisAutoScaleAction = actions.control.YAxisAutoScaleAction(
            parent=self, plot=plot)
        self.addAction(self._yAxisAutoScaleAction)

        self._xAxisLogarithmicAction = actions.control.XAxisLogarithmicAction(
            parent=self, plot=plot)
        self.addAction(self._xAxisLogarithmicAction)

        self._yAxisLogarithmicAction = actions.control.YAxisLogarithmicAction(
            parent=self, plot=plot)
        self.addAction(self._yAxisLogarithmicAction)

        self._gridAction = actions.control.GridAction(
            parent=self, plot=plot)
        self.addAction(self._gridAction)

        self._curveStyleAction = actions.control.CurveStyleAction(
            parent=self, plot=plot)
        self.addAction(self._curveStyleAction)

    def getResetZoomAction(self):
        """Returns the QAction to reset the zoom.

        :rtype: PlotAction
        """
        return self._resetZoomAction

    def getXAxisAutoScaleAction(self):
        """Returns the QAction to toggle X axis autoscale.

        :rtype: PlotAction
        """
        return self._xAxisAutoScaleAction

    def getYAxisAutoScaleAction(self):
        """Returns the QAction to toggle Y axis autoscale.

        :rtype: PlotAction
        """
        return self._yAxisAutoScaleAction

    def getXAxisLogarithmicAction(self):
        """Returns the QAction to toggle X axis log/linear scale.

        :rtype: PlotAction
        """
        return self._xAxisLogarithmicAction

    def getYAxisLogarithmicAction(self):
        """Returns the QAction to toggle Y axis log/linear scale.

        :rtype: PlotAction
        """
        return self._yAxisLogarithmicAction

    def getGridAction(self):
        """Returns the action to toggle the plot grid.

        :rtype: PlotAction
        """
        return self._gridAction

    def getCurveStyleAction(self):
        """Returns the QAction to change the style of all curves.

        :rtype: PlotAction
        """
        return self._curveStyleAction


class ScatterToolBar(qt.QToolBar):
    """Toolbar providing PlotAction suited when displaying scatter plot

    :param parent: See :class:`QWidget`
    :param silx.gui.plot.PlotWidget plot: PlotWidget to control
    :param str title: Title of the toolbar.
    """

    def __init__(self, parent=None, plot=None, title='Scatter Tools'):
        super(ScatterToolBar, self).__init__(title, parent)

        assert isinstance(plot, PlotWidget)

        self._resetZoomAction = actions.control.ResetZoomAction(
            parent=self, plot=plot)
        self.addAction(self._resetZoomAction)

        self._xAxisLogarithmicAction = actions.control.XAxisLogarithmicAction(
            parent=self, plot=plot)
        self.addAction(self._xAxisLogarithmicAction)

        self._yAxisLogarithmicAction = actions.control.YAxisLogarithmicAction(
            parent=self, plot=plot)
        self.addAction(self._yAxisLogarithmicAction)

        self._keepDataAspectRatioButton = PlotToolButtons.AspectToolButton(
            parent=self, plot=plot)
        self.addWidget(self._keepDataAspectRatioButton)

        self._gridAction = actions.control.GridAction(
            parent=self, plot=plot)
        self.addAction(self._gridAction)

        self._colormapAction = actions.control.ColormapAction(
            parent=self, plot=plot)
        self.addAction(self._colormapAction)

        self._symbolToolButton = PlotToolButtons.SymbolToolButton(
            parent=self, plot=plot)
        self.addWidget(self._symbolToolButton)

    def getResetZoomAction(self):
        """Returns the QAction to reset the zoom.

        :rtype: PlotAction
        """
        return self._resetZoomAction

    def getXAxisLogarithmicAction(self):
        """Returns the QAction to toggle X axis log/linear scale.

        :rtype: PlotAction
        """
        return self._xAxisLogarithmicAction

    def getYAxisLogarithmicAction(self):
        """Returns the QAction to toggle Y axis log/linear scale.

        :rtype: PlotAction
        """
        return self._yAxisLogarithmicAction

    def getGridAction(self):
        """Returns the action to toggle the plot grid.

        :rtype: PlotAction
        """
        return self._gridAction

    def getColormapAction(self):
        """Returns the QAction to control the colormap.

        :rtype: PlotAction
        """
        return self._colormapAction

    def getSymbolToolButton(self):
        """Returns the QToolButton controlling symbol size and marker.

        :rtype: SymbolToolButton
        """
        return self._symbolToolButton

    def getKeepDataAspectRatioButton(self):
        """Returns the QToolButton controlling data aspect ratio.

        :rtype: QToolButton
        """
        return self._keepDataAspectRatioButton