def __init__(self): super(StatusLightWidget, self).__init__() self.lock = Lock() self.status_sub = None self.status = 0 self._status_topics = [] self._update_topic_timer = QTimer(self) self._update_topic_timer.timeout.connect(self.updateTopics) self._update_topic_timer.start(1) self._active_topic = None self._dialog = ComboBoxDialog() self._update_plot_timer = QTimer(self) self._update_plot_timer.timeout.connect(self.redraw) self._update_plot_timer.start(5)
def __init__(self): super(StringLabelWidget, self).__init__() self.lock = Lock() vbox = QtGui.QVBoxLayout(self) self.label = QLabel() self.label.setAlignment(Qt.AlignLeft) self.label.setSizePolicy( QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)) font = QFont("Helvetica", 14) self.label.setFont(font) self.label.setWordWrap(True) vbox.addWidget(self.label) self.string_sub = None self._string_topics = [] self._update_topic_timer = QTimer(self) self._update_topic_timer.timeout.connect(self.updateTopics) self._update_topic_timer.start(1) self._active_topic = None self._dialog = ComboBoxDialog()
def __init__(self): super(StatusLightWidget, self).__init__() self.lock = Lock() self.status_sub = None self.status = 0 self._status_topics = [] self._update_topic_timer = QTimer(self) self._update_topic_timer.timeout.connect(self.updateTopics) self._update_topic_timer.start(1000) self._active_topic = None self._dialog = ComboBoxDialog() self._update_plot_timer = QTimer(self) self._update_plot_timer.timeout.connect(self.redraw) self._update_plot_timer.start(1000 / 15)
class StringLabelWidget(QWidget): def __init__(self): super(StringLabelWidget, self).__init__() self.lock = Lock() vbox = QtGui.QVBoxLayout(self) self.label = QLabel() self.label.setAlignment(Qt.AlignLeft) self.label.setSizePolicy( QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)) font = QFont("Helvetica", 14) self.label.setFont(font) self.label.setWordWrap(True) vbox.addWidget(self.label) self.string_sub = None self._string_topics = [] self._update_topic_timer = QTimer(self) self._update_topic_timer.timeout.connect(self.updateTopics) self._update_topic_timer.start(1) self._active_topic = None self._dialog = ComboBoxDialog() def trigger_configuration(self): self._dialog.exec_() self.setupSubscriber(self._string_topics[self._dialog.number]) def updateTopics(self): need_to_update = False for (topic, topic_type) in rospy.get_published_topics(): if topic_type == "std_msgs/String": if not topic in self._string_topics: self._string_topics.append(topic) need_to_update = True if need_to_update: self._string_topics = sorted(self._string_topics) self._dialog.combo_box.clear() for topic in self._string_topics: self._dialog.combo_box.addItem(topic) if self._active_topic: if self._active_topic not in self._string_topics: self._string_topics.append(self._active_topic) self._dialog.combo_box.addItem(self._active_topic) self._dialog.combo_box.setCurrentIndex( self._string_topics.index(self._active_topic)) def setupSubscriber(self, topic): if self.string_sub: self.string_sub.unregister() self.string_sub = rospy.Subscriber(topic, String, self.stringCallback) self._active_topic = topic def onActivated(self, number): self.setupSubscriber(self._string_topics[number]) def stringCallback(self, msg): self.string = msg.data self.label.setText(self.string) def save_settings(self, plugin_settings, instance_settings): if self._active_topic: instance_settings.set_value("active_topic", self._active_topic) def restore_settings(self, plugin_settings, instance_settings): if instance_settings.value("active_topic"): topic = instance_settings.value("active_topic") self._dialog.combo_box.addItem(topic) self.setupSubscriber(topic)
class StatusLightWidget(QWidget): _UNKNOWN_COLOR = QColor("#dddddd") _SUCCESS_COLOR = QColor("#18FFFF") _WARN_COLOR = QColor("#FFCA00") _ERROR_COLOR = QColor("#F44336") def __init__(self): super(StatusLightWidget, self).__init__() self.lock = Lock() self.status_sub = None self.status = 0 self._status_topics = [] self._update_topic_timer = QTimer(self) self._update_topic_timer.timeout.connect(self.updateTopics) self._update_topic_timer.start(1000) self._active_topic = None self._dialog = ComboBoxDialog() self._update_plot_timer = QTimer(self) self._update_plot_timer.timeout.connect(self.redraw) self._update_plot_timer.start(1000 / 15) def redraw(self): self.update() def paintEvent(self, event): with self.lock: if self.status == 1: color = self._SUCCESS_COLOR elif self.status == 2: color = self._WARN_COLOR else: color = self._UNKNOWN_COLOR rect = event.rect() qp = QPainter() qp.begin(self) radius = min(rect.width(), rect.height()) - 100 qp.setFont(QFont('Helvetica', 100)) qp.setPen(QPen(QBrush(color), 50)) qp.setBrush(color) qp.drawEllipse((rect.width() - radius) / 2, (rect.height() - radius) / 2, radius, radius) qp.end() return def trigger_configuration(self): self._dialog.exec_() self.setupSubscriber(self._status_topics[self._dialog.number]) def updateTopics(self): need_to_update = False for (topic, topic_type) in rospy.get_published_topics(): if topic_type == "std_msgs/UInt8": if not topic in self._status_topics: self._status_topics.append(topic) need_to_update = True if need_to_update: self._status_topics = sorted(self._status_topics) self._dialog.combo_box.clear() for topic in self._status_topics: self._dialog.combo_box.addItem(topic) if self._active_topic: if self._active_topic not in self._status_topics: self._status_topics.append(self._active_topic) self._dialog.combo_box.addItem(self._active_topic) self._dialog.combo_box.setCurrentIndex(self._status_topics.index(self._active_topic)) def setupSubscriber(self, topic): if self.status_sub: self.status_sub.unregister() self.status_sub = rospy.Subscriber(topic, UInt8, self.statusCallback) self._active_topic = topic def onActivated(self, number): self.setupSubscriber(self._status_topics[number]) def statusCallback(self, msg): self.status = msg.data def save_settings(self, plugin_settings, instance_settings): if self._active_topic: instance_settings.set_value("active_topic", self._active_topic) def restore_settings(self, plugin_settings, instance_settings): if instance_settings.value("active_topic"): topic = instance_settings.value("active_topic") self._dialog.combo_box.addItem(topic) self.setupSubscriber(topic)
class StatusLightWidget(QWidget): _UNKNOWN_COLOR = QColor("#dddddd") _SUCCESS_COLOR = QColor("#18FFFF") _WARN_COLOR = QColor("#FFCA00") _ERROR_COLOR = QColor("#F44336") def __init__(self): super(StatusLightWidget, self).__init__() self.lock = Lock() self.status_sub = None self.status = 0 self._status_topics = [] self._update_topic_timer = QTimer(self) self._update_topic_timer.timeout.connect(self.updateTopics) self._update_topic_timer.start(1) self._active_topic = None self._dialog = ComboBoxDialog() self._update_plot_timer = QTimer(self) self._update_plot_timer.timeout.connect(self.redraw) self._update_plot_timer.start(5) def redraw(self): self.update() def paintEvent(self, event): with self.lock: if self.status == 1: color = self._SUCCESS_COLOR elif self.status == 2: color = self._WARN_COLOR else: color = self._UNKNOWN_COLOR rect = event.rect() qp = QPainter() qp.begin(self) radius = min(rect.width(), rect.height()) - 100 qp.setFont(QFont('Helvetica', 100)) qp.setPen(QPen(QBrush(color), 50)) qp.setBrush(color) qp.drawEllipse((rect.width() - radius) / 2, (rect.height() - radius) / 2, radius, radius) qp.end() return def trigger_configuration(self): self._dialog.exec_() self.setupSubscriber(self._status_topics[self._dialog.number]) def updateTopics(self): need_to_update = False for (topic, topic_type) in rospy.get_published_topics(): if topic_type == "std_msgs/UInt8": if not topic in self._status_topics: self._status_topics.append(topic) need_to_update = True if need_to_update: self._status_topics = sorted(self._status_topics) self._dialog.combo_box.clear() for topic in self._status_topics: self._dialog.combo_box.addItem(topic) if self._active_topic: if self._active_topic not in self._status_topics: self._status_topics.append(self._active_topic) self._dialog.combo_box.addItem(self._active_topic) self._dialog.combo_box.setCurrentIndex( self._status_topics.index(self._active_topic)) def setupSubscriber(self, topic): if self.status_sub: self.status_sub.unregister() self.status_sub = rospy.Subscriber(topic, UInt8, self.statusCallback) self._active_topic = topic def onActivated(self, number): self.setupSubscriber(self._status_topics[number]) def statusCallback(self, msg): self.status = msg.data def save_settings(self, plugin_settings, instance_settings): if self._active_topic: instance_settings.set_value("active_topic", self._active_topic) def restore_settings(self, plugin_settings, instance_settings): if instance_settings.value("active_topic"): topic = instance_settings.value("active_topic") self._dialog.combo_box.addItem(topic) self.setupSubscriber(topic)