24 from xml.etree
import ElementTree
25 from roslib.packages
import get_pkg_dir
27 from airbus_cobot_gui
import airbus_cobot_gui_dir
30 from airbus_pyqt_extend.QtAgiCore
import get_pkg_dir_from_prefix
41 PluginProvider interacts with ros plugin package. The first is its
42 import plugin, and the second is the set plugin configuration which
47 """! The constructor."""
52 if not os.path.isfile(xml_register_dir):
53 raise CobotGuiException(
'Plugins register file "%s" in package "airbus_cobot_gui" not found'
59 except Exception
as e:
63 """! Find plugin package name and xml name registered in plugins_register.xml.
64 @param plugin_label: plugin label.
65 @type package_name: string.
67 @return plugin_desc: package name and xml file name.
68 @type plugin_desc: tuple (string, string).
73 root = self._plugin_register.getroot()
76 plugin_desc = root.find(
'./plugin[@label="%s"]'%plugin_label)
78 if plugin_desc
is None:
81 return plugin_desc.attrib[
'package'], plugin_desc.attrib[
'plugin-xml']
83 def load(self, node, plugin_label):
84 """! Load Python package.
85 @param package_name: package name.
86 @type package_name: string.
88 @param plugin_xml: xml file name.
89 @type plugin_xml: string.
91 @return plugin_instance: plugin instance.
92 @type plugin_instance: CobotUiPlugin.
99 sys.path.append(package[
'package_path'])
104 module = __builtin__.__import__(package[
'module_name'],
105 fromlist=[package[
'class_name']],
107 except NotImplementedError
as e:
108 rospy.logerr(
'PluginProvider::load(%s,%s): raised an exception:\n%s'
109 %(package_name, plugin_xml, e))
111 except Exception
as e:
112 raise CobotGuiException(
'PluginProvider::load exception raised in import_module(%s, %s):\n%s'
113 %(package[
'module_name'], package[
'class_name'],traceback.format_exc()))
116 plugin_ref = getattr(module, package[
'class_name'],
None)
118 if plugin_ref
is None:
119 rospy.logerr(
'PluginProvider::load could not find plugin %s.%s !'
120 %(package[
'module_name'], package[
'class_name'], module))
124 if param.tag ==
"param":
126 parameters[param.attrib[
"name"]] = param.attrib[
"value"]
128 parameters.update({param.attrib[
"name"] : param.attrib[
"value"]})
131 plugin_instance = plugin_ref()
132 plugin_instance.set_params(parameters)
133 plugin_instance.setup()
134 plugin_instance.install(config)
135 plugin_instance.exit()
136 except Exception
as e:
137 raise CobotGuiException(
'PluginProvider.plugin_instance raised with exception %s'%e)
139 return plugin_instance
142 """! Read plugin xml file.
143 @param package_name: python pakage name.
144 @type package_name: string.
146 @param plugin_xml: plugin xml name.
147 @type plugin_xml: string.
149 @return: plugin_desc: package descrition, plugin configuration.
150 @type plugin_desc: tuple (dictonary, dictonary).
153 package = {
'package_path' :
None,
154 'module_name' :
None,
157 config = {
'label' : self.
_label,
'description' :
None,
158 'icon' :
None,
'style-sheet' :
None,
'restriction':
None}
160 pkg_dir = get_pkg_dir(package_name)
162 path =
'/'.join([pkg_dir, plugin_xml])
164 if not os.path.isfile(path):
165 rospy.logerr(
'PluginProvider._parse_plugin_xml() plugin file "%s" in package "%s" not found'
166 %(plugin_xml, package_name))
170 tree = ElementTree.parse(path)
174 path = [pkg_dir,tree.getroot().attrib[
'path']]
176 package[
'package_path'] =
'/'.join(path)
178 plugin_import = tree.getroot().find(
'./class').attrib[
'import']
180 config[
'description'] = tree.getroot().find(
'./description').text
183 module_name, class_name = plugin_import.rsplit(
'.', 1)
184 package[
'module_name'] = module_name
185 package[
'class_name'] = class_name
187 config_node = tree.getroot().find(
'./init')
189 for child
in config_node:
190 if child.tag ==
'icon':
191 config[
'icon'] = get_pkg_dir_from_prefix(child.text, pkg_dir)
192 elif child.tag ==
'style-sheet':
193 if child.text !=
None and child.text !=
'none':
194 config[
'style-sheet'] = child.text
195 elif child.tag ==
'access-rights':
196 config[
'restriction'] = child.text
200 parameters_node = tree.getroot().find(
'./parameters')
203 param_type={
"string": str,
207 if parameters_node
is not None:
209 for param
in parameters_node:
210 name = param.attrib[
'name']
211 type = param_type[param.attrib[
'type']]
212 value = param.attrib[
'value']
213 parameters.update({name : type(value)})
215 return package, config, parameters
224 QPopup.__init__(self, parent)
226 self.setAttribute(Qt.WA_TranslucentBackground)
227 self.setStyleSheet(
"background:transparent;")
228 self.
setLinks(QPopup.TopRight, QPopup.TopLeft)
231 self._launchers_layout.setContentsMargins(20, 2, 2, 2)
232 self._launchers_layout.setSpacing(15)
233 self._launchers_layout.setSizeConstraint(QLayout.SetMaximumSize)
237 for launcher
in launchers:
238 self.connect(launcher, SIGNAL(
'clicked()'), self.close)
239 self._launchers_layout.addWidget(launcher)
244 QPushButton.__init__(self, parent)
245 self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
249 icon_path = get_pkg_dir_from_prefix(icon)
251 if os.access(icon_path, os.W_OK):
252 self.setIcon(QIcon(icon_path))
254 self.setStyleSheet(
"background-color:rgba(255,0,0,80%);\
255 border-radius: 10px;\
259 self.setText(group_name)
264 launcher.setFixedSize(size)
265 launcher.setIconSize(size)
268 launcher.setStyleSheet(
"background:none;")
269 self._launchers.append(launcher)
def __init__
The constructor.
def get_plugin_registered
Find plugin package name and xml name registered in plugins_register.xml.
Class for load Python plugin package.
def _parse_plugin_xml
Read plugin xml file.
Object for create an exception.
def load
Load Python package.