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 import os
00032 import threading
00033 import time
00034
00035 import rospy
00036
00037 from qt_gui.composite_plugin_provider import CompositePluginProvider
00038 from qt_gui.errors import PluginLoadError
00039
00040 from python_qt_binding.QtCore import qDebug, Qt, qWarning, Signal
00041 from python_qt_binding.QtGui import QMessageBox
00042
00043 from rqt_gui.rospkg_plugin_provider import RospkgPluginProvider
00044
00045
00046 class RosPyPluginProvider(CompositePluginProvider):
00047
00048 _master_found_signal = Signal(int)
00049
00050 def __init__(self):
00051 super(RosPyPluginProvider, self).__init__([RospkgPluginProvider('rqt_gui', 'rqt_gui_py::Plugin')])
00052 self.setObjectName('RosPyPluginProvider')
00053 self._node_initialized = False
00054 self._wait_for_master_dialog = None
00055 self._wait_for_master_thread = None
00056
00057 def load(self, plugin_id, plugin_context):
00058 self._check_for_master()
00059 self._init_node()
00060 return super(RosPyPluginProvider, self).load(plugin_id, plugin_context)
00061
00062 def _check_for_master(self):
00063
00064 try:
00065 rospy.get_master().getSystemState()
00066 return
00067 except Exception:
00068 pass
00069
00070 self._wait_for_master_thread = threading.Thread(target=self._wait_for_master)
00071 self._wait_for_master_thread.start()
00072 self._wait_for_master_dialog = QMessageBox(QMessageBox.Question, self.tr('Waiting for ROS master'), self.tr("Could not find ROS master. Either start a 'roscore' or abort loading the plugin."), QMessageBox.Abort)
00073 self._master_found_signal.connect(self._wait_for_master_dialog.done, Qt.QueuedConnection)
00074 button = self._wait_for_master_dialog.exec_()
00075
00076 no_master = button != QMessageBox.Ok
00077 self._wait_for_master_dialog.deleteLater()
00078 self._wait_for_master_dialog = None
00079 if no_master:
00080 raise PluginLoadError('RosPyPluginProvider._init_node() could not find ROS master')
00081
00082 def _wait_for_master(self):
00083 while True:
00084 time.sleep(0.1)
00085 if not self._wait_for_master_dialog:
00086 break
00087 try:
00088 rospy.get_master().getSystemState()
00089 except Exception:
00090 continue
00091 self._master_found_signal.emit(QMessageBox.Ok)
00092 break
00093
00094 def _init_node(self):
00095
00096 if not self._node_initialized:
00097 name = 'rqt_gui_py_node_%d' % os.getpid()
00098 qDebug('RosPyPluginProvider._init_node() initialize ROS node "%s"' % name)
00099 rospy.init_node(name, disable_signals=True)
00100 self._node_initialized = True