error_status_widget.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import vigir_footstep_planning_msgs.msg
5 
6 from python_qt_binding.QtCore import Qt, Signal, Slot
7 from python_qt_binding.QtGui import QWidget, QVBoxLayout, QHBoxLayout, QTextEdit, QPushButton, QCheckBox, QSizePolicy, QColor
8 
9 from vigir_footstep_planning_msgs.msg import ErrorStatus
11 
12 
13 # widget for printing error status msgs to a text box
14 class QErrorStatusTextBox(QTextEdit):
15 
16  def __init__(self):
17  QTextEdit.__init__(self)
18  self.setReadOnly(True)
19 
20  @Slot(str, QColor)
21  def out_log(self, msg, color=Qt.black):
22  self.setTextColor(color)
23  self.append(msg)
24 
25  def set_error_status(self, error_status):
26  self.clear()
27  self.append_error_status(error_status)
28 
29  def append_error_status(self, error_status):
30  if error_status.error != 0:
31  self.out_log(error_status.error_msg, Qt.red)
32 
33  if error_status.warning != 0:
34  self.out_log(error_status.warning_msg, QColor(255, 165, 0))
35 
36 
37 # complex widget for printing error status msgs to a text box
38 class QErrorStatusWidget(QWidget):
39 
40  error_status_signal = Signal(ErrorStatus)
41 
42  def __init__(self, parent=None, subscribe=False):
43  QWidget.__init__(self, parent)
44 
45  # start widget
46  vbox = QVBoxLayout()
47  vbox.setMargin(0)
48  vbox.setContentsMargins(0, 0, 0, 0)
49 
50  # add error status text edit
52  self.error_status_text_box_layout = QHBoxLayout()
53  self.error_status_text_box_layout.addWidget(self.error_status_text_box)
54  vbox.addLayout(self.error_status_text_box_layout)
55 
56  # add panel
57  hbox = QHBoxLayout()
58 
59  # clear push button
60  self.execute_command = QPushButton("Clear")
61  self.execute_command.clicked.connect(self.error_status_text_box.clear)
62  hbox.addWidget(self.execute_command)
63 
64  hbox.addStretch()
65 
66  # hide window checkbox
67  hide_window_check_box = QCheckBox("Hide")
68  hide_window_check_box.stateChanged.connect(self.state_changed)
69  hbox.addWidget(hide_window_check_box)
70 
71  # end panel
72  vbox.addLayout(hbox)
73 
74  # end widget
75  self.setLayout(vbox)
76  #self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
77 
78  # subscriber
79  if subscribe:
80  self.error_status_sub = rospy.Subscriber("error_status", ErrorStatus, self.error_status_callback)
81  self.subscribed = subscribe
82 
83  # connect signal slot internally to prevent crash by subscriber
84  self.error_status_signal.connect(self.append_error_status)
85 
86  def __del__(self):
87  if self.subscribed:
88  self.error_status_sub.unregister()
89 
90  def error_status_callback(self, error_status):
91  self.error_status_signal.emit(error_status)
92 
93  def get_text_box(self):
94  return self.error_status_text_box
95 
96  @Slot(str, QColor)
97  def set_text(self, msg, color):
98  self.error_status_text_box.clear()
99  self.append(msg, color)
100 
101  @Slot(str, QColor)
102  def append(self, msg, color):
103  self.error_status_text_box.out_log(msg, color)
104 
105  @Slot(ErrorStatus)
106  def set_error_status(self, error_status):
107  self.error_status_text_box.set_error_status(error_status)
108 
109  @Slot(ErrorStatus)
110  def append_error_status(self, error_status):
111  self.error_status_text_box.append_error_status(error_status)
112 
113  @Slot(int)
114  def state_changed(self, state):
115  if state == Qt.Unchecked:
116  self.error_status_text_box_layout.addWidget(self.error_status_text_box)
117  self.error_status_text_box.setVisible(True)
118  elif state == Qt.Checked:
119  self.error_status_text_box_layout.removeWidget(self.error_status_text_box)
120  self.error_status_text_box.setVisible(False)


vigir_footstep_planning_lib
Author(s): Alexander Stumpf
autogenerated on Mon Jun 10 2019 15:47:33