visualizer_plugin.py
Go to the documentation of this file.
00001 # Copyright 2014 Open Source Robotics Foundation, Inc.
00002 #
00003 # Licensed under the Apache License, Version 2.0 (the "License");
00004 # you may not use this file except in compliance with the License.
00005 # You may obtain a copy of the License at
00006 #
00007 #     http://www.apache.org/licenses/LICENSE-2.0
00008 #
00009 # Unless required by applicable law or agreed to in writing, software
00010 # distributed under the License is distributed on an "AS IS" BASIS,
00011 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 # See the License for the specific language governing permissions and
00013 # limitations under the License.
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 # set this environment variable to enable diarc debug printing
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         # Process standalone plugin command-line arguments
00052         from argparse import ArgumentParser
00053         parser = ArgumentParser()
00054         # Add argument(s) to the parser.
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         # Initialize the Visualizer
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()


rqt_graphprofiler
Author(s): Dan Brooks
autogenerated on Thu Jun 6 2019 20:29:31