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.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: # The "All" checkbox was checked / unchecked
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)


rqt_bag
Author(s): Aaron Blasdel, Tim Field
autogenerated on Mon Oct 6 2014 07:15:30