plugin_installer.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 ################################################################################
3 #
4 # Copyright Airbus Group SAS 2015
5 # All rigths reserved.
6 #
7 # File Name : plugin_installer.py
8 # Authors : Martin Matignon
9 #
10 # If you find any bug or if you have any question please contact
11 # Adolfo Suarez Roos <adolfo.suarez@airbus.com>
12 # Martin Matignon <martin.matignon.external@airbus.com>
13 #
14 #
15 ################################################################################
16 
17 import rospy
18 import uuid
19 import os
20 from roslib.packages import get_pkg_dir
21 from python_qt_binding import QtGui
22 from python_qt_binding import QtCore
23 
24 from airbus_cobot_gui.account import Privilege, User
25 from airbus_cobot_gui.translator import trUtf8
26 
27 from airbus_cobot_gui.exception import CobotGuiException
28 
29 ## @package: plugin
30 ##
31 ## @version 4.0
32 ## @author Matignon Martin
33 ## @date Last modified 28/02/2014
34 
35 ## @class PluginInstaller
36 ## @brief Base class for install plugin components.
38 
39  def __init__(self, user_changed_event_cb):
40  """! The constructor."""
41  self._label = str(self.__class__.__name__)
42  self._description = 'Not informed !'
43  self._restriction = Privilege.OPERATOR
44  self._user = User(userid='Unknown', privilege=Privilege.NONE)
45  self._widget = None
46  self._user_changed_cb = user_changed_event_cb
47 
48  #Launcher button instance
49  self._launcher = QtGui.QPushButton()
50  self._launcher.setFocusPolicy(QtCore.Qt.NoFocus)
51  self._launcher.setObjectName(str(uuid.uuid1()))
52 
53  self._parameters = None
54 
55  def install(self, plugin_descriptors = {}):
56  """! Install Plugin with plugin description.
57  @param plugin_descriptors: plugin descriptors.
58  @type plugin_descriptors: dict(strings).
59  """
60 
61  self._label = plugin_descriptors['label']
62  self._description = plugin_descriptors['description']
63  self._restriction = Privilege.TOLEVEL[plugin_descriptors['restriction']]
64 
65  if plugin_descriptors['style-sheet'] is not None:
66  self._widget.setStyleSheet(plugin_descriptors['style-sheet'])
67 
68  self._setup_launcher(plugin_descriptors['icon'])
69 
70  def _setup_launcher(self, icon_path):
71  """! Setup launcher button.
72  @param icon_path: icon path.
73  @type icon_path: String.
74  """
75  self._launcher.setSizePolicy(QtGui.QSizePolicy.Expanding,
76  QtGui.QSizePolicy.Preferred)
77 
78  if os.access(icon_path, os.W_OK):
79  self._launcher.setIcon(QtGui.QIcon(icon_path))
80  else:
81  self._launcher.setStyleSheet("background-color: rgba(255,0,0,80%);\
82  border-radius: 10px;\
83  font-size: 12pt;\
84  font-weight:60;\
85  color: #ffffff;")
86  self._launcher.setText(self._label)
87 
88  self._launcher.setEnabled(False)
89 
90  def _get_launcher(self):
91  """! Get launcher button.
92  @return launcher: plugin launcher button.
93  @type launcher: QPushButton.
94  """
95  return self._launcher
96 
97  def _update_user(self, user):
98  """! Methode called when user account changed.
99  @param user: user informations.
100  @type user: User.
101  """
102 
103  self._user = user
104 
105  if self._user.privilege < self._restriction:
106  self._launcher.setEnabled(False)
107  else:
108  self._launcher.setEnabled(True)
109 
110  try:
111  self._user_changed_cb(self._user)
112  except Exception as e:
113  rospy.logerr('%s::user_changed_event(%s) raised with exception "%s"'
114  %(self._label, str(self._user), str(e)))
115 
116  def set_widget(self, widget):
117  self._widget = widget
118  self._widget.setObjectName(self._launcher.objectName())
119 
120  def get_widget(self):
121  return self._widget
122 
123  def get_access_right(self):
124  return self._restriction
125 
126  def get_plugin_name(self):
127  return self._label
128 
129  def set_params(self, params):
130  self._parameters = params
131 
132  def get_param(self, name, default):
133 
134  param = default
135 
136  if self._parameters is not None:
137  if name in self._parameters.keys():
138  param = self._parameters[name]
139  else:
140  rospy.logerr('Plugin::%s parameter "%s" not found !'
141  %(self._label, name))
142 
143  return param
144 
145 #End of file
146 
def install
Install Plugin with plugin description.
Base class for install plugin components.
def _update_user
Methode called when user account changed.


airbus_cobot_gui
Author(s):
autogenerated on Thu Dec 17 2015 11:42:05