topic_selection.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2014, Surya Ambrose, Aldebaran
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Willow Garage, Inc. nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
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:  # The "All" checkbox was checked / unchecked
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)


rqt_bag
Author(s): Aaron Blasdel, Tim Field
autogenerated on Thu Aug 17 2017 02:19:27