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 import rospy
00019 import time
00020 import os
00021 import rosnode
00022 import roslaunch
00023 import subprocess
00024 from roslaunch import main as ros_launch
00025
00026 from roslib.packages import get_pkg_dir
00027
00028 from python_qt_binding.QtGui import *
00029 from python_qt_binding.QtCore import *
00030
00031 def widget_creator(obj_ui):
00032
00033 widget = QWidget()
00034
00035 layout = QHBoxLayout(widget)
00036 layout.setSpacing(6)
00037 layout.setContentsMargins(0, 0, 0, 0)
00038 spacer_left = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
00039 spacer_right = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
00040
00041 layout.addItem(spacer_left)
00042 layout.addWidget(obj_ui)
00043 layout.addItem(spacer_right)
00044
00045 return widget
00046
00047 class NodeItem:
00048
00049 NONE = 'None'
00050 RUNNING = 'Running'
00051 ABARTED = 'Aborted'
00052 SHUTDOWN = 'Shutdown'
00053
00054 NODE_EXCEPTION = ['/rosout']
00055
00056 def __init__(self, node_uri, node_name):
00057
00058 rsc = os.path.join(get_pkg_dir('airbus_plugin_node_manager'),'resources')
00059
00060 self._icon_node_start = QIcon(rsc+'/start.png')
00061 self._icon_node_stop = QIcon(rsc+'/stop.png')
00062
00063 self.uri = QLabel(node_uri)
00064 self.uri.setContentsMargins(0,0,10,0)
00065 self.uri.setMinimumHeight(40)
00066
00067 self.name = QLabel(node_name)
00068 self.name.setContentsMargins(0,0,10,0)
00069 self.name.setMinimumHeight(40)
00070
00071 self.status = QLabel(self.RUNNING)
00072 self.status.setStyleSheet('qproperty-alignment: AlignCenter;')
00073 self.status.setMinimumSize(QSize(100,40))
00074
00075 self.ping = QLabel('...')
00076 self.ping.setStyleSheet("qproperty-alignment: AlignCenter;")
00077
00078 self.button_start_stop = QPushButton()
00079 self.button_start_stop.setIcon(self._icon_node_stop)
00080 self.button_start_stop.setIconSize(QSize(30,30))
00081 self.button_start_stop.setFixedSize(QSize(100,40))
00082
00083 self.button_start_stop_widget = widget_creator(self.button_start_stop)
00084
00085 if node_name not in self.NODE_EXCEPTION:
00086 self.button_start_stop.clicked.connect(self.start_stop_slot)
00087 self.button_start_stop.setEnabled(False)
00088
00089 self.current_status = self.NONE
00090
00091 def start_stop_slot(self):
00092
00093 self.button_start_stop.setEnabled(False)
00094
00095 if self.current_status == self.RUNNING:
00096 self.stop_node()
00097 else:
00098 self.start_node()
00099
00100 def start_node(self):
00101 rospy.loginfo('%s::started()'%self.name.text())
00102
00103 launch_file = self.name.text().replace('/','')
00104 launch_file += '.launch'
00105 subprocess.Popen(['roslaunch',
00106 'node_launchers',
00107 launch_file])
00108
00109 def stop_node(self):
00110 rospy.loginfo('%s::stoped()'%self.name.text())
00111 rosnode._rosnode_cmd_kill(['fake','fake',self.name.text()])
00112
00113 def refresh(self, status, ping=None):
00114
00115 if ping is not None:
00116 self.ping.setText(str("%.3f"%ping))
00117 else:
00118 self.ping.setText('...')
00119
00120 if status != self.current_status:
00121 self.current_status = status
00122 self.button_start_stop.setEnabled(True)
00123 self.status.setText(self.current_status)
00124 if self.current_status == self.RUNNING:
00125 self.status.setStyleSheet("background:rgb(0,255,0);")
00126 self.button_start_stop.setIcon(self._icon_node_stop)
00127 elif self.current_status == self.ABARTED:
00128 self.status.setStyleSheet("background:rgb(255,0,0);")
00129 self.button_start_stop.setIcon(self._icon_node_start)
00130 elif self.current_status == self.SHUTDOWN:
00131 self.status.setStyleSheet("background:rgb(255,255,0);")
00132 self.button_start_stop.setIcon(self._icon_node_start)
00133 else:
00134 self.status.setStyleSheet("background:rgb(255,255,255);")
00135 self.status.setText('Unknown')
00136
00137