24 from PyQt5
import QtCore, QtWidgets
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 QtWidgets.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)
55 """Updates the ComboOptionsWidget and the active widget of the show area.
57 This method calls the Update method of the active widget.
62 """Adds a Widget to this Options Widget.
64 The Widget must have a identifier. If another Widget has the same identifier,
65 the old widget will be removed and the new widget gets the identifier.
66 Returns True, if widget is added. Otherwise it returns False
68 if isinstance(widget, QtWidgets.QWidget)
and ident
is not None:
69 if hasattr(widget,
"GetText"):
70 string = widget.GetText()
75 self.stacked_widget_.addWidget(widget)
77 self.combo_box_.addItem(string, QtCore.QVariant(qpair))
84 self.stacked_widget_.removeWidget(self.combo_box_.itemData(index)[1])
85 self.combo_box_.removeItem(index)
88 """This abstract method is called whenever the View is updated.
90 This abstract method must be implemented by all subclasses.
91 It can be used to do something ;-) whenever the combobox changes its value.
93 raise NotImplementedError,
"Subclasses must define OnComboChange()"
100 Change Current Selected Item.
102 Shows the widget which corresponds to the ident in the show area. If ident
103 is not valid, nothing happens.
106 if(i>=0)
and self.combo_box_.currentIndex() != i:
107 self.combo_box_.setCurrentIndex(i)
108 if (self.combo_box_.count() > 0):
110 self.stacked_widget_.setCurrentWidget(pair[1])
114 if(self.combo_box_.currentIndex() >= 0):
122 if(hasattr(item,
"minimumHeight")):
123 height=item.minimumHeight()
124 if(hasattr(item,
"minimumWidth")):
125 width=item.minimumWidth()
126 self.setMinimumSize(width,40+height)
127 if(hasattr(self.
parent_,
"DoResize")):
128 self.parent_.DoResize()
131 def __UpdateView(self, item):
132 if (self.combo_box_.count() > 0):
134 self.stacked_widget_.setCurrentWidget(pair[1])
137 def __GetIndex(self, ident):
138 for i
in range(self.combo_box_.count()):
139 pair = self.combo_box_.itemData(i)
144 def __GetCurrentPair(self):
145 current_index = self.combo_box_.currentIndex()
146 return self.combo_box_.itemData(current_index)
150 QtWidgets.QWidget.setEnabled(self, bool)
151 for i
in range(self.combo_box_.count()):
152 pair = self.combo_box_.itemData(i)