34 import builtins
as __builtin__
38 from xml.etree
import ElementTree
40 from python_qt_binding.QtCore
import qCritical
47 """Base class for providing plugins based on the ROS package system."""
49 def __init__(self, export_tag, base_class_type):
50 super(RosPluginProvider, self).
__init__()
51 self.setObjectName(
'RosPluginProvider')
61 The information of the `PluginDescriptor`s are extracted from the plugin manifests.
64 plugin_descriptors = []
66 for package_name, plugin_xml
in plugin_file_list:
69 for plugin_descriptor
in plugin_descriptors:
71 return plugin_descriptors
73 def load(self, plugin_id, plugin_context):
76 sys.path.append(os.path.join(attributes[
'plugin_path'], attributes[
'library_path']))
79 module = __builtin__.__import__(
80 attributes[
'module_name'], fromlist=[attributes[
'class_from_class_type']], level=0)
81 except NotImplementedError
as e:
82 qCritical(
'RosPluginProvider.load(%s): raised an exception:\n%s' % (plugin_id, e))
84 except Exception
as e:
85 qCritical(
'RosPluginProvider.load(%s) exception raised in '
86 '__builtin__.__import__(%s, [%s]):\n%s' % (
87 plugin_id, attributes[
'module_name'],
88 attributes[
'class_from_class_type'],
89 traceback.format_exc()))
92 class_ref = getattr(module, attributes[
'class_from_class_type'],
None)
94 qCritical(
'RosPluginProvider.load(%s): could not find class "%s" in module "%s"' %
95 (plugin_id, attributes[
'class_from_class_type'], module))
100 code = class_ref.__init__.func_code
101 except AttributeError:
102 code = class_ref.__init__.__code__
103 if code.co_argcount == 1
and plugin_context
is None:
106 return class_ref(plugin_context)
112 raise NotImplementedError
115 plugin_descriptors = []
117 if not os.path.isfile(plugin_xml):
118 qCritical(
'RosPluginProvider._parse_plugin_xml() plugin file "%s" in package "%s" '
119 'not found' % (plugin_xml, package_name))
120 return plugin_descriptors
123 root = ElementTree.parse(plugin_xml)
125 qCritical(
'RosPluginProvider._parse_plugin_xml() could not parse "%s" in package "%s"'
126 % (plugin_xml, package_name))
127 return plugin_descriptors
128 for library_el
in root.iter(
'library'):
129 library_path = library_el.attrib[
'path']
131 for class_el
in library_el.iter(
'class'):
134 'package_name': package_name,
135 'plugin_path': os.path.dirname(plugin_xml),
136 'library_path': library_path,
140 for key, value
in class_el.items():
141 attributes[
'class_' + key] = value
144 class_base_class_type = attributes.get(
'class_base_class_type',
None)
149 plugin_id = package_name
150 if 'class_name' in attributes:
151 plugin_id = plugin_id +
'/' + attributes[
'class_name']
152 attributes[
'plugin_id'] = plugin_id
155 module_name, class_from_class_type = attributes[
'class_type'].rsplit(
'.', 1)
156 attributes[
'module_name'] = module_name
157 attributes[
'class_from_class_type'] = class_from_class_type
160 attributes[
'not_available'] =
''
166 if len(action_attributes) > 0:
167 plugin_descriptor.set_action_attributes(
168 action_attributes[
'label'],
169 action_attributes.get(
'statustip',
None),
170 action_attributes.get(
'icon',
None),
171 action_attributes.get(
'icontype',
None),
175 plugin_descriptor.add_group_attributes(
177 group.get(
'statustip',
None),
178 group.get(
'icon',
None),
179 group.get(
'icontype',
None),
183 plugin_descriptors.append(plugin_descriptor)
185 return plugin_descriptors
189 plugin_attributes = {}
193 guiplugin_el = class_el.find(
'qtgui')
194 if guiplugin_el
is not None:
196 for group_el
in guiplugin_el.iter(
'group'):
199 return plugin_attributes, groups
203 for tag
in [
'label',
'icon',
'statustip']:
204 text = group_el.findtext(tag)
206 attributes[tag] = str(text)
208 icon_el = group_el.find(
'icon')
209 if icon_el
is not None:
210 icon_type_attrib = icon_el.get(
'type')
211 if icon_type_attrib
is not None:
212 attributes[
'icontype'] = str(icon_type_attrib)