Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 PKG = 'rqt_bag_plugins'
00034 import roslib; roslib.load_manifest(PKG)
00035
00036 import Image
00037 import ImageQt
00038
00039 from rqt_bag import TopicMessageView
00040 import image_helper
00041
00042 from python_qt_binding.QtGui import QGraphicsScene, QGraphicsView, QPixmap
00043
00044
00045 class ImageView(TopicMessageView):
00046 """
00047 Popup image viewer
00048 """
00049 name = 'Image'
00050
00051 def __init__(self, timeline, parent):
00052 super(ImageView, self).__init__(timeline, parent)
00053
00054 self._image = None
00055 self._image_topic = None
00056 self._image_stamp = None
00057 self.quality = Image.NEAREST
00058
00059
00060 self._overlay_font_size = 14.0
00061 self._overlay_indent = (4, 4)
00062 self._overlay_color = (0.2, 0.2, 1.0)
00063
00064 self._image_view = QGraphicsView(parent)
00065 self._image_view.resizeEvent = self._resizeEvent
00066 self._scene = QGraphicsScene()
00067 self._image_view.setScene(self._scene)
00068 parent.layout().addWidget(self._image_view)
00069
00070
00071 def _resizeEvent(self, event):
00072
00073 self._scene.setSceneRect(0, 0, self._image_view.size().width() - 2, self._image_view.size().height() - 2)
00074 self.put_image_into_scene()
00075
00076 def message_viewed(self, bag, msg_details):
00077 """
00078 refreshes the image
00079 """
00080 TopicMessageView.message_viewed(self, bag, msg_details)
00081 topic, msg, t = msg_details[:3]
00082 if not msg:
00083 self.set_image(None, topic, 'no message')
00084 else:
00085 self.set_image(msg, topic, msg.header.stamp)
00086
00087 def message_cleared(self):
00088 TopicMessageView.message_cleared(self)
00089 self.set_image(None, None, None)
00090
00091
00092 def put_image_into_scene(self):
00093 if self._image:
00094 resized_image = self._image.resize((self._image_view.size().width() - 2, self._image_view.size().height() - 2), self.quality)
00095
00096 QtImage = ImageQt.ImageQt(resized_image)
00097 pixmap = QPixmap.fromImage(QtImage)
00098 self._scene.clear()
00099 self._scene.addPixmap(pixmap)
00100
00101 def set_image(self, image_msg, image_topic, image_stamp):
00102 self._image_msg = image_msg
00103 if image_msg:
00104 self._image = image_helper.imgmsg_to_pil(image_msg)
00105 else:
00106 self._image = None
00107 self._image_topic = image_topic
00108 self._image_stamp = image_stamp
00109 self.put_image_into_scene()