filter_wrapper_widget.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2012, Willow Garage, 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 import os
00034 import rospkg
00035 
00036 from python_qt_binding import loadUi
00037 from python_qt_binding.QtGui import QIcon
00038 from python_qt_binding.QtWidgets import QWidget
00039 
00040 
00041 class FilterWrapperWidget(QWidget):
00042 
00043     """
00044     Wraps the other filter widgets to provide enable check box, delete button control and uniform
00045     labeling
00046     """
00047 
00048     def __init__(self, widget, filter_name):
00049         """
00050         :param widget: the Qwidget to wrap ''Qwidget''
00051         :param filter_name: the name to be placed on the label ''str''
00052         """
00053         super(FilterWrapperWidget, self).__init__()
00054         rp = rospkg.RosPack()
00055         ui_file = os.path.join(
00056             rp.get_path('rqt_console'), 'resource/filters', 'filter_wrapper_widget.ui')
00057         loadUi(ui_file, self)
00058         self.setObjectName('FilterWrapperWidget')
00059         self.delete_button.setIcon(QIcon.fromTheme('list-remove'))
00060         self._widget = widget
00061 
00062         # Replace the placeholder QWidget with the passed in object
00063         stretch = self.layout_frame.stretch(2)
00064         self.layout_frame.insertWidget(2, widget)
00065         self.layout_frame.setStretch(2, stretch)
00066 
00067         # This line sets the place holder to 0 width so it can no longer be seen
00068         # It is a hack since removing it causes other widgets not to function properly
00069         self.layout_frame.setStretch(3, 0)
00070 
00071         self.enabled_checkbox.clicked[bool].connect(self.enabled_callback)
00072         self.filter_name_label.setText(filter_name + ':')
00073 
00074     def enabled_callback(self, checked):
00075         self._widget._parentfilter.set_enabled(checked)
00076         self._widget.setEnabled(checked)
00077 
00078     def repopulate(self):
00079         self._widget.repopulate()
00080 
00081     def save_settings(self, settings):
00082         """
00083         Handles writing the enabled flag to the ini file and then passes the
00084         settings object to the wrapped widget
00085 
00086         :param settings: used to write the settings to an ini file ''qt_gui.settings.Settings''
00087         """
00088         settings.set_value('enabled', self._widget._parentfilter._enabled)
00089         self._widget.save_settings(settings)
00090 
00091     def restore_settings(self, settings):
00092         """
00093         Handles reading the enabled flag from the ini file.
00094         :param settings: used to read the settings to an ini file ''qt_gui.settings.Settings''
00095         """
00096         checked = settings.value('enabled') in [True, 'true']
00097         self.enabled_callback(checked)
00098         self.enabled_checkbox.setChecked(checked)
00099         self._widget.restore_settings(settings)


rqt_console
Author(s): Aaron Blasdel
autogenerated on Sat Jun 8 2019 20:58:08