bag.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2012, Willow Garage, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Willow Garage, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 
33 import os
34 import argparse
35 import threading
36 
37 from qt_gui.plugin import Plugin
38 
39 from .bag_widget import BagWidget
40 
41 
42 class Bag(Plugin):
43 
44  """
45  Subclass of Plugin to provide interactive bag visualization, playing(publishing) and recording
46  """
47 
48  def __init__(self, context):
49  """
50  :param context: plugin context hook to enable adding widgets as a ROS_GUI pane, ''PluginContext''
51  """
52  super(Bag, self).__init__(context)
53  self.setObjectName('Bag')
54 
55  args = self._parse_args(context.argv())
56 
57  self._widget = BagWidget(context, args.clock)
58  if context.serial_number() > 1:
59  self._widget.setWindowTitle(
60  self._widget.windowTitle() + (' (%d)' % context.serial_number()))
61  context.add_widget(self._widget)
62 
63  def load_bags():
64  for bagfile in args.bagfiles:
65  self._widget.load_bag(bagfile)
66 
67  load_thread = threading.Thread(target=load_bags)
68  load_thread.start()
69 
70  def _parse_args(self, argv):
71  parser = argparse.ArgumentParser(prog='rqt_bag', add_help=False)
72  Bag.add_arguments(parser)
73  return parser.parse_args(argv)
74 
75  @staticmethod
76  def _isfile(parser, arg):
77  if os.path.isfile(arg):
78  return arg
79  else:
80  parser.error("Bag file %s does not exist" % (arg))
81 
82  @staticmethod
83  def add_arguments(parser):
84  group = parser.add_argument_group('Options for rqt_bag plugin')
85  group.add_argument('--clock', action='store_true', help='publish the clock time')
86  group.add_argument('bagfiles', type=lambda x: Bag._isfile(parser, x),
87  nargs='*', default=[], help='Bagfiles to load')
88 
89  def shutdown_plugin(self):
90  self._widget.shutdown_all()
91 
92  def save_settings(self, plugin_settings, instance_settings):
93  # TODO implement saving
94  # instance_settings.set_value(k, v)
95  pass
96 
97  def restore_settings(self, plugin_settings, instance_settings):
98  # TODO implement restoring
99  # v = instance_settings.value(k)
100  pass
101 
102  # def trigger_configuration(self):
103  # TODO move some of the button functionality to config button if it is "more configy"
rqt_bag.bag_widget.BagWidget
Definition: bag_widget.py:56
rqt_bag.bag.Bag.restore_settings
def restore_settings(self, plugin_settings, instance_settings)
Definition: bag.py:97
qt_gui::plugin::Plugin
rqt_bag.bag.Bag._isfile
def _isfile(parser, arg)
Definition: bag.py:76
rqt_bag.bag.Bag.save_settings
def save_settings(self, plugin_settings, instance_settings)
Definition: bag.py:92
rqt_bag.bag.Bag._widget
_widget
Definition: bag.py:57
rqt_bag.bag.Bag._parse_args
def _parse_args(self, argv)
Definition: bag.py:70
rqt_bag.bag.Bag.shutdown_plugin
def shutdown_plugin(self)
Definition: bag.py:89
rqt_bag.bag.Bag
Definition: bag.py:42
rqt_bag.bag.Bag.add_arguments
def add_arguments(parser)
Definition: bag.py:83
qt_gui::plugin
rqt_bag.bag.Bag.__init__
def __init__(self, context)
Definition: bag.py:48


rqt_bag
Author(s): Dirk Thomas , Aaron Blasdel , Austin Hendrix , Tim Field
autogenerated on Thu Mar 2 2023 03:43:15