QT GUI Chooser variable_qtgui_chooser QT GUI Widgets from PyQt4 import Qt self.$(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 $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 $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+" ", None)) self._$(id)_combo_box = Qt.QComboBox(None) $(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) Label label string #if $label() then 'none' else 'part'# Type type int enum part Num Options num_opts 3 enum Default Value value 0 $type Options options [0, 1, 2] raw #if int($num_opts()) then 'all' else 'none'# Labels labels [] raw #if int($num_opts()) then 'all' else 'none'# Option 0 option0 0 $type #if int($num_opts()) > 0 then 'none' else 'all'# Label 0 label0 string $((int($num_opts()) > 0) and ($label0() and 'none' or 'part') or 'all') Option 1 option1 1 $type #if int($num_opts()) > 1 then 'none' else 'all'# Label 1 label1 string $((int($num_opts()) > 1) and ($label1() and 'none' or 'part') or 'all') Option 2 option2 2 $type #if int($num_opts()) > 2 then 'none' else 'all'# Label 2 label2 string $((int($num_opts()) > 2) and ($label2() and 'none' or 'part') or 'all') Option 3 option3 3 $type #if int($num_opts()) > 3 then 'none' else 'all'# Label 3 label3 string $((int($num_opts()) > 3) and ($label3() and 'none' or 'part') or 'all') Option 4 option4 4 $type #if int($num_opts()) > 4 then 'none' else 'all'# Label 4 label4 string $((int($num_opts()) > 4) and ($label4() and 'none' or 'part') or 'all') Widget widget combo_box enum part Orientation orient Qt.QVBoxLayout enum #if $widget() == 'radio_buttons' then 'part' else 'all'# GUI Hint gui_hint gui_hint part 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.