35 from math
import floor
36 from collections
import deque
39 from python_qt_binding.QtCore
import QPointF, Signal, Slot
40 from python_qt_binding.QtGui
import QColor, QIcon
41 from python_qt_binding.QtWidgets
import QGraphicsPixmapItem, QGraphicsView, \
45 from diagnostic_msgs.msg
import DiagnosticStatus
50 This class draws a graphical representation of a timeline. 52 This is ONLY the bar and colored boxes. 54 When you instantiate this class, do NOT forget to call set_init_data to 59 position_changed = Signal(int)
63 """Cannot take args other than parent due to loadUi limitation.""" 65 super(TimelineView, self).
__init__(parent=parent)
76 self.setUpdatesEnabled(
True)
86 :type event: QMouseEvent 93 :type event: QMouseEvent 96 self.paused.emit(
True)
103 :type event: QMouseEvent 110 Get the index in the timeline from the mouse click position 112 :param x: Position relative to self widget. 115 width = self.size().width()
117 width_cell = width / float(max(len(self.
_levels), 1))
118 return int(floor(x / width_cell))
123 Set marker position from index 125 :param xpos: Marker index 128 rospy.logwarn(
'Called set_marker_pos before set_levels')
155 Judge if val is within the range given by min & max. 156 If not, return either min or max. 158 :type val: any number format 159 :type min: any number format 160 :type max: any number format 177 Gets called either when new msg comes in or when marker is moved by 190 width_tl = qsize.width()
192 w = width_tl / float(max(len(self.
_levels), 1))
193 is_enabled = self.isEnabled()
195 for i, level
in enumerate(self.
_levels):
196 h = self.viewport().height()
199 qcolor = QColor(
'grey')
200 if is_enabled
and level
is not None:
201 if level > DiagnosticStatus.ERROR:
203 level = DiagnosticStatus.ERROR
204 qcolor = util.level_to_color(level)
210 self._scene.addRect(w * i, 0, w, h, QColor(
'white'), qcolor)
214 while xpos_marker < 0:
215 xpos_marker += len(self.
_levels)
216 xpos_marker = (xpos_marker * w +
218 pos_marker = QPointF(xpos_marker, 0)
223 timeline_marker.setPos(pos_marker)
224 self._scene.addItem(timeline_marker)
227 timeline_marker_icon = QIcon.fromTheme(
'system-search')
228 timeline_marker_icon_pixmap = timeline_marker_icon.pixmap(
231 return QGraphicsPixmapItem(timeline_marker_icon_pixmap)
def __init__(self, parent=None)
def mouseMoveEvent(self, event)
def set_levels(self, levels)
def mouseReleaseEvent(self, event)
def set_marker_pos(self, xpos)
def _clamp(self, val, min, max)
def mousePressEvent(self, event)
def _instantiate_tl_icon(self)