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
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 import rosgraph
00034 import rosnode
00035 from python_qt_binding.QtCore import Qt
00036 from python_qt_binding.QtWidgets import QWidget, QVBoxLayout, QCheckBox, QScrollArea, QPushButton
00037
00038
00039 class NodeSelection(QWidget):
00040
00041 def __init__(self, parent):
00042 super(NodeSelection, self).__init__()
00043 self.parent_widget = parent
00044 self.selected_nodes = []
00045 self.setWindowTitle("Select the nodes you want to record")
00046 self.resize(500, 700)
00047 self.area = QScrollArea(self)
00048 self.main_widget = QWidget(self.area)
00049 self.ok_button = QPushButton("Done", self)
00050 self.ok_button.clicked.connect(self.onButtonClicked)
00051 self.ok_button.setEnabled(False)
00052 self.main_vlayout = QVBoxLayout(self)
00053 self.main_vlayout.addWidget(self.area)
00054 self.main_vlayout.addWidget(self.ok_button)
00055 self.setLayout(self.main_vlayout)
00056
00057 self.selection_vlayout = QVBoxLayout(self)
00058
00059 self.node_list = rosnode.get_node_names()
00060 self.node_list.sort()
00061 for node in self.node_list:
00062 self.addCheckBox(node)
00063 self.main_widget.setLayout(self.selection_vlayout)
00064 self.show()
00065
00066 def addCheckBox(self, node):
00067 item = QCheckBox(node, self)
00068 item.stateChanged.connect(lambda x: self.updateNode(x, node))
00069 self.selection_vlayout.addWidget(item)
00070
00071 def updateNode(self, state, node):
00072 if state == Qt.Checked:
00073 self.selected_nodes.append(node)
00074 else:
00075 self.selected_nodes.remove(node)
00076 if len(self.selected_nodes) > 0:
00077 self.ok_button.setEnabled(True)
00078 else:
00079 self.ok_button.setEnabled(False)
00080
00081 def onButtonClicked(self):
00082 master = rosgraph.Master('rqt_bag_recorder')
00083 state = master.getSystemState()
00084 subs = [t for t, l in state[1]
00085 if len([node_name for node_name in self.selected_nodes if node_name in l]) > 0]
00086 for topic in subs:
00087 self.parent_widget.changeTopicCheckState(topic, Qt.Checked)
00088 self.parent_widget.updateList(Qt.Checked, topic)
00089 self.close()