24 from PyQt4
import QtCore, QtGui
27 """QWidget with a Combobox and a show area.
29 This abstract QWidget has a Combobox and a show area. Whenever the value of
30 the Combobox changes, the Widget corresponding to the Combobox's value is
31 shown in the show area.
34 QtGui.QWidget.__init__(self, parent)
38 self.grid_layout_.setHorizontalSpacing(0)
39 self.grid_layout_.setVerticalSpacing(0)
40 self.grid_layout_.setContentsMargins(0,0,0,0)
42 self.grid_layout_.addWidget(self.
combo_box_, 0, 0, 1, 1)
48 QtCore.QObject.connect(self.
combo_box_, QtCore.SIGNAL(
"activated(int)"),
56 """Updates the ComboOptionsWidget and the active widget of the show area.
58 This method calls the Update method of the active widget.
63 """Adds a Widget to this Options Widget.
65 The Widget must have a identifier. If another Widget has the same identifier,
66 the old widget will be removed and the new widget gets the identifier.
67 Returns True, if widget is added. Otherwise it returns False
69 if isinstance(widget, QtGui.QWidget)
and ident
is not None:
70 if hasattr(widget,
"GetText"):
71 string = QtCore.QString(widget.GetText())
73 string = QtCore.QString(ident)
76 self.stacked_widget_.addWidget(widget)
78 self.combo_box_.addItem(string, QtCore.QVariant(qpair))
85 self.stacked_widget_.removeWidget(self.combo_box_.itemData(index).toPyObject()[1])
86 self.combo_box_.removeItem(index)
89 """This abstract method is called whenever the View is updated.
91 This abstract method must be implemented by all subclasses.
92 It can be used to do something ;-) whenever the combobox changes its value.
94 raise NotImplementedError,
"Subclasses must define OnComboChange()"
101 Change Current Selected Item.
103 Shows the widget which corresponds to the ident in the show area. If ident
104 is not valid, nothing happens.
107 if(i>=0)
and self.combo_box_.currentIndex() != i:
108 self.combo_box_.setCurrentIndex(i)
109 if (self.combo_box_.count() > 0):
111 self.stacked_widget_.setCurrentWidget(pair[1])
115 if(self.combo_box_.currentIndex() >= 0):
123 if(hasattr(item,
"minimumHeight")):
124 height=item.minimumHeight()
125 if(hasattr(item,
"minimumWidth")):
126 width=item.minimumWidth()
127 self.setMinimumSize(width,40+height)
128 if(hasattr(self.
parent_,
"DoResize")):
129 self.parent_.DoResize()
132 def __UpdateView(self, item):
133 if (self.combo_box_.count() > 0):
135 self.stacked_widget_.setCurrentWidget(pair[1])
138 def __GetIndex(self, ident):
139 for i
in range(self.combo_box_.count()):
140 pair = self.combo_box_.itemData(i).toPyObject()
145 def __GetCurrentPair(self):
146 current_index = self.combo_box_.currentIndex()
147 return self.combo_box_.itemData(current_index).toPyObject()
151 QtGui.QWidget.setEnabled(self, bool)
152 for i
in range(self.combo_box_.count()):
153 pair = self.combo_box_.itemData(i).toPyObject()