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
00035 from python_qt_binding.QtCore import Qt, Signal
00036 from python_qt_binding.QtWidgets import QWidget, QVBoxLayout, QCheckBox, QScrollArea, QPushButton
00037 from .node_selection import NodeSelection
00038
00039
00040 class TopicSelection(QWidget):
00041
00042 recordSettingsSelected = Signal(bool, list)
00043
00044 def __init__(self):
00045 super(TopicSelection, self).__init__()
00046 master = rosgraph.Master('rqt_bag_recorder')
00047 self.setWindowTitle("Select the topics you want to record")
00048 self.resize(500, 700)
00049
00050 self.topic_list = []
00051 self.selected_topics = []
00052 self.items_list = []
00053
00054 self.area = QScrollArea(self)
00055 self.main_widget = QWidget(self.area)
00056 self.ok_button = QPushButton("Record", self)
00057 self.ok_button.clicked.connect(self.onButtonClicked)
00058 self.ok_button.setEnabled(False)
00059
00060 self.from_nodes_button = QPushButton("From Nodes", self)
00061 self.from_nodes_button.clicked.connect(self.onFromNodesButtonClicked)
00062
00063 self.main_vlayout = QVBoxLayout(self)
00064 self.main_vlayout.addWidget(self.area)
00065 self.main_vlayout.addWidget(self.ok_button)
00066 self.main_vlayout.addWidget(self.from_nodes_button)
00067 self.setLayout(self.main_vlayout)
00068
00069 self.selection_vlayout = QVBoxLayout(self)
00070 self.item_all = QCheckBox("All", self)
00071 self.item_all.stateChanged.connect(self.updateList)
00072 self.selection_vlayout.addWidget(self.item_all)
00073 topic_data_list = master.getPublishedTopics('')
00074 topic_data_list.sort()
00075 for topic, datatype in topic_data_list:
00076 self.addCheckBox(topic)
00077
00078 self.main_widget.setLayout(self.selection_vlayout)
00079
00080 self.area.setWidget(self.main_widget)
00081 self.show()
00082
00083 def addCheckBox(self, topic):
00084 self.topic_list.append(topic)
00085 item = QCheckBox(topic, self)
00086 item.stateChanged.connect(lambda x: self.updateList(x, topic))
00087 self.items_list.append(item)
00088 self.selection_vlayout.addWidget(item)
00089
00090 def changeTopicCheckState(self, topic, state):
00091 for item in self.items_list:
00092 if item.text() == topic:
00093 item.setCheckState(state)
00094 return
00095
00096 def updateList(self, state, topic=None, force_update_state=False):
00097 if topic is None:
00098 if state == Qt.Checked:
00099 self.item_all.setTristate(False)
00100 for item in self.items_list:
00101 if item.checkState() == Qt.Unchecked:
00102 item.setCheckState(Qt.Checked)
00103 elif state == Qt.Unchecked:
00104 self.item_all.setTristate(False)
00105 for item in self.items_list:
00106 if item.checkState() == Qt.Checked:
00107 item.setCheckState(Qt.Unchecked)
00108 else:
00109 if state == Qt.Checked:
00110 self.selected_topics.append(topic)
00111 else:
00112 self.selected_topics.remove(topic)
00113 if self.item_all.checkState() == Qt.Checked:
00114 self.item_all.setCheckState(Qt.PartiallyChecked)
00115
00116 if self.selected_topics == []:
00117 self.ok_button.setEnabled(False)
00118 else:
00119 self.ok_button.setEnabled(True)
00120
00121 def onButtonClicked(self):
00122 self.close()
00123 self.recordSettingsSelected.emit(
00124 self.item_all.checkState() == Qt.Checked, self.selected_topics)
00125
00126 def onFromNodesButtonClicked(self):
00127 self.node_selection = NodeSelection(self)