led_widget.py
Go to the documentation of this file.
00001 import rospy
00002 from functools import partial
00003 
00004 from kobuki_msgs.msg import Led
00005 
00006 from rqt_robot_dashboard.widgets import MenuDashWidget
00007 from python_qt_binding.QtCore import QSize
00008 
00009 class LedWidget(MenuDashWidget):
00010     def __init__(self, topic):
00011         self._pub = rospy.Publisher(topic, Led, queue_size=5)
00012 
00013         self._off_icon = ['bg-grey.svg', 'ic-led.svg']
00014         self._green_icon = ['bg-green.svg', 'ic-led.svg']
00015         self._orange_icon = ['bg-orange.svg', 'ic-led.svg']
00016         self._red_icon = ['bg-red.svg', 'ic-led.svg']
00017 
00018         icons = [self._off_icon, self._green_icon, self._orange_icon, self._red_icon]
00019         super(LedWidget, self).__init__(topic, icons=icons)
00020         self.setFixedSize(QSize(40,40))
00021 
00022         self.add_action('Off', partial(self.update_state, 0))
00023         self.add_action('Green', partial(self.update_state, 1))
00024         self.add_action('Orange', partial(self.update_state, 2))
00025         self.add_action('Red', partial(self.update_state, 3))
00026         
00027         self.setToolTip("LED: Off")
00028 
00029     def update_state(self, state):
00030         super(LedWidget, self).update_state(state)
00031         self._pub.publish(Led(state))
00032         if state is 1:
00033             self.setToolTip("LED: Green")
00034         elif state is 2:
00035             self.setToolTip("LED: Orange")
00036         elif state is 3:
00037             self.setToolTip("LED: Red")
00038         else:
00039             self.setToolTip("LED: Off")
00040 
00041     def close(self):
00042         self._pub.unregister()
00043     


kobuki_dashboard
Author(s): Ze'ev Klapow, Marcus Liebhardt
autogenerated on Thu Jun 6 2019 19:42:44