ros_py_plugin_provider.py
Go to the documentation of this file.
00001 # Copyright (c) 2011, Dirk Thomas, TU Darmstadt
00002 # All rights reserved.
00003 #
00004 # Redistribution and use in source and binary forms, with or without
00005 # modification, are permitted provided that the following conditions
00006 # are met:
00007 #
00008 #   * Redistributions of source code must retain the above copyright
00009 #     notice, this list of conditions and the following disclaimer.
00010 #   * Redistributions in binary form must reproduce the above
00011 #     copyright notice, this list of conditions and the following
00012 #     disclaimer in the documentation and/or other materials provided
00013 #     with the distribution.
00014 #   * Neither the name of the TU Darmstadt nor the names of its
00015 #     contributors may be used to endorse or promote products derived
00016 #     from this software without specific prior written permission.
00017 #
00018 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00021 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00022 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00023 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00024 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00026 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00027 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00028 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029 # POSSIBILITY OF SUCH DAMAGE.
00030 
00031 import os
00032 import roslib
00033 roslib.load_manifest('rqt_gui_py')
00034 import rospy
00035 
00036 from qt_gui.composite_plugin_provider import CompositePluginProvider
00037 
00038 from python_qt_binding.QtCore import qDebug, qWarning
00039 
00040 try:
00041     from rqt_gui.rospkg_plugin_provider import RospkgPluginProvider
00042     ActualRosPluginProvider = RospkgPluginProvider
00043 except ImportError:
00044     from rqt_gui.roslib_plugin_provider import RoslibPluginProvider
00045     ActualRosPluginProvider = RoslibPluginProvider
00046 
00047 
00048 class RosPyPluginProvider(CompositePluginProvider):
00049 
00050     def __init__(self):
00051         super(RosPyPluginProvider, self).__init__([ActualRosPluginProvider('rqt_gui', 'rqt_gui_py::Plugin')])
00052         self.setObjectName('RosPyPluginProvider')
00053         self._node_initialized = False
00054 
00055     def discover(self):
00056         descriptors = super(RosPyPluginProvider, self).discover()
00057 
00058         if not self._master_found():
00059             qWarning('RosPyPluginProvider.discover() could not find ROS master, all rospy-based plugins are disabled')
00060             # mark all plugins as "not_available"
00061             for descriptor in descriptors:
00062                 descriptor.attributes()['not_available'] = 'no ROS master found (roscore needs to be started before the GUI)'
00063 
00064         return descriptors
00065 
00066     def load(self, plugin_id, plugin_context):
00067         self._init_node()
00068         return super(RosPyPluginProvider, self).load(plugin_id, plugin_context)
00069 
00070     def _master_found(self):
00071         try:
00072             rospy.get_master().getSystemState()
00073             return True
00074         except Exception:
00075             return False
00076 
00077     def _init_node(self):
00078         # initialize node once
00079         if not self._node_initialized:
00080             name = 'rqt_gui_py_node_%d' % os.getpid()
00081             qDebug('RosPyPluginProvider._init_node() initialize ROS node "%s"' % name)
00082             rospy.init_node(name, disable_signals=True)
00083             self._node_initialized = True


rqt_gui_py
Author(s): Dirk Thomas
autogenerated on Fri Jan 3 2014 11:53:54