print"Can't configure QSplitter using object of type",type(s)
ifw.count()>0:## make sure at least one item is not collapsed
foriinw.sizes():
ifi>0:
return
w.setSizes([50]*w.count())
defcomboState(w):
ind=w.currentIndex()
data=w.itemData(ind)
#if not data.isValid():
ifdataisnotNone:
try:
ifnotdata.isValid():
data=None
else:
data=data.toInt()[0]
exceptAttributeError:
pass
ifdataisNone:
returnunicode(w.itemText(ind))
else:
returndata
defsetComboState(w,v):
iftype(v)isint:
#ind = w.findData(QtCore.QVariant(v))
ind=w.findData(v)
ifind>-1:
w.setCurrentIndex(ind)
return
w.setCurrentIndex(w.findText(str(v)))
classWidgetGroup(QtCore.QObject):
"""This class takes a list of widgets and keeps an internal record of their state which is always up to date. Allows reading and writing from groups of widgets simultaneously."""
## List of widget types which can be handled by WidgetGroup.
## The value for each type is a tuple (change signal function, get function, set function, [auto-add children])
## The change signal function that takes an object and returns a signal that is emitted any time the state of the widget changes, not just
## when it is changed by user interaction. (for example, 'clicked' is not a valid signal here)
## If the change signal is None, the value of the widget is not cached.
## Custom widgets not in this list can be made to work with WidgetGroup by giving them a 'widgetGroupInterface' method
## which returns the tuple.
classes={
QtGui.QSpinBox:
(lambdaw:w.valueChanged,
QtGui.QSpinBox.value,
QtGui.QSpinBox.setValue),
QtGui.QDoubleSpinBox:
(lambdaw:w.valueChanged,
QtGui.QDoubleSpinBox.value,
QtGui.QDoubleSpinBox.setValue),
QtGui.QSplitter:
(None,
splitterState,
restoreSplitter,
True),
QtGui.QCheckBox:
(lambdaw:w.stateChanged,
QtGui.QCheckBox.isChecked,
QtGui.QCheckBox.setChecked),
QtGui.QComboBox:
(lambdaw:w.currentIndexChanged,
comboState,
setComboState),
QtGui.QGroupBox:
(lambdaw:w.toggled,
QtGui.QGroupBox.isChecked,
QtGui.QGroupBox.setChecked,
True),
QtGui.QLineEdit:
(lambdaw:w.editingFinished,
lambdaw:str(w.text()),
QtGui.QLineEdit.setText),
QtGui.QRadioButton:
(lambdaw:w.toggled,
QtGui.QRadioButton.isChecked,
QtGui.QRadioButton.setChecked),
QtGui.QSlider:
(lambdaw:w.valueChanged,
QtGui.QSlider.value,
QtGui.QSlider.setValue),
}
sigChanged=QtCore.Signal(str,object)
def__init__(self,widgetList=None):
"""Initialize WidgetGroup, adding specified widgets into this group.