Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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}