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, QLineEdit, QWidget
00039 import rospy
00040 
00041 from rqt_launch.name_surrogate import NamesSurrogate
00042 
00043 
00044 class NodeWidget(QWidget):
00045     '''
00046     Works as a proxy between ROS Node
00047     (more in particular, roslaunch.nodeprocess) and GUI.
00048     '''
00049 
00050     __slots__ = ['_run_id', 'master_uri', 'config', '_process']
00051 
00052     def __init__(self, rospack, master_uri, launch_config,
00053                  label_status):
00054         '''
00055         @type launch_node: roslaunch.core.Node
00056         @type launch_config: roslaunch.core.Config
00057         @type label_status: StatusIndicator
00058         '''
00059         super(NodeWidget, self).__init__()
00060         self._rospack = rospack
00061         self._master_uri = master_uri
00062         self._launch_config = launch_config
00063 
00064         ui_file = os.path.join(self._rospack.get_path('rqt_launch'),
00065                                'resource', 'node_widget.ui')
00066         loadUi(ui_file, self)
00067 
00068         self.label_status = label_status  # Public
00069         # stop_button = QPushButton(self.style().standardIcon(
00070         #                                             QStyle.SP_MediaStop), "")
00071         self._respawn_toggle.setChecked(self._launch_config.respawn)
00072         self._lineEdit_launch_args = QLineEdit(
00073                                             self._launch_config.launch_prefix)
00074 
00075         rospy.logdebug('_proxy.conf.namespace={} launch_config={}'.format(
00076                       self._launch_config.namespace, self._launch_config.name))
00077         self._resolved_node_name = NamesSurrogate.ns_join(
00078                        self._launch_config.namespace, self._launch_config.name)
00079         self._label_nodename.setText(self._get_node_name())
00080         self._label_pkg_name.setText(self._launch_config.package)
00081         self._label_name_executable.setText(self._launch_config.type)
00082 
00083         self._icon_node_start = QIcon.fromTheme('media-playback-start')
00084         self._icon_node_stop = QIcon.fromTheme('media-playback-stop')
00085         self._icon_respawn_toggle = QIcon.fromTheme('view-refresh')
00086 
00087         self._pushbutton_start_stop_node.setIcon(self._icon_node_start)
00088         self._respawn_toggle.setIcon(self._icon_respawn_toggle)
00089 
00090         self._node_controller = None  # Connected in self.set_node_controller
00091 
00092     def _get_node_name(self):
00093         return self._resolved_node_name
00094 
00095     def connect_start_stop_button(self, slot):
00096         self._pushbutton_start_stop_node.toggled.connect(slot)
00097 
00098     def set_node_started(self, is_started=True):
00099         # If the button is not down yet
00100         is_node_running = self._node_controller.is_node_running()
00101         rospy.logdebug('NodeWidget.set_node_started running?={}'.format(
00102                                                             is_node_running))
00103         #if is_node_running:
00104         if is_started:
00105             #and self._pushbutton_start_stop_node.isDown():
00106             self._pushbutton_start_stop_node.setIcon(self._icon_node_start)
00107             self._pushbutton_start_stop_node.setDown(False)
00108 
00109         #elif not is_node_running:  # To START the node
00110         else:
00111             #and not self._pushbutton_start_stop_node.isDown():
00112             self._pushbutton_start_stop_node.setIcon(self._icon_node_stop)
00113             self._pushbutton_start_stop_node.setDown(True)
00114 
00115     def set_node_controller(self, node_controller):
00116         #TODO: Null check
00117         self._node_controller = node_controller
00118         #self._pushbutton_start_stop_node.pressed.connect(
00119         #                                self._node_controller.start_stop_slot)


rqt_launch
Author(s): Isaac Saito , Stuart Glaser
autogenerated on Mon Oct 6 2014 07:15:40