topic_selection.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2014, Surya Ambrose, Aldebaran
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Willow Garage, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 
33 import rosgraph
34 
35 from python_qt_binding.QtCore import Qt, Signal
36 from python_qt_binding.QtWidgets import QWidget, QVBoxLayout, QCheckBox, QScrollArea, QPushButton
37 from .node_selection import NodeSelection
38 
39 
40 class TopicSelection(QWidget):
41 
42  recordSettingsSelected = Signal(bool, list)
43 
44  def __init__(self):
45  super(TopicSelection, self).__init__()
46  master = rosgraph.Master('rqt_bag_recorder')
47  self.setWindowTitle("Select the topics you want to record")
48  self.resize(500, 700)
49 
50  self.topic_list = []
51  self.selected_topics = []
52  self.items_list = []
53 
54  self.area = QScrollArea(self)
55  self.main_widget = QWidget(self.area)
56  self.ok_button = QPushButton("Record", self)
57  self.ok_button.clicked.connect(self.onButtonClicked)
58  self.ok_button.setEnabled(False)
59 
60  self.from_nodes_button = QPushButton("From Nodes", self)
61  self.from_nodes_button.clicked.connect(self.onFromNodesButtonClicked)
62 
63  self.main_vlayout = QVBoxLayout(self)
64  self.main_vlayout.addWidget(self.area)
65  self.main_vlayout.addWidget(self.ok_button)
66  self.main_vlayout.addWidget(self.from_nodes_button)
67  self.setLayout(self.main_vlayout)
68 
69  self.selection_vlayout = QVBoxLayout(self)
70  self.item_all = QCheckBox("All", self)
71  self.item_all.stateChanged.connect(self.updateList)
72  self.selection_vlayout.addWidget(self.item_all)
73  topic_data_list = master.getPublishedTopics('')
74  topic_data_list.sort()
75  for topic, datatype in topic_data_list:
76  self.addCheckBox(topic)
77 
78  self.main_widget.setLayout(self.selection_vlayout)
79 
80  self.area.setWidget(self.main_widget)
81  self.show()
82 
83  def addCheckBox(self, topic):
84  self.topic_list.append(topic)
85  item = QCheckBox(topic, self)
86  item.stateChanged.connect(lambda x: self.updateList(x, topic))
87  self.items_list.append(item)
88  self.selection_vlayout.addWidget(item)
89 
90  def changeTopicCheckState(self, topic, state):
91  for item in self.items_list:
92  if item.text() == topic:
93  item.setCheckState(state)
94  return
95 
96  def updateList(self, state, topic=None, force_update_state=False):
97  if topic is None: # The "All" checkbox was checked / unchecked
98  if state == Qt.Checked:
99  self.item_all.setTristate(False)
100  for item in self.items_list:
101  if item.checkState() == Qt.Unchecked:
102  item.setCheckState(Qt.Checked)
103  elif state == Qt.Unchecked:
104  self.item_all.setTristate(False)
105  for item in self.items_list:
106  if item.checkState() == Qt.Checked:
107  item.setCheckState(Qt.Unchecked)
108  else:
109  if state == Qt.Checked:
110  self.selected_topics.append(topic)
111  else:
112  self.selected_topics.remove(topic)
113  if self.item_all.checkState() == Qt.Checked:
114  self.item_all.setCheckState(Qt.PartiallyChecked)
115 
116  if self.selected_topics == []:
117  self.ok_button.setEnabled(False)
118  else:
119  self.ok_button.setEnabled(True)
120 
121  def onButtonClicked(self):
122  self.close()
123  self.recordSettingsSelected.emit(
124  self.item_all.checkState() == Qt.Checked, self.selected_topics)
125 
rqt_bag.topic_selection.TopicSelection.updateList
def updateList(self, state, topic=None, force_update_state=False)
Definition: topic_selection.py:96
rqt_bag.topic_selection.TopicSelection.area
area
Definition: topic_selection.py:54
rqt_bag.topic_selection.TopicSelection.__init__
def __init__(self)
Definition: topic_selection.py:44
rqt_bag.topic_selection.TopicSelection.onFromNodesButtonClicked
def onFromNodesButtonClicked(self)
Definition: topic_selection.py:126
rqt_bag.topic_selection.TopicSelection.item_all
item_all
Definition: topic_selection.py:70
rqt_bag.topic_selection.TopicSelection.onButtonClicked
def onButtonClicked(self)
Definition: topic_selection.py:121
rqt_bag.topic_selection.TopicSelection.from_nodes_button
from_nodes_button
Definition: topic_selection.py:60
rqt_bag.topic_selection.TopicSelection
Definition: topic_selection.py:40
rqt_bag.topic_selection.TopicSelection.changeTopicCheckState
def changeTopicCheckState(self, topic, state)
Definition: topic_selection.py:90
rqt_bag.topic_selection.TopicSelection.recordSettingsSelected
recordSettingsSelected
Definition: topic_selection.py:42
rqt_bag.topic_selection.TopicSelection.main_widget
main_widget
Definition: topic_selection.py:55
rqt_bag.node_selection.NodeSelection
Definition: node_selection.py:39
rqt_bag.topic_selection.TopicSelection.items_list
items_list
Definition: topic_selection.py:52
rqt_bag.topic_selection.TopicSelection.addCheckBox
def addCheckBox(self, topic)
Definition: topic_selection.py:83
rqt_bag.topic_selection.TopicSelection.selection_vlayout
selection_vlayout
Definition: topic_selection.py:69
rqt_bag.topic_selection.TopicSelection.node_selection
node_selection
Definition: topic_selection.py:127
rqt_bag.topic_selection.TopicSelection.topic_list
topic_list
Definition: topic_selection.py:50
rqt_bag.topic_selection.TopicSelection.ok_button
ok_button
Definition: topic_selection.py:56
rqt_bag.topic_selection.TopicSelection.main_vlayout
main_vlayout
Definition: topic_selection.py:63
rqt_bag.topic_selection.TopicSelection.selected_topics
selected_topics
Definition: topic_selection.py:51


rqt_bag
Author(s): Dirk Thomas , Aaron Blasdel , Austin Hendrix , Tim Field
autogenerated on Thu Mar 2 2023 03:43:15