5 from python_qt_binding.QtCore
import Qt, QSize, QRegExp, Signal, Slot
6 from python_qt_binding.QtGui
import QWidget, QRegExpValidator, QHBoxLayout, QPushButton, QComboBox, QIcon
12 topic_changed_signal = Signal(str)
14 def __init__(self, parent=None, topic_type=str(), is_action_topic=
False):
15 QWidget.__init__(self, parent)
26 hbox.setContentsMargins(0, 0, 0, 0)
30 self.topic_combo_box.setEnabled(
False)
31 self.topic_combo_box.blockSignals(
True)
32 self.topic_combo_box.setValidator(QRegExpValidator(QRegExp(
'((\d|\w|/)(?!//))*'), self))
33 self.topic_combo_box.currentIndexChanged[str].connect(self.
topic_changed)
37 icon = QIcon.fromTheme(
"view-refresh")
38 size = icon.actualSize(QSize(32, 32))
41 refresh_topics_button = QPushButton()
43 refresh_topics_button.setIcon(icon)
44 refresh_topics_button.setFixedSize(size.width()+2, size.height()+2)
45 hbox.addWidget(refresh_topics_button)
57 self.topic_combo_box.setEditable(enable)
60 if self.topic_combo_box.isEnabled():
61 return self.topic_combo_box.currentText()
67 self.topic_changed_signal.emit(topic_name)
71 self.topic_combo_box.clear()
72 self.topic_combo_box.setEnabled(
False)
73 self.topic_combo_box.blockSignals(
True)
74 self.topic_combo_box.addItem(
'Updating...')
77 _, _, topic_type = rospy.get_master().getTopicTypes()
78 topic_dict = dict(topic_type)
80 topic_dict_filtered = dict()
81 for k, v
in topic_dict.items():
82 if (len(topic_type) == 0)
or (v == self.
topic_type):
84 topic_dict_filtered[k[:-5]] = v
86 topic_dict_filtered[k] = v
88 self.topic_combo_box.clear()
89 self.topic_combo_box.addItems(sorted(topic_dict_filtered.keys()))
91 if self.topic_combo_box.count() > 0:
92 self.topic_combo_box.setEnabled(
True)
93 self.topic_combo_box.blockSignals(
False)
96 self.topic_combo_box.addItem(
'No topics available!')