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 import rospy
00020 import uuid
00021 import os
00022 from roslib.packages import get_pkg_dir
00023 from python_qt_binding.QtGui import *
00024 from python_qt_binding.QtCore import *
00025
00026 from airbus_cobot_gui.account import Privilege, User
00027 from airbus_cobot_gui.util import CobotGuiException, Parameters
00028
00029
00030 from airbus_pyqt_extend.QtAgiCore import get_pkg_dir_from_prefix
00031 from airbus_pyqt_extend.QtAgiGui import QAgiPopup
00032
00033 from airbus_cobot_gui.res import R
00034
00035
00036 class DashboardPopup(QAgiPopup):
00037
00038 def __init__(self,
00039 parent,
00040 popup_winpos=QAgiPopup.TopRight,
00041 parent_winpos=QAgiPopup.BottomRight):
00042
00043 QAgiPopup.__init__(self, parent)
00044
00045 self.setRelativePosition(popup_winpos,
00046 parent_winpos)
00047
00048 self._parent = parent
00049
00050 def getParent(self):
00051 return self._parent
00052
00053 def onCreate(self, param):
00054 pass
00055
00056 def onTranslate(self, lng):
00057 pass
00058
00059 def onDestroy(self):
00060 pass
00061
00062 def closeEvent(self, event):
00063 self.onDestroy()
00064
00065
00066
00067 class WrapperDashboard(QWidget):
00068
00069 def __init__(self, context):
00070 QWidget.__init__(self)
00071
00072 self._context = context
00073 self._name = self.__class__.__name__
00074
00075 self._param = Parameters()
00076 self._popup_enabled = True
00077 self._access_rights = Privilege.OPERATOR
00078
00079 self.setMinimumSize(QSize(35,35))
00080 self.setMaximumSize(QSize(600,35))
00081
00082 self._layout = QHBoxLayout(self)
00083 self._layout.setContentsMargins(0, 0, 0, 0)
00084 self._layout.setSpacing(5)
00085
00086 context.addUserEventListener(self.onUserChanged)
00087 context.addLanguageEventListner(self.onTranslate)
00088 context.addControlModeEventListener(self.onControlModeChanged)
00089 context.addEmergencyStopEventListner(self.onEmergencyStop)
00090 context.addCloseEventListner(self.onDestroy)
00091
00092 def setup(self, dashboard_descriptor, param):
00093
00094 xsetup = dashboard_descriptor.find('setup')
00095
00096 if xsetup is not None:
00097
00098 icon = xsetup.find('icon')
00099
00100 if icon is not None:
00101 icon_path = get_pkg_dir_from_prefix(icon.text)
00102 if os.path.isfile(icon_path):
00103 ico_label = QLabel(self)
00104 ico_label.setPixmap(QPixmap(icon_path).scaled(60,60))
00105
00106 access_rights = xsetup.find('access-rights')
00107
00108 if access_rights is not None:
00109 self._access_rights = Privilege.TOLEVEL[access_rights.text]
00110
00111 else:
00112 self.logErr("Cannot found '<setup>' into %s/dashboard_descriptor.xml"%self.getName())
00113
00114 self._param = param
00115 self.onCreate(param)
00116
00117 def getContext(self):
00118 return self._context
00119
00120 def getLayout(self):
00121 return self._layout
00122
00123 def getName(self):
00124 return self._name
00125
00126 def getAccessRights(self):
00127 return self._access_rights
00128
00129 def setPopupEnabled(self, state):
00130 self._popup_enabled = state
00131
00132 def logInfo(self,):
00133 self._context.getLogger().info(msg)
00134
00135 def logWarn(self, msg):
00136 self._context.getLogger().warn(msg)
00137
00138 def logErr(self, msg):
00139 self._context.getLogger().err(msg)
00140
00141 def onCreate(self, param):
00142 raise NotImplementedError("Need to surchage onCreate(self, param)")
00143
00144 def onControlModeChanged(self, mode):
00145 raise NotImplementedError("Need to surchage onControlModeChanged(self, mode)")
00146
00147 def onUserChanged(self, user_info):
00148 raise NotImplementedError("Need to surchage onUserChanged(self, user_info)")
00149
00150 def onTranslate(self, lng):
00151 raise NotImplementedError("Need to surchage onTranslate(self, lng)")
00152
00153 def onEmergencyStop(self, state):
00154 raise NotImplementedError("Need to surchage onEmergencyStop(self, state)")
00155
00156 def onDestroy(self):
00157 raise NotImplementedError("Need to surchage onDestroy(self)")
00158
00159 def onRequestPopup(self):
00160 return None
00161
00162 def mousePressEvent(self, event):
00163 if self._popup_enabled is True:
00164 popup = self.onRequestPopup()
00165 if popup is not None:
00166 popup.onCreate(self._param)
00167 popup.onTranslate(self.getContext().getLanguage())
00168 popup.adjustSize()
00169 popup.show_()
00170
00171 def closeEvent(self, event):
00172 self.onDestroy()
00173
00174
00175