WUT Velma robot API
subsystem_components.py
Go to the documentation of this file.
1 # Copyright (c) 2014, Robot Control and Pattern Recognition Group, Warsaw University of Technology
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution.
11 # * Neither the name of the Warsaw University of Technology nor the
12 # names of its contributors may be used to endorse or promote products
13 # derived from this software without specific prior written permission.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 # DISCLAIMED. IN NO EVENT SHALL <COPYright HOLDER> BE LIABLE FOR ANY
19 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 from __future__ import division
27 import os
28 import math
29 import subprocess
30 
31 from python_qt_binding import loadUi
32 from python_qt_binding.QtCore import Qt, QTimer, Signal, Slot, QRectF, QPointF, QSize, QRect, QPoint
33 from python_qt_binding.QtWidgets import QWidget, QPushButton, QVBoxLayout, QHBoxLayout, QLabel, QListWidgetItem, QDialog, QGraphicsView, QGraphicsScene, QGraphicsPathItem, QTableWidgetItem, QHeaderView, QStyle, QCommonStyle
34 from python_qt_binding.QtGui import QColor, QPen, QBrush, QPainterPath, QPolygonF, QTransform, QPainter, QIcon, QPixmap, QPaintEvent, QPalette
35 from python_qt_binding.QtSvg import QSvgGenerator
36 import roslib
37 import rospkg
38 import rospy
39 from rospy.exceptions import ROSException
40 
41 import xml.dom.minidom as minidom
42 import tempfile
43 
44 from rqt_topic.topic_info import TopicInfo
45 
46 from subsystem_msgs.srv import *
47 
48 def getComponentBrush(state):
49  b = QBrush(QColor(0,0,255)) # unconfigured/preoperational
50  if state == 'S': # stopped
51  b = QBrush(QColor(255,255,255))
52  elif state == 'R': # running
53  b = QBrush(QColor(0,255,0))
54  elif state == 'E': # error
55  b = QBrush(QColor(255,0,0))
56  elif state == 'F': # fatal error
57  b = QBrush(QColor(255,127,127))
58  elif state == 'X': # exception
59  b = QBrush(QColor(0,255,255))
60  return b
61 
63  tooltip = 'unconfigured/preoperational'
64  if state == 'S': # stopped
65  tooltip = 'stopped'
66  elif state == 'R': # running
67  tooltip = 'running'
68  elif state == 'E': # error
69  tooltip = 'error'
70  elif state == 'F': # fatal error
71  tooltip = 'fatal error'
72  elif state == 'X': # exception
73  tooltip = 'exception'
74  return tooltip
75 
76 class ComponentsDialog(QDialog):
77 
78  @Slot()
79  def closeClick(self):
80  self.close()
81 
82  def __init__(self, subsystem_name, parent=None):
83  super(ComponentsDialog, self).__init__(parent)
84 
85  self.parent = parent
86 
87  self.setWindowFlags(Qt.Window)
88 
89  rp = rospkg.RosPack()
90  ui_file = os.path.join(rp.get_path('rqt_agent'), 'resource', 'SubsystemComponents.ui')
91  loadUi(ui_file, self)
92 
93  self.setWindowTitle(subsystem_name + " - state history")
94 
95  self.pushButton_close.clicked.connect(self.closeClick)
96 
97  self.components = {}
98 
99  def updateState(self, components_state, components_diag_msgs):
100  # iterate through components and add them to QListWidget
101  for comp in components_state:
102  if not comp in self.components:
103  item = QListWidgetItem()
104  item.setText(comp)
105  self.components[comp] = item
106  self.listWidget.addItem(item)
107  self.components[comp].setBackground( getComponentBrush(components_state[comp]) )
108  self.components[comp].setToolTip( getComponentTooltip(components_state[comp]) )
109 
110  for comp in components_diag_msgs:
111  if comp in self.components:
112  self.components[comp].setText(comp + ' (' + components_diag_msgs[comp] + ')')
113 
def updateState(self, components_state, components_diag_msgs)
def __init__(self, subsystem_name, parent=None)