Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 from python_qt_binding.QtWidgets import QTreeWidgetItem
00036 import rqt_robot_monitor.util_robot_monitor as util
00037
00038 class _StatusItem(QTreeWidgetItem):
00039 """
00040 Internal subclass of QTreeWidgetItem which adds a 'name' member to make
00041 it easier to extract the item name and create an inspector when an item
00042 is clicked
00043 """
00044 def __init__(self, name):
00045 super(_StatusItem, self).__init__()
00046 self.name = name
00047
00048 class StatusItem(object):
00049 """
00050 A class that wraps the default QTreeWidgetItem, so that we can manipulate
00051 all of the nodes in the tree in the same way (even the invisible root node)
00052 """
00053 def __init__(self, item=None):
00054 self._children = {}
00055 self.updated = False
00056 if item is not None:
00057 self._item = item
00058 else:
00059 self._item = _StatusItem("NONAME")
00060
00061 def update(self, status, displayname):
00062 self.updated = True
00063 self.displayname = displayname
00064 self._item.name = status.name
00065 self._item.setText(0, self.displayname)
00066 self._item.setIcon(0, util.level_to_icon(status.level))
00067 self._item.setText(1, status.message)
00068
00069 def prune(self):
00070 stale = []
00071 for child in self._children:
00072 if not self._children[child].updated:
00073 stale.append(child)
00074 else:
00075 self._children[child].prune()
00076 if len(stale) > 0:
00077 for child in stale:
00078 self._item.removeChild(self._children[child]._item)
00079 del self._children[child]
00080 self.updated = False
00081
00082
00083 def __getitem__(self, key):
00084
00085 if not key in self._children:
00086 self._children[key] = StatusItem()
00087 self._item.addChild(self._children[key]._item)
00088 return self._children[key]
00089
00090 def __setitem__(self, key, value):
00091
00092
00093 if key in self._children:
00094 self._item.removeChild(self._children[key]._item)
00095 self._children[key] = value
00096 self._item.addChild(value._item)
00097
00098 def __contains__(self, key):
00099 return key in self._children
00100
00101 def __iter__(self):
00102 for key in self._children:
00103 yield key
rqt_robot_monitor
Author(s): Austin Hendrix, Isaac Saito, Ze'ev Klapow, Kevin Watts, Josh Faust
autogenerated on Tue Sep 26 2017 02:44:21