context.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2015 Airbus
00004 # Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00005 #
00006 # Licensed under the Apache License, Version 2.0 (the "License");
00007 # you may not use this file except in compliance with the License.
00008 # You may obtain a copy of the License at
00009 #
00010 #   http://www.apache.org/licenses/LICENSE-2.0
00011 #
00012 # Unless required by applicable law or agreed to in writing, software
00013 # distributed under the License is distributed on an "AS IS" BASIS,
00014 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 # See the License for the specific language governing permissions and
00016 # limitations under the License.
00017 
00018 
00019 import rospy
00020 import os
00021 
00022 from python_qt_binding.QtGui import *
00023 from python_qt_binding.QtCore import *
00024 
00025 from alarm import Alarm
00026 from account import User
00027 
00028 from airbus_cobot_gui.res import R
00029 
00030 class UiLogger:
00031     
00032     INFO     = QMessageBox.Information
00033     WARN     = QMessageBox.Warning
00034     CRITICAL = QMessageBox.Critical
00035     QUESTION = QMessageBox.Question
00036     
00037     @staticmethod
00038     def log(level, message):
00039         massage_box = QMessageBox()
00040         massage_box.setWindowFlags(Qt.FramelessWindowHint)
00041         massage_box.setIcon(level)
00042         massage_box.setText(message)
00043         return massage_box.exec_()
00044         
00045     @staticmethod
00046     def info(message):
00047         return UiLogger.log(UiLogger.INFO, message)
00048     
00049     @staticmethod
00050     def warn(message):
00051         return UiLogger.log(UiLogger.WARN, message)
00052         
00053     @staticmethod
00054     def err(message):
00055         return UiLogger.log(UiLogger.CRITICAL, message)
00056     
00057     @staticmethod
00058     def critical(message):
00059         return UiLogger.log(UiLogger.CRITICAL, message)
00060         
00061     @staticmethod
00062     def question(message):
00063         return UiLogger.log(UiLogger.QUESTION, message)
00064 
00065 class Context(QObject):
00066     
00067     DEFAULT_LNG = 'en'
00068     
00069     AUTOMATIC = 1
00070     MANUAL    = 2
00071     
00072     viewManagerRequest = SIGNAL('viewManagerRequested')
00073     
00074     newUserConnectionRequest = SIGNAL('newUserConnectionRequested')
00075     newControlModeRequest    = SIGNAL('newControlModeRequested')
00076     newLanguageRequest       = SIGNAL('newLanguageRequested')
00077     
00078     defaultTrigger       = SIGNAL('defaultTriggered')
00079     alarmTrigger         = SIGNAL('alarmTriggered')
00080     emergencyStopRequest = SIGNAL('emergencyStopRequested')
00081     shutingdownRequest   = SIGNAL('shutingdownRequested')
00082     
00083     def __init__(self, parent):
00084         QObject.__init__(self, parent)
00085         
00086         self._parent       = parent
00087         self._user         = User()
00088         self._control_mode = self.AUTOMATIC
00089         self._lng          = self.DEFAULT_LNG
00090         
00091         self._default = 0
00092         self._emer    = False
00093         self._what    = ''
00094         
00095     def getParent(self):
00096         return self._parent
00097         
00098     def addViewManagerEventListner(self, listener):
00099         self.connect(self, self.viewManagerRequest, listener)
00100         
00101     def addUserEventListener(self, listener):
00102         self.connect(self, self.newUserConnectionRequest, listener)
00103         
00104     addUserConnectionEventListener = addUserEventListener
00105         
00106     def addControlModeEventListener(self, listener):
00107         self.connect(self, self.newControlModeRequest, listener)
00108         
00109     def addLanguageEventListner(self, listener):
00110         self.connect(self, self.newLanguageRequest, listener)
00111         
00112     def addDefaultEventListner(self, listener):
00113         self.connect(self, self.defaultTrigger, listener)
00114         
00115     def addAlarmEventListner(self, listener):
00116         self.connect(self, self.alarmTrigger, listener)
00117         
00118     def addEmergencyStopEventListner(self, listener):
00119         self.connect(self, self.emergencyStopRequest, listener)
00120         
00121     def addCloseEventListner(self, listener):
00122         self.connect(self, self.shutingdownRequest, listener)
00123         
00124     addShutingdownEventListner = addCloseEventListner
00125         
00126     def getR(self):
00127         return R
00128     
00129     def getLogger(self):
00130         return UiLogger
00131     
00132     def requestNewUserConnection(self, user):
00133         self._user = user
00134         self.emit(self.newUserConnectionRequest, user)
00135         
00136     switchUser = requestNewUserConnection
00137     
00138     def getUser(self):
00139         return self._user
00140     
00141     getUserInfo = getUser
00142     
00143     def requestDisplayView(self, view):
00144         self.emit(self.viewManagerRequest, view)
00145         
00146     def requestNewControlMode(self, ctrl):
00147         self._control_mode = ctrl
00148         self.emit(self.newControlModeRequest, ctrl)
00149         
00150     switchControlMode = requestNewControlMode
00151         
00152     def getControlMode(self):
00153         return self._control_mode
00154         
00155     def requestNewLanguage(self, lng):
00156         self._lng = lng
00157         self.emit(self.newLanguageRequest, lng)
00158         
00159     switchLanguage = requestNewLanguage
00160         
00161     def getLanguage(self):
00162         return self._lng
00163     
00164     def requestDefault(self, errcode, what=''):
00165         self._default = errcode
00166         self._what = what
00167         self.emit(self.defaultTrigger, self._default)
00168         
00169     def getDefault(self):
00170         return self._default
00171     
00172     def requestAlarm(self, level, what="???"):
00173         self.emit(self.alarmTrigger, Alarm(self, level, what))
00174         
00175     sendAlarm = requestAlarm
00176         
00177     def getAlarm(self):
00178         return self._alarm
00179 
00180     def resquestEmergencyStop(self, state, what=''):
00181         self._emer = state
00182         self._what = what
00183         self.emit(self.emergencyStopRequest, state)
00184     
00185     def inEmergencyStop(self):
00186         return self._emer
00187     
00188     def what(self):
00189         return self._what
00190     
00191     def requestShutdown(self):
00192         self.emit(self.shutingdownRequest)
00193     


airbus_cobot_gui
Author(s): Martin Matignon
autogenerated on Thu Jun 6 2019 17:59:19