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)
def __init__(self, title='Options', description=None)


qt_gui_py_common
Author(s): Dorian Scholz
autogenerated on Tue Apr 13 2021 03:03:15