filter_wrapper_widget.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 rospkg
35 
36 from python_qt_binding import loadUi
37 from python_qt_binding.QtGui import QIcon
38 from python_qt_binding.QtWidgets import QWidget
39 
40 
41 class FilterWrapperWidget(QWidget):
42 
43  """
44  Wraps the other filter widgets to provide enable check box, delete button control and uniform
45  labeling
46  """
47 
48  def __init__(self, widget, filter_name):
49  """
50  :param widget: the Qwidget to wrap ''Qwidget''
51  :param filter_name: the name to be placed on the label ''str''
52  """
53  super(FilterWrapperWidget, self).__init__()
54  rp = rospkg.RosPack()
55  ui_file = os.path.join(
56  rp.get_path('rqt_console'), 'resource/filters', 'filter_wrapper_widget.ui')
57  loadUi(ui_file, self)
58  self.setObjectName('FilterWrapperWidget')
59  self.delete_button.setIcon(QIcon.fromTheme('list-remove'))
60  self._widget = widget
61 
62  # Replace the placeholder QWidget with the passed in object
63  stretch = self.layout_frame.stretch(2)
64  self.layout_frame.insertWidget(2, widget)
65  self.layout_frame.setStretch(2, stretch)
66 
67  # This line sets the place holder to 0 width so it can no longer be seen
68  # It is a hack since removing it causes other widgets not to function properly
69  self.layout_frame.setStretch(3, 0)
70 
71  self.enabled_checkbox.clicked[bool].connect(self.enabled_callback)
72  self.filter_name_label.setText(filter_name + ':')
73 
74  def enabled_callback(self, checked):
75  self._widget._parentfilter.set_enabled(checked)
76  self._widget.setEnabled(checked)
77 
78  def repopulate(self):
79  self._widget.repopulate()
80 
81  def save_settings(self, settings):
82  """
83  Handles writing the enabled flag to the ini file and then passes the
84  settings object to the wrapped widget
85 
86  :param settings: used to write the settings to an ini file ''qt_gui.settings.Settings''
87  """
88  settings.set_value('enabled', self._widget._parentfilter._enabled)
89  self._widget.save_settings(settings)
90 
91  def restore_settings(self, settings):
92  """
93  Handles reading the enabled flag from the ini file.
94  :param settings: used to read the settings to an ini file ''qt_gui.settings.Settings''
95  """
96  checked = settings.value('enabled') in [True, 'true']
97  self.enabled_callback(checked)
98  self.enabled_checkbox.setChecked(checked)
99  self._widget.restore_settings(settings)


rqt_console
Author(s): Aaron Blasdel
autogenerated on Sun May 24 2020 03:23:49