node_selection.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2016, Ryohei Ueda
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 import rosgraph
34 import rosnode
35 from python_qt_binding.QtCore import Qt
36 from python_qt_binding.QtWidgets import QWidget, QVBoxLayout, QCheckBox, QScrollArea, QPushButton
37 
38 
39 class NodeSelection(QWidget):
40 
41  def __init__(self, parent):
42  super(NodeSelection, self).__init__()
43  self.parent_widget = parent
44  self.selected_nodes = []
45  self.setWindowTitle("Select the nodes you want to record")
46  self.resize(500, 700)
47  self.area = QScrollArea(self)
48  self.main_widget = QWidget(self.area)
49  self.ok_button = QPushButton("Done", self)
50  self.ok_button.clicked.connect(self.onButtonClicked)
51  self.ok_button.setEnabled(False)
52  self.main_vlayout = QVBoxLayout(self)
53  self.main_vlayout.addWidget(self.area)
54  self.main_vlayout.addWidget(self.ok_button)
55  self.setLayout(self.main_vlayout)
56 
57  self.selection_vlayout = QVBoxLayout(self)
58 
59  self.node_list = rosnode.get_node_names()
60  self.node_list.sort()
61  for node in self.node_list:
62  self.addCheckBox(node)
63  self.main_widget.setLayout(self.selection_vlayout)
64  self.show()
65 
66  def addCheckBox(self, node):
67  item = QCheckBox(node, self)
68  item.stateChanged.connect(lambda x: self.updateNode(x, node))
69  self.selection_vlayout.addWidget(item)
70 
71  def updateNode(self, state, node):
72  if state == Qt.Checked:
73  self.selected_nodes.append(node)
74  else:
75  self.selected_nodes.remove(node)
76  if len(self.selected_nodes) > 0:
77  self.ok_button.setEnabled(True)
78  else:
79  self.ok_button.setEnabled(False)
80 
81  def onButtonClicked(self):
82  master = rosgraph.Master('rqt_bag_recorder')
83  state = master.getSystemState()
84  subs = [t for t, l in state[1]
85  if len([node_name for node_name in self.selected_nodes if node_name in l]) > 0]
86  for topic in subs:
87  self.parent_widget.changeTopicCheckState(topic, Qt.Checked)
88  self.parent_widget.updateList(Qt.Checked, topic)
89  self.close()
def updateNode(self, state, node)


rqt_bag
Author(s): Dirk Thomas , Aaron Blasdel , Austin Hendrix , Tim Field
autogenerated on Fri Feb 19 2021 03:14:14