File: taurusimageitem.py

package info (click to toggle)
taurus-pyqtgraph 0.9.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,284 kB
  • sloc: python: 5,234; makefile: 82
file content (77 lines) | stat: -rw-r--r-- 2,428 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python

#############################################################################
##
# This file is part of Taurus
##
# http://taurus-scada.org
##
# Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain
##
# Taurus is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
##
# Taurus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
##
# You should have received a copy of the GNU Lesser General Public License
# along with Taurus.  If not, see <http://www.gnu.org/licenses/>.
##
#############################################################################
__all__ = ["TaurusImageItem"]

import sys
from taurus.qt.qtgui.application import TaurusApplication
from taurus.qt.qtgui.base import TaurusBaseComponent
from pyqtgraph import ImageItem


class TaurusImageItem(ImageItem, TaurusBaseComponent):
    """
    Displays 2D and 3D image data
    """

    # TODO: clear image if .setModel(None)
    def __init__(self, *args, **kwargs):
        ImageItem.__init__(self, *args, **kwargs)
        TaurusBaseComponent.__init__(self, "TaurusImageItem")

    def handleEvent(self, evt_src, evt_type, evt_val):
        """Reimplemented from :class:`TaurusImageItem`"""
        if evt_val is None or getattr(evt_val, "rvalue", None) is None:
            self.debug("Ignoring empty value event from %s" % repr(evt_src))
            return
        try:
            data = evt_val.rvalue
            self.setImage(data)
        except Exception as e:
            self.warning("Exception in handleEvent: %s", e)


if __name__ == "__main__":
    import pyqtgraph as pg

    app = TaurusApplication()

    plot_widget = pg.PlotWidget()
    plot_item = plot_widget.getPlotItem()

    image_item = TaurusImageItem()

    # Add taurus 2D image data
    image_item.setModel("eval:randint(0,256,(16,16))")

    # add TarusImageItem to a PlotItem
    plot_item.addItem(image_item)

    # show or hide axis from the plot
    plot_item.showAxis("left", show=True)
    plot_item.showAxis("bottom", show=True)

    plot_widget.show()

    sys.exit(app.exec_())