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 from PIL import Image
00034 from PIL.ImageQt import ImageQt
00035
00036 from rqt_bag import TopicMessageView
00037 import image_helper
00038
00039 from python_qt_binding.QtGui import QGraphicsScene, QGraphicsView, QPixmap
00040
00041
00042 class ImageView(TopicMessageView):
00043 """
00044 Popup image viewer
00045 """
00046 name = 'Image'
00047
00048 def __init__(self, timeline, parent, topic):
00049 super(ImageView, self).__init__(timeline, parent, topic)
00050
00051 self._image = None
00052 self._image_topic = None
00053 self._image_stamp = None
00054 self.quality = Image.NEAREST
00055
00056
00057 self._overlay_font_size = 14.0
00058 self._overlay_indent = (4, 4)
00059 self._overlay_color = (0.2, 0.2, 1.0)
00060
00061 self._image_view = QGraphicsView(parent)
00062 self._image_view.resizeEvent = self._resizeEvent
00063 self._scene = QGraphicsScene()
00064 self._image_view.setScene(self._scene)
00065 parent.layout().addWidget(self._image_view)
00066
00067
00068 def _resizeEvent(self, event):
00069
00070 self._scene.setSceneRect(0, 0, self._image_view.size().width() - 2, self._image_view.size().height() - 2)
00071 self.put_image_into_scene()
00072
00073 def message_viewed(self, bag, msg_details):
00074 """
00075 refreshes the image
00076 """
00077 TopicMessageView.message_viewed(self, bag, msg_details)
00078 topic, msg, t = msg_details[:3]
00079 if not msg:
00080 self.set_image(None, topic, 'no message')
00081 else:
00082 self.set_image(msg, topic, msg.header.stamp)
00083
00084 def message_cleared(self):
00085 TopicMessageView.message_cleared(self)
00086 self.set_image(None, None, None)
00087
00088
00089 def put_image_into_scene(self):
00090 if self._image:
00091 resized_image = self._image.resize((self._image_view.size().width() - 2, self._image_view.size().height() - 2), self.quality)
00092
00093 QtImage = ImageQt(resized_image)
00094 pixmap = QPixmap.fromImage(QtImage)
00095 self._scene.clear()
00096 self._scene.addPixmap(pixmap)
00097
00098 def set_image(self, image_msg, image_topic, image_stamp):
00099 self._image_msg = image_msg
00100 if image_msg:
00101 self._image = image_helper.imgmsg_to_pil(image_msg)
00102 else:
00103 self._image = None
00104 self._image_topic = image_topic
00105 self._image_stamp = image_stamp
00106 self.put_image_into_scene()