Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 from __future__ import print_function
00016
00017 import os
00018 import sys
00019 import logging
00020
00021 from python_qt_binding.QtGui import QCheckBox
00022 from python_qt_binding.QtGui import QHBoxLayout
00023 from python_qt_binding.QtGui import QIcon
00024 from python_qt_binding.QtGui import QPushButton
00025 from python_qt_binding.QtGui import QVBoxLayout
00026 from python_qt_binding.QtGui import QWidget
00027
00028 from qt_gui.plugin import Plugin
00029 import rosprofiler_adapter
00030
00031 from diarc import qt_view
00032
00033 from blacklist import BlacklistDialog
00034
00035 TOPIC_BLACKLIST = ['/clock', '/topology', '/statistics']
00036 NODE_BLACKLIST = ['/rosout']
00037
00038
00039 if 'DIARC_DEBUG' in os.environ:
00040 logging.getLogger('diarc').setLevel(logging.DEBUG)
00041 ch = logging.StreamHandler(sys.stdout)
00042 ch.setLevel(logging.DEBUG)
00043 logging.getLogger('diarc').addHandler(ch)
00044
00045
00046 class VisualizerPlugin(Plugin):
00047 def __init__(self, context):
00048 super(VisualizerPlugin, self).__init__(context)
00049 self.setObjectName('VisualizerPlugin')
00050
00051
00052 from argparse import ArgumentParser
00053 parser = ArgumentParser()
00054
00055 parser.add_argument("-q", "--quiet", action="store_true",
00056 dest="quiet", help="Put plugin in silent mode")
00057 args, unknowns = parser.parse_known_args(context.argv())
00058
00059 context.add_widget(VisualizerWidget())
00060
00061 def shutdown_plugin(self):
00062 pass
00063
00064 def save_settings(self, plugin_settings, instance_settings):
00065 pass
00066
00067 def restore_settings(self, plugin_settings, instance_settings):
00068 pass
00069
00070
00071 class VisualizerWidget(QWidget):
00072 def __init__(self, parent=None):
00073 super(VisualizerWidget, self).__init__(parent)
00074 self.setWindowTitle('Graph Profiler Visualizer')
00075 vbox = QVBoxLayout()
00076 self.setLayout(vbox)
00077
00078 toolbar_layout = QHBoxLayout()
00079 refresh_button = QPushButton()
00080 refresh_button.setIcon(QIcon.fromTheme('view-refresh'))
00081 auto_refresh_checkbox = QCheckBox("Auto Refresh")
00082 hide_disconnected_topics = QCheckBox("Hide Disconnected Topics")
00083 topic_blacklist_button = QPushButton("Topic Blacklist")
00084 node_blacklist_button = QPushButton("Node Blacklist")
00085
00086 refresh_button.clicked.connect(self._refresh)
00087 topic_blacklist_button.clicked.connect(self._edit_topic_blacklist)
00088 node_blacklist_button.clicked.connect(self._edit_node_blacklist)
00089 auto_refresh_checkbox.setCheckState(2)
00090 auto_refresh_checkbox.stateChanged.connect(self._autorefresh_changed)
00091 hide_disconnected_topics.setCheckState(2)
00092 hide_disconnected_topics.stateChanged.connect(self._hidedisconnectedtopics_changed)
00093
00094 toolbar_layout.addWidget(refresh_button)
00095 toolbar_layout.addWidget(auto_refresh_checkbox)
00096 toolbar_layout.addStretch(0)
00097 toolbar_layout.addWidget(hide_disconnected_topics)
00098 toolbar_layout.addWidget(topic_blacklist_button)
00099 toolbar_layout.addWidget(node_blacklist_button)
00100 vbox.addLayout(toolbar_layout)
00101
00102
00103 self._view = qt_view.QtView()
00104 self._adapter = rosprofiler_adapter.ROSProfileAdapter(self._view)
00105 self._adapter.set_topic_quiet_list(TOPIC_BLACKLIST)
00106 self._adapter.set_node_quiet_list(NODE_BLACKLIST)
00107 vbox.addWidget(self._view)
00108
00109 def _edit_topic_blacklist(self):
00110 """ Opens topic blacklist Dialog and modifies the blacklist """
00111 topics = self._adapter.get_topic_quiet_list()
00112 topic_blacklist = BlacklistDialog.get_blacklist(values=topics)
00113 self._adapter.set_topic_quiet_list(topic_blacklist)
00114 self._adapter.topology_update()
00115
00116 def _edit_node_blacklist(self):
00117 """ Opens node blacklist Dialog and modifies the blacklist """
00118 nodes = self._adapter.get_node_quiet_list()
00119 node_blacklist = BlacklistDialog.get_blacklist(values=nodes)
00120 self._adapter.set_node_quiet_list(node_blacklist)
00121 self._adapter.topology_update()
00122
00123 def _autorefresh_changed(self, value):
00124 if value == 2:
00125 print("Enabling Autorefresh")
00126 self._adapter.enable_auto_update()
00127 self._refresh()
00128 elif value == 0:
00129 print("Disabling Autorefresh")
00130 self._adapter.disable_auto_update()
00131 else:
00132 raise Exception()
00133
00134 def _hidedisconnectedtopics_changed(self, value):
00135 if value == 2:
00136 print("Hiding disconnected topics")
00137 self._adapter.hide_disconnected_topics()
00138 elif value == 0:
00139 print("Showing disconnected topics")
00140 self._adapter.show_disconnected_topics()
00141 else:
00142 raise Exception()
00143
00144 def _refresh(self):
00145 self._adapter.topology_update()
00146 self._adapter.statistics_update()