control_mode.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 : control_mode.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 ## @package: control_mode
18 ##
19 ## @version 1.0
20 ## @author Matignon Martin
21 ## @date Last modified 24/09/2014
22 
23 import rospy
24 import os
25 import sys
26 from roslib.packages import get_pkg_dir
27 
28 from python_qt_binding.QtGui import *
29 from python_qt_binding.QtCore import *
30 from python_qt_binding import loadUi
31 
32 from airbus_cobot_gui import resources_dir, trUtf8
33 from airbus_cobot_gui.python_qt_extend import MessageBox, QSilderButton
34 
35 ## @class ControlMode
36 ## @brief Class for difine different control mode.
38 
39  AUTOMATIC = 1
40  MANUAL = 2
41 
42  TOSTR = {AUTOMATIC : 'Automatic',
43  MANUAL : 'Manual'}
44 
45  TOLEVEL = {'Automatic' : AUTOMATIC,
46  'Manual' : MANUAL}
47 
48 class ControlModeWidget(QWidget):
49 
50  def __init__(self):
51  """! The constructor."""
52  QWidget.__init__(self)
53 
54  self.setFixedSize(QSize(140,40))
55 
56  self._slider_button = QSilderButton(self,
57  status=True,
58  on_label='MANU',
59  off_label='AUTO')
60  self._slider_button.setFixedSize(QSize(140,40))
61  self.connect(self._slider_button,
62  SIGNAL("statusChanged"),
63  self._switch_mode)
64 
65  def set_default_mode(self, mode):
66 
67  if mode is ControlMode.AUTOMATIC:
68  self._slider_button.set_status(False)
69  else:
70  self._slider_button.set_status(True)
71 
72  self.emit(SIGNAL('controlModeChanged'), mode)
73 
74  def _switch_mode(self, status):
75 
76  if status == False:
77  self.emit(SIGNAL('controlModeChanged'), ControlMode.AUTOMATIC)
78  else:
79  msg_box = MessageBox()
80  msg_box.setText(trUtf8("Switching AUTOMATIC to MANUAL mode",'!'))
81  msg_box.setIcon(QMessageBox.Warning)
82  msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
83  msg_box.button(QMessageBox.Yes).setMinimumSize(100,40)
84  msg_box.button(QMessageBox.No).setMinimumSize(100,40)
85 
86  response = msg_box.exec_()
87 
88  if response == QMessageBox.Yes:
89  self.emit(SIGNAL('controlModeChanged'), ControlMode.MANUAL)
90  else:
91  self._slider_button.set_status(False)
92 
93  def retranslate(self):
94  pass
95 
96 if __name__ == "__main__":
97 
98  rospy.init_node('unittest_countrol_mode_ui')
99 
100  a = QApplication(sys.argv)
101 
102  utt_appli = QMainWindow()
103 
104  utt_appli.setCentralWidget(ControlModeWidget())
105 
106  utt_appli.show()
107  a.exec_()
108 
109 #End of file
Class for difine different control mode.
Definition: control_mode.py:37


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