ros_pluginlib_plugin_provider.py
Go to the documentation of this file.
1 # Copyright (c) 2011, Dirk Thomas, TU Darmstadt
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following
12 # disclaimer in the documentation and/or other materials provided
13 # with the distribution.
14 # * Neither the name of the TU Darmstadt nor the names of its
15 # contributors may be used to endorse or promote products derived
16 # from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 
31 from qt_gui.errors import PluginLoadError
32 from qt_gui.plugin_descriptor import PluginDescriptor
33 from qt_gui.plugin_provider import PluginProvider
34 
35 from .cpp_binding_helper import qt_gui_cpp
36 
37 
39 
40  def __init__(self, plugin_provider):
41  super(RosPluginlibPluginProvider, self).__init__()
42  self._plugin_provider = plugin_provider
43 
44  def discover(self, discovery_data):
45  discovered_plugins = self._unfold(self._plugin_provider.discover(discovery_data))
46  plugin_descriptors = []
47  for plugin in discovered_plugins.values():
48  plugin_descriptor = PluginDescriptor(plugin['plugin_id'], plugin['attributes'])
49 
50  action_attributes = plugin['action']
51  plugin_descriptor.set_action_attributes(
52  action_attributes['label'],
53  action_attributes.get('statustip', None),
54  action_attributes.get('icon', None),
55  action_attributes.get('icontype', None))
56 
57  groups = plugin.get('groups', {})
58  for group in groups.values():
59  plugin_descriptor.add_group_attributes(
60  group['label'], group['statustip'], group['icon'], group['icontype'])
61 
62  plugin_descriptors.append(plugin_descriptor)
63  return plugin_descriptors
64 
65  def load(self, plugin_id, plugin_context):
66  if qt_gui_cpp is None:
67  return None
68  cpp_plugin_context = None
69  if plugin_context is not None:
70  cpp_plugin_context = qt_gui_cpp.PluginContext(
71  plugin_context._handler, plugin_context.serial_number(), plugin_context.argv())
72  bridge = qt_gui_cpp.PluginBridge() # @UndefinedVariable
73  loaded = bridge.load_plugin(self._plugin_provider, plugin_id, cpp_plugin_context)
74  if not loaded:
75  raise PluginLoadError(
76  'RosPluginlibPluginProvider.load() could not load plugin "%s"' % plugin_id)
77  return bridge
78 
79  def unload(self, bridge):
80  return bridge.unload_plugin()
81 
82  def _unfold(self, flat_dict):
83  dictionary = {}
84  for key, value in flat_dict.items():
85  keys = str(key).split('.')
86  current_level = dictionary
87  for i in keys[:-1]:
88  if i not in current_level:
89  current_level[i] = {}
90  current_level = current_level[i]
91  current_level[keys[-1]] = str(value) if value != '' else None
92  return dictionary
93 
94  def shutdown(self):
95  self._plugin_provider.shutdown()


qt_gui_cpp
Author(s): Dirk Thomas
autogenerated on Thu Jun 6 2019 19:54:30