plugin_container_widget.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2013, Open Source Robotics Foundation Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Willow Garage, Inc. nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
00032 #
00033 # Author: Isaac Saito
00034 
00035 from __future__ import division
00036 
00037 import os
00038 
00039 from python_qt_binding import loadUi
00040 from python_qt_binding.QtGui import QWidget
00041 import rospkg
00042 import rospy
00043 
00044 
00045 class PluginContainerWidget(QWidget):
00046     """
00047     This widget accommodates a plugin widget that needs an area to show system
00048     message. A plugin widget is the pane that provides plugin's main
00049     functionalities. PluginContainerWidget visually encapsulates a plugin
00050     widget.
00051 
00052     In order to print msg in the msg pane provided by this class, plugin widget
00053     MUST define and emit following signals:
00054 
00055     - sig_sysmsg
00056     - sig_progress
00057 
00058     Having said that this architecture is based on signals, it is recommended
00059     that exceptions raised in classes that are used in a plugin widget be
00060     aggregated in it, so that only plugin widget is responsible for emitting
00061     signals.
00062     """
00063 
00064     def __init__(self, plugin_widget,
00065                  on_sys_msg=True, on_sysprogress_bar=True):
00066         """
00067         @param plugin_widget: The main widget of an rqt plugin.
00068         @type plugin_widget: QWidget
00069         @type on_sys_msg: bool
00070         @param on_sys_msg: If True, a pane that accommodates str messages will
00071                            appear in the plugin's region.
00072         @param on_sysprogress_bar: If True, a progress bar will appear in the
00073                                    plugin's region.
00074         """
00075         super(PluginContainerWidget, self).__init__()
00076 
00077         ui_file = os.path.join(rospkg.RosPack().get_path('rqt_py_common'),
00078                                'resource', 'plugin_container.ui')
00079         loadUi(ui_file, self)
00080 
00081         self._plugin_widget = plugin_widget
00082         self._splitter.insertWidget(0, self._plugin_widget)
00083         self.setWindowTitle(self._plugin_widget.windowTitle())
00084 
00085         # Default is on for these sys status widgets. Only if the flag for them
00086         # are 'False', hide them.
00087         if on_sys_msg:
00088             self._plugin_widget.sig_sysmsg.connect(self.set_sysmsg)
00089         else:
00090             self._sysmsg_widget.hide()
00091 
00092         if on_sysprogress_bar:
00093             self._plugin_widget.sig_sysprogress.connect(self.set_sysprogress)
00094         else:
00095             self._sysprogress_bar.hide()
00096 
00097     def set_sysprogress(self, sysprogress):
00098         #TODO: Pass progress value
00099         pass
00100 
00101     def set_sysmsg(self, sysmsg):
00102         """
00103         Set system msg that's supposed to be shown in sys msg pane.
00104         @type sysmsg: str
00105         """
00106         rospy.loginfo('PluginContainerWidget; {}'.format(sysmsg))
00107         #self._sysmsg_widget.setPlainText(sysmsg)
00108         self._sysmsg_widget.append(sysmsg)
00109 
00110     def shutdown(self):
00111 
00112         #TODO: Is shutdown step necessary for PluginContainerWidget?
00113 
00114         self._plugin_widget.shutdown()
00115 
00116     def save_settings(self, plugin_settings, instance_settings):
00117 
00118         #Save setting of PluginContainerWidget.
00119         instance_settings.set_value('_splitter', self._splitter.saveState())
00120 
00121         #Save setting of ContainED widget
00122         self._plugin_widget.save_settings(plugin_settings, instance_settings)
00123 
00124     def restore_settings(self, plugin_settings, instance_settings):
00125 
00126         # Restore the setting of PluginContainerWidget, separate from
00127         # ContainED widget.
00128         if instance_settings.contains('_splitter'):
00129             self._splitter.restoreState(instance_settings.value('_splitter'))
00130         else:
00131             self._splitter.setSizes([100, 100, 200])
00132 
00133         # Now restore the setting of ContainED widget
00134         self._plugin_widget.restore_settings(plugin_settings,
00135                                              instance_settings)


rqt_py_common
Author(s): Dorian Scholz, Isaac Saito
autogenerated on Wed Sep 16 2015 06:58:00