QT GUI Chooservariable_qtgui_chooserQT GUI Widgetsfrom PyQt4 import Qtself.$(id) = $(id) = $value#slurp
#set $all_options = [$option0, $option1, $option2, $option3, $option4][:int($num_opts())]
#set $all_labels = [$label0, $label1, $label2, $label3, $label4][:int($num_opts())]
#if not $label()
#set $label = '"%s"'%$id
#end if
########################################################################
## Create the options list
########################################################################
#if int($num_opts())
self._$(id)_options = (#slurp
#for $ch in $all_options
$ch, #slurp
#end for
)
#else
self._$(id)_options = $options
#end if
########################################################################
## Create the labels list
########################################################################
#if int($num_opts())
self._$(id)_labels = (#slurp
#for i, $lbl in enumerate($all_labels)
#if $lbl()
$lbl, #slurp
#else
str(self._$(id)_options[$i]), #slurp
#end if
#end for
)
#elif $labels()
self._$(id)_labels = $labels
#else
self._$(id)_labels = map(str, self._$(id)_options)
#end if
########################################################################
## Create the combo box
########################################################################
#if $widget() == 'combo_box'
#set $win = 'self._%s_tool_bar'%$id
$win = Qt.QToolBar(self)
$(win).addWidget(Qt.QLabel($label+": "))
self._$(id)_combo_box = Qt.QComboBox()
$(win).addWidget(self._$(id)_combo_box)
for label in self._$(id)_labels: self._$(id)_combo_box.addItem(label)
self._$(id)_callback = lambda i: self._$(id)_combo_box.setCurrentIndex(self._$(id)_options.index(i))
self._$(id)_callback(self.$id)
self._$(id)_combo_box.currentIndexChanged.connect(
lambda i: self.set_$(id)(self._$(id)_options[i]))
#end if
########################################################################
## Create the radio buttons
########################################################################
#if $widget() == 'radio_buttons'
#set $win = 'self._%s_group_box'%$id
$win = Qt.QGroupBox($label)
self._$(id)_box = $(orient)()
self._$(id)_button_group = Qt.QButtonGroup()
$(win).setLayout(self._$(id)_box)
for i, label in enumerate(self._$(id)_labels):
radio_button = Qt.QRadioButton(label)
self._$(id)_box.addWidget(radio_button)
self._$(id)_button_group.addButton(radio_button, i)
self._$(id)_callback = lambda i: self._$(id)_button_group.button(self._$(id)_options.index(i)).setChecked(True)
self._$(id)_callback(self.$id)
self._$(id)_button_group.buttonClicked[int].connect(
lambda i: self.set_$(id)(self._$(id)_options[i]))
#end if
$(gui_hint()($win))self.set_$(id)($value)self._$(id)_callback($id)Labellabelstring#if $label() then 'none' else 'part'#TypetypeintenumpartNum Optionsnum_opts3enumDefault Valuevalue0$typeOptionsoptions[0, 1, 2]raw#if int($num_opts()) then 'all' else 'none'#Labelslabels[]raw#if int($num_opts()) then 'all' else 'none'#Option 0option00$type#if int($num_opts()) > 0 then 'none' else 'all'#Label 0label0string$((int($num_opts()) > 0) and ($label0() and 'none' or 'part') or 'all')Option 1option11$type#if int($num_opts()) > 1 then 'none' else 'all'#Label 1label1string$((int($num_opts()) > 1) and ($label1() and 'none' or 'part') or 'all')Option 2option22$type#if int($num_opts()) > 2 then 'none' else 'all'#Label 2label2string$((int($num_opts()) > 2) and ($label2() and 'none' or 'part') or 'all')Option 3option33$type#if int($num_opts()) > 3 then 'none' else 'all'#Label 3label3string$((int($num_opts()) > 3) and ($label3() and 'none' or 'part') or 'all')Option 4option44$type#if int($num_opts()) > 4 then 'none' else 'all'#Label 4label4string$((int($num_opts()) > 4) and ($label4() and 'none' or 'part') or 'all')Widgetwidgetcombo_boxenumpartOrientationorientQt.QVBoxLayoutenum#if $widget() == 'radio_buttons' then 'part' else 'all'#GUI Hintgui_hintgui_hintpart
This block creates a variable with enumerated options. \
The gui widget is implemented as a combo box or radio button group. \
Leave the label blank to use the variable id as the label.
Choose the number of options available to your chooser. \
When the label is left blank, the option will be used as the label. \
Set the number of options to "list" to enter a single list of options and labels. \
When the labels is an empty list, the options will be used as the label.
The GUI hint can be used to position the widget within the application. \
The hint is of the form [tab_id@tab_index]: [row, col, row_span, col_span]. \
Both the tab specification and the grid position are optional.