node_widget.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2013, Willow Garage, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Willow Garage, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 #
33 # Author: Isaac Saito
34 
35 import os
36 
37 from python_qt_binding import loadUi
38 from python_qt_binding.QtGui import QIcon
39 from python_qt_binding.QtWidgets import QLineEdit, QWidget
40 import rospy
41 
42 from rqt_launch.name_surrogate import NamesSurrogate
43 
44 
45 class NodeWidget(QWidget):
46 
47  '''
48  Works as a proxy between ROS Node
49  (more in particular, roslaunch.nodeprocess) and GUI.
50  '''
51 
52  __slots__ = ['_run_id', 'master_uri', 'config', '_process']
53 
54  def __init__(self, rospack, master_uri, launch_config,
55  label_status):
56  '''
57  @type launch_node: roslaunch.core.Node
58  @type launch_config: roslaunch.core.Config
59  @type label_status: StatusIndicator
60  '''
61  super(NodeWidget, self).__init__()
62  self._rospack = rospack
63  self._master_uri = master_uri
64  self._launch_config = launch_config
65 
66  ui_file = os.path.join(self._rospack.get_path('rqt_launch'),
67  'resource', 'node_widget.ui')
68  loadUi(ui_file, self)
69 
70  self.label_status = label_status # Public
71  # stop_button = QPushButton(self.style().standardIcon(
72  # QStyle.SP_MediaStop), "")
73  self._respawn_toggle.setChecked(self._launch_config.respawn)
74  self._lineEdit_launch_args = QLineEdit(self._launch_config.launch_prefix)
75 
76  rospy.logdebug('_proxy.conf.namespace={} launch_config={}'.format(
77  self._launch_config.namespace, self._launch_config.name))
78  self._resolved_node_name = NamesSurrogate.ns_join(
79  self._launch_config.namespace, self._launch_config.name)
80  self._label_nodename.setText(self._get_node_name())
81  self._label_pkg_name.setText(self._launch_config.package)
82  self._label_name_executable.setText(self._launch_config.type)
83 
84  self._icon_node_start = QIcon.fromTheme('media-playback-start')
85  self._icon_node_stop = QIcon.fromTheme('media-playback-stop')
86  self._icon_respawn_toggle = QIcon.fromTheme('view-refresh')
87 
88  self._pushbutton_start_stop_node.setIcon(self._icon_node_start)
89  self._respawn_toggle.setIcon(self._icon_respawn_toggle)
90 
91  self._node_controller = None # Connected in self.set_node_controller
92 
93  def _get_node_name(self):
94  return self._resolved_node_name
95 
96  def connect_start_stop_button(self, slot):
97  self._pushbutton_start_stop_node.toggled.connect(slot)
98 
99  def set_node_started(self, is_started=True):
100  # If the button is not down yet
101  is_node_running = self._node_controller.is_node_running()
102  rospy.logdebug('NodeWidget.set_node_started running?={}'.format(is_node_running))
103  # if is_node_running:
104  if is_started:
105  # and self._pushbutton_start_stop_node.isDown():
106  self._pushbutton_start_stop_node.setIcon(self._icon_node_start)
107  self._pushbutton_start_stop_node.setDown(False)
108 
109  # elif not is_node_running: # To START the node
110  else:
111  # and not self._pushbutton_start_stop_node.isDown():
112  self._pushbutton_start_stop_node.setIcon(self._icon_node_stop)
113  self._pushbutton_start_stop_node.setDown(True)
114 
115  def set_node_controller(self, node_controller):
116  # TODO: Null check
117  self._node_controller = node_controller
118  # self._pushbutton_start_stop_node.pressed.connect(
119  # self._node_controller.start_stop_slot)
def __init__(self, rospack, master_uri, launch_config, label_status)
Definition: node_widget.py:55
def connect_start_stop_button(self, slot)
Definition: node_widget.py:96
def set_node_controller(self, node_controller)
Definition: node_widget.py:115
def set_node_started(self, is_started=True)
Definition: node_widget.py:99


rqt_launch
Author(s): Isaac Saito, Stuart Glaser
autogenerated on Wed Jun 5 2019 21:35:22