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 from qt_gui.plugin_descriptor import PluginDescriptor
00032 from qt_gui.plugin_provider import PluginProvider
00033
00034 from cpp_binding_helper import qt_gui_cpp
00035
00036
00037 class RosPluginlibPluginProvider(PluginProvider):
00038
00039 def __init__(self, plugin_provider):
00040 super(RosPluginlibPluginProvider, self).__init__()
00041 self._plugin_provider = plugin_provider
00042
00043 def discover(self):
00044 discovered_plugins = self._unfold(self._plugin_provider.discover())
00045 plugin_descriptors = []
00046 for plugin in discovered_plugins.values():
00047 plugin_descriptor = PluginDescriptor(plugin['plugin_id'], plugin['attributes'])
00048
00049 action_attributes = plugin['action']
00050 plugin_descriptor.set_action_attributes(action_attributes['label'], action_attributes.get('statustip', None), action_attributes.get('icon', None), action_attributes.get('icontype', None))
00051
00052 groups = plugin.get('groups', {})
00053 for group in groups.values():
00054 plugin_descriptor.add_group_attributes(group['label'], group['statustip'], group['icon'], group['icontype'])
00055
00056 plugin_descriptors.append(plugin_descriptor)
00057 return plugin_descriptors
00058
00059 def load(self, plugin_id, plugin_context):
00060 if qt_gui_cpp is None:
00061 return None
00062 cpp_plugin_context = None
00063 if plugin_context is not None:
00064 cpp_plugin_context = qt_gui_cpp.PluginContext(plugin_context._handler, plugin_context.serial_number(), plugin_context.argv())
00065 bridge = qt_gui_cpp.PluginBridge()
00066 loaded = bridge.load_plugin(self._plugin_provider, plugin_id, cpp_plugin_context)
00067 if not loaded:
00068 raise ImportError('RosPluginlibPluginProvider.load() could not load plugin "%s"' % plugin_id)
00069 return bridge
00070
00071 def unload(self, bridge):
00072 return bridge.unload_plugin()
00073
00074 def _unfold(self, flat_dict):
00075 dictionary = {}
00076 for key, value in flat_dict.items():
00077 keys = str(key).split('.')
00078 current_level = dictionary
00079 for i in keys[:-1]:
00080 if i not in current_level:
00081 current_level[i] = {}
00082 current_level = current_level[i]
00083 current_level[keys[-1]] = str(value) if value != '' else None
00084 return dictionary