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 from python_qt_binding.QtGui import QButtonGroup, QGroupBox, QLabel, QRadioButton, QVBoxLayout, QWidget
00034
00035
00036 class ExclusiveOptionGroup(QGroupBox):
00037 """
00038 Creates a button group of exclusive radio options.
00039
00040 Options must be a dict with following keys: 'enabled','selected','title','description','tooltip'
00041 """
00042
00043 def __init__(self, options, title='Exclusive Options', selected_index=None, parent=None):
00044 super(ExclusiveOptionGroup, self).__init__()
00045 self.setTitle(title)
00046 self.setLayout(QVBoxLayout())
00047 self._button_group = QButtonGroup()
00048 self._button_group.setExclusive(True)
00049 self._options = options
00050 if parent == None:
00051 parent = self
00052
00053 for (button_id, option) in enumerate(self._options):
00054
00055 radio_button = QRadioButton(option.get('title', 'option %d' % button_id))
00056 radio_button.setEnabled(option.get('enabled', True))
00057 radio_button.setChecked(option.get('selected', False) or button_id == selected_index)
00058 radio_button.setToolTip(option.get('tooltip', ''))
00059
00060 self._button_group.addButton(radio_button, button_id)
00061 parent.layout().addWidget(radio_button)
00062 if 'description' in option:
00063 parent.layout().addWidget(QLabel(option['description']))
00064
00065 def get_settings(self):
00066 """Returns dictionary with selected_index (int) and selected_option (dict) keys."""
00067 selected_index = self._button_group.checkedId()
00068 if selected_index >= 0:
00069 return {'selected_index': selected_index, 'selected_option': self._options[selected_index]}
00070 return {'selected_index': None, 'selected_option': None}