node_widget.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2013, Willow Garage, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Willow Garage, Inc. nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
00032 #
00033 # Author: Isaac Saito
00034 
00035 import os
00036 
00037 from python_qt_binding import loadUi
00038 from python_qt_binding.QtGui import QIcon
00039 from python_qt_binding.QtWidgets import QLineEdit, QWidget
00040 import rospy
00041 
00042 from rqt_launch.name_surrogate import NamesSurrogate
00043 
00044 
00045 class NodeWidget(QWidget):
00046     '''
00047     Works as a proxy between ROS Node
00048     (more in particular, roslaunch.nodeprocess) and GUI.
00049     '''
00050 
00051     __slots__ = ['_run_id', 'master_uri', 'config', '_process']
00052 
00053     def __init__(self, rospack, master_uri, launch_config,
00054                  label_status):
00055         '''
00056         @type launch_node: roslaunch.core.Node
00057         @type launch_config: roslaunch.core.Config
00058         @type label_status: StatusIndicator
00059         '''
00060         super(NodeWidget, self).__init__()
00061         self._rospack = rospack
00062         self._master_uri = master_uri
00063         self._launch_config = launch_config
00064 
00065         ui_file = os.path.join(self._rospack.get_path('rqt_launch'),
00066                                'resource', 'node_widget.ui')
00067         loadUi(ui_file, self)
00068 
00069         self.label_status = label_status  # Public
00070         # stop_button = QPushButton(self.style().standardIcon(
00071         #                                             QStyle.SP_MediaStop), "")
00072         self._respawn_toggle.setChecked(self._launch_config.respawn)
00073         self._lineEdit_launch_args = QLineEdit(
00074                                             self._launch_config.launch_prefix)
00075 
00076         rospy.logdebug('_proxy.conf.namespace={} launch_config={}'.format(
00077                       self._launch_config.namespace, self._launch_config.name))
00078         self._resolved_node_name = NamesSurrogate.ns_join(
00079                        self._launch_config.namespace, self._launch_config.name)
00080         self._label_nodename.setText(self._get_node_name())
00081         self._label_pkg_name.setText(self._launch_config.package)
00082         self._label_name_executable.setText(self._launch_config.type)
00083 
00084         self._icon_node_start = QIcon.fromTheme('media-playback-start')
00085         self._icon_node_stop = QIcon.fromTheme('media-playback-stop')
00086         self._icon_respawn_toggle = QIcon.fromTheme('view-refresh')
00087 
00088         self._pushbutton_start_stop_node.setIcon(self._icon_node_start)
00089         self._respawn_toggle.setIcon(self._icon_respawn_toggle)
00090 
00091         self._node_controller = None  # Connected in self.set_node_controller
00092 
00093     def _get_node_name(self):
00094         return self._resolved_node_name
00095 
00096     def connect_start_stop_button(self, slot):
00097         self._pushbutton_start_stop_node.toggled.connect(slot)
00098 
00099     def set_node_started(self, is_started=True):
00100         # If the button is not down yet
00101         is_node_running = self._node_controller.is_node_running()
00102         rospy.logdebug('NodeWidget.set_node_started running?={}'.format(
00103                                                             is_node_running))
00104         #if is_node_running:
00105         if is_started:
00106             #and self._pushbutton_start_stop_node.isDown():
00107             self._pushbutton_start_stop_node.setIcon(self._icon_node_start)
00108             self._pushbutton_start_stop_node.setDown(False)
00109 
00110         #elif not is_node_running:  # To START the node
00111         else:
00112             #and not self._pushbutton_start_stop_node.isDown():
00113             self._pushbutton_start_stop_node.setIcon(self._icon_node_stop)
00114             self._pushbutton_start_stop_node.setDown(True)
00115 
00116     def set_node_controller(self, node_controller):
00117         #TODO: Null check
00118         self._node_controller = node_controller
00119         #self._pushbutton_start_stop_node.pressed.connect(
00120         #                                self._node_controller.start_stop_slot)


rqt_launch
Author(s): Isaac Saito, Stuart Glaser
autogenerated on Tue May 2 2017 02:42:28