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