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 import argparse
00034
00035 from python_qt_binding import QT_BINDING
00036 from python_qt_binding.QtCore import qDebug
00037 from rqt_gui_py.plugin import Plugin
00038
00039 from rqt_py_common.ini_helper import pack, unpack
00040
00041 from .plot_widget import PlotWidget
00042
00043 from .data_plot import DataPlot
00044
00045 class Plot(Plugin):
00046
00047 def __init__(self, context):
00048 super(Plot, self).__init__(context)
00049 self.setObjectName('Plot')
00050
00051 self._context = context
00052
00053 self._args = self._parse_args(context.argv())
00054 self._widget = PlotWidget(initial_topics=self._args.topics, start_paused=self._args.start_paused)
00055 self._data_plot = DataPlot(self._widget)
00056
00057
00058 self._data_plot.set_autoscale(x=False)
00059 self._data_plot.set_autoscale(y=DataPlot.SCALE_EXTEND|DataPlot.SCALE_VISIBLE)
00060 self._data_plot.set_xlim([0, 10.0])
00061
00062 self._widget.switch_data_plot_widget(self._data_plot)
00063 if context.serial_number() > 1:
00064 self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))
00065 context.add_widget(self._widget)
00066
00067 def _parse_args(self, argv):
00068 parser = argparse.ArgumentParser(prog='rqt_plot', add_help=False)
00069 Plot.add_arguments(parser)
00070 args = parser.parse_args(argv)
00071
00072
00073 topic_list = []
00074 for t in args.topics:
00075
00076 c_topics = []
00077
00078 for sub_t in [x for x in t.split(',') if x]:
00079
00080 if ':' in sub_t:
00081 base = sub_t[:sub_t.find(':')]
00082
00083 c_topics.append(base)
00084 if not '/' in base:
00085 parser.error("%s must contain a topic and field name" % sub_t)
00086 base = base[:base.rfind('/')]
00087
00088
00089 fields = sub_t.split(':')[1:]
00090 c_topics.extend(["%s/%s" % (base, f) for f in fields if f])
00091 else:
00092 c_topics.append(sub_t)
00093
00094 import rosgraph
00095 c_topics = [rosgraph.names.script_resolve_name('rqt_plot', n) for n in c_topics]
00096 if type(c_topics) == list:
00097 topic_list.extend(c_topics)
00098 else:
00099 topic_list.append(c_topics)
00100 args.topics = topic_list
00101
00102 return args
00103
00104 @staticmethod
00105 def add_arguments(parser):
00106 group = parser.add_argument_group('Options for rqt_plot plugin')
00107 group.add_argument('-P', '--pause', action='store_true', dest='start_paused',
00108 help='Start in paused state')
00109 group.add_argument('-e', '--empty', action='store_true', dest='start_empty',
00110 help='Start without restoring previous topics')
00111 group.add_argument('topics', nargs='*', default=[], help='Topics to plot')
00112
00113 def _update_title(self):
00114 self._widget.setWindowTitle(self._data_plot.getTitle())
00115 if self._context.serial_number() > 1:
00116 self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % self._context.serial_number()))
00117
00118 def save_settings(self, plugin_settings, instance_settings):
00119 self._data_plot.save_settings(plugin_settings, instance_settings)
00120 instance_settings.set_value('autoscroll', self._widget.autoscroll_checkbox.isChecked())
00121 instance_settings.set_value('topics', pack(self._widget._rosdata.keys()))
00122
00123 def restore_settings(self, plugin_settings, instance_settings):
00124 autoscroll = instance_settings.value('autoscroll', True) in [True, 'true']
00125 self._widget.autoscroll_checkbox.setChecked(autoscroll)
00126 self._data_plot.autoscroll(autoscroll)
00127
00128 self._update_title()
00129
00130 if len(self._widget._rosdata.keys()) == 0 and not self._args.start_empty:
00131 topics = unpack(instance_settings.value('topics', []))
00132 if topics:
00133 for topic in topics:
00134 self._widget.add_topic(topic)
00135
00136 self._data_plot.restore_settings(plugin_settings, instance_settings)
00137
00138 def trigger_configuration(self):
00139 self._data_plot.doSettingsDialog()
00140 self._update_title()
00141
00142 def shutdown_plugin(self):
00143 self._widget.clean_up_subscribers()