yes_no_button.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 import os
00004 import rospy
00005 import rospkg
00006 
00007 from qt_gui.plugin import Plugin
00008 from python_qt_binding import loadUi
00009 from python_qt_binding.QtGui import QWidget
00010 
00011 from jsk_rqt_plugins.srv import YesNo, YesNoResponse
00012 
00013 
00014 class YesNoButtonWidget(QWidget):
00015     def __init__(self):
00016         super(YesNoButtonWidget, self).__init__()
00017         rospy.Service('rqt_yn_btn', YesNo, self._handle_yn_btn)
00018         rp = rospkg.RosPack()
00019         ui_file = os.path.join(rp.get_path('jsk_rqt_plugins'),
00020             'resource', 'yes_no_button.ui')
00021         loadUi(ui_file, self)
00022         self.setObjectName('YesNoButtonUi')
00023         self.yes_button.clicked[bool].connect(self._clicked_yes_button)
00024         self.no_button.clicked[bool].connect(self._clicked_no_button)
00025         self.yes_button.setEnabled(False)
00026         self.no_button.setEnabled(False)
00027         self.yes = None
00028 
00029     def _clicked_yes_button(self):
00030         """Handle events of being clicked yes button."""
00031         self.yes = True
00032 
00033     def _clicked_no_button(self):
00034         """Handle events of being clicked no button."""
00035         self.yes = False
00036 
00037     def _handle_yn_btn(self, req):
00038         """Callback function of service,
00039         and handle enable/disable of the buttons."""
00040         self.yes = None  # initialize
00041         self.yes_button.setEnabled(True)
00042         self.no_button.setEnabled(True)
00043         while self.yes is None:  # wait for user input
00044             rospy.sleep(1.)
00045         self.yes_button.setEnabled(False)
00046         self.no_button.setEnabled(False)
00047         return YesNoResponse(yes=self.yes)
00048 
00049 
00050 class YesNoButton(Plugin):
00051     def __init__(self, context):
00052         super(YesNoButton, self).__init__(context)
00053         self.setObjectName('YesNoButton')
00054         self._widget = YesNoButtonWidget()
00055         context.add_widget(self._widget)


jsk_rqt_plugins
Author(s):
autogenerated on Sun Sep 13 2015 22:29:48