checkbox_group.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2014, Andrew Wilson
00004 # Copyright (c) 2012, Dorian Scholz
00005 # All rights reserved.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions
00009 # are met:
00010 #
00011 #  * Redistributions of source code must retain the above copyright
00012 #    notice, this list of conditions and the following disclaimer.
00013 #  * Redistributions in binary form must reproduce the above
00014 #    copyright notice, this list of conditions and the following
00015 #    disclaimer in the documentation and/or other materials provided
00016 #    with the distribution.
00017 #  * Neither the name of Willow Garage, Inc. nor the names of its
00018 #    contributors may be used to endorse or promote products derived
00019 #    from this software without specific prior written permission.
00020 #
00021 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 # POSSIBILITY OF SUCH DAMAGE.
00033 
00034 from python_qt_binding.QtGui import QButtonGroup, QGroupBox, QLabel, QCheckBox, QVBoxLayout, QWidget
00035 
00036 
00037 class CheckBoxGroup(QGroupBox):
00038     """
00039     Creates a button group of non-exclusive checkbox options. 
00040 
00041     Options must be a dict with following keys: 'enabled','title','description','tooltip'
00042     """
00043 
00044     def __init__(self, options, title='Checkboxes', selected_indexes=[], parent=None):
00045         super(CheckBoxGroup, self).__init__()
00046         self.setTitle(title)
00047         self.setLayout(QVBoxLayout())
00048         self._button_group = QButtonGroup()
00049         self._button_group.setExclusive(False)
00050         self._options = options
00051         if parent == None:
00052             parent = self
00053         
00054         for (button_id, option) in enumerate(self._options):
00055 
00056             checkbox = QCheckBox(option.get('title', 'option %d' % button_id))
00057             checkbox.setEnabled(option.get('enabled', True))
00058             checkbox.setChecked(button_id in selected_indexes)
00059             checkbox.setToolTip(option.get('tooltip', ''))
00060 
00061             self._button_group.addButton(checkbox, button_id)
00062             parent.layout().addWidget(checkbox)
00063             if 'description' in option:
00064                 parent.layout().addWidget(QLabel(option['description']))
00065 
00066     def get_settings(self):
00067         """Returns dictionary with selected_indexes (array) and selected_options (array) keys."""
00068         selected_indexes = []
00069         selected_options = []
00070         for button in self._button_group.buttons():
00071             if button.isChecked():
00072                 selected_indexes.append(self._button_group.id(button))
00073                 selected_options.append(self._options[self._button_group.id(button)])
00074         return {'selected_indexes': selected_indexes, 'selected_options': selected_options}


qt_gui_py_common
Author(s): Dorian Scholz
autogenerated on Mon Oct 6 2014 03:57:55