simple_settings_dialog.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2012, Dorian Scholz
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 
35 from python_qt_binding import loadUi
36 from python_qt_binding.QtCore import qWarning
37 from python_qt_binding.QtWidgets import QDialog, QLabel
38 from rospkg.rospack import RosPack
39 
40 from .checkbox_group import CheckBoxGroup
41 from .exclusive_options_group import ExclusiveOptionGroup
42 
43 
44 class SimpleSettingsDialog(QDialog):
45  """Simple dialog that can show multiple settings groups and returns their combined results."""
46 
47  def __init__(self, title='Options', description=None):
48  super(SimpleSettingsDialog, self).__init__()
49  self.setObjectName('SimpleSettingsDialog')
50 
51  rp = RosPack()
52  ui_file = os.path.join(
53  rp.get_path('qt_gui_py_common'), 'resource', 'simple_settings_dialog.ui')
54  loadUi(ui_file, self)
55 
56  self.setWindowTitle(title)
57  self._settings_groups = []
58 
59  if description is not None:
60  self.add_label(description)
61 
62  def add_label(self, text):
63  self.group_area.layout().addWidget(QLabel(text))
64 
65  def add_exclusive_option_group(self, *args, **kwargs):
66  """Add an ExclusiveOptionGroup."""
67  self.add_settings_group(ExclusiveOptionGroup(*args, **kwargs))
68 
69  def add_checkbox_group(self, *args, **kwargs):
70  """Add a CheckBoxGroup."""
71  self.add_settings_group(CheckBoxGroup(*args, **kwargs))
72 
73  def add_settings_group(self, settings_group):
74  """Add a settings group, which is any widget with a get_settings method."""
75  if not hasattr(settings_group, 'get_settings'):
76  qWarning(
77  'add_settings_group(): this settings group has no get_settings method to collect the settings!')
78  self._settings_groups.append(settings_group)
79  self.group_area.layout().addWidget(settings_group)
80 
81  def get_settings(self):
82  """Return the combined settings from all settings groups as a list."""
83  if self.exec_() == QDialog.Accepted:
84  results = []
85  for settings_group in self._settings_groups:
86  if hasattr(settings_group, 'get_settings'):
87  results.append(settings_group.get_settings())
88  else:
89  results.append(None)
90  return results
91  return [None] * len(self._settings_groups)
qt_gui_py_common.exclusive_options_group.ExclusiveOptionGroup
Definition: exclusive_options_group.py:37
qt_gui_py_common.simple_settings_dialog.SimpleSettingsDialog._settings_groups
_settings_groups
Definition: simple_settings_dialog.py:57
qt_gui_py_common.simple_settings_dialog.SimpleSettingsDialog
Definition: simple_settings_dialog.py:44
qt_gui_py_common.simple_settings_dialog.SimpleSettingsDialog.add_label
def add_label(self, text)
Definition: simple_settings_dialog.py:62
qt_gui_py_common.checkbox_group.CheckBoxGroup
Definition: checkbox_group.py:38
qt_gui_py_common.simple_settings_dialog.SimpleSettingsDialog.add_settings_group
def add_settings_group(self, settings_group)
Definition: simple_settings_dialog.py:73
qt_gui_py_common.simple_settings_dialog.SimpleSettingsDialog.__init__
def __init__(self, title='Options', description=None)
Definition: simple_settings_dialog.py:47
qt_gui_py_common.simple_settings_dialog.SimpleSettingsDialog.add_exclusive_option_group
def add_exclusive_option_group(self, *args, **kwargs)
Definition: simple_settings_dialog.py:65
qt_gui_py_common.simple_settings_dialog.SimpleSettingsDialog.get_settings
def get_settings(self)
Definition: simple_settings_dialog.py:81
qt_gui_py_common.simple_settings_dialog.SimpleSettingsDialog.add_checkbox_group
def add_checkbox_group(self, *args, **kwargs)
Definition: simple_settings_dialog.py:69


qt_gui_py_common
Author(s): Dorian Scholz
autogenerated on Sat Jun 25 2022 02:15:08