1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
<?xml version="1.0"?>
<!--
###################################################
##Variable Chooser:
## A chooser, radio buttons
###################################################
-->
<block>
<name>QT GUI Chooser</name>
<key>variable_qtgui_chooser</key>
<category>QT GUI Widgets</category>
<import>from PyQt4 import Qt</import>
<var_make>self.$(id) = $(id) = $value</var_make>
<make>#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))</make>
<callback>self.set_$(id)($value)</callback>
<callback>self._$(id)_callback($id)</callback>
<param>
<name>Label</name>
<key>label</key>
<value></value>
<type>string</type>
<hide>#if $label() then 'none' else 'part'#</hide>
</param>
<param>
<name>Type</name>
<key>type</key>
<value>int</value>
<type>enum</type>
<hide>part</hide>
<option><name>Float</name><key>real</key></option>
<option><name>Integer</name><key>int</key></option>
<option><name>String</name><key>string</key></option>
<option><name>Any</name><key>raw</key></option>
</param>
<param>
<name>Num Options</name>
<key>num_opts</key>
<value>3</value>
<type>enum</type>
<option><name>List</name><key>0</key></option>
<option><name>1</name><key>1</key></option>
<option><name>2</name><key>2</key></option>
<option><name>3</name><key>3</key></option>
<option><name>4</name><key>4</key></option>
<option><name>5</name><key>5</key></option>
</param>
<param>
<name>Default Value</name>
<key>value</key>
<value>0</value>
<type>$type</type>
</param>
<param>
<name>Options</name>
<key>options</key>
<value>[0, 1, 2]</value>
<type>raw</type>
<hide>#if int($num_opts()) then 'all' else 'none'#</hide>
</param>
<param>
<name>Labels</name>
<key>labels</key>
<value>[]</value>
<type>raw</type>
<hide>#if int($num_opts()) then 'all' else 'none'#</hide>
</param>
<param>
<name>Option 0</name>
<key>option0</key>
<value>0</value>
<type>$type</type>
<hide>#if int($num_opts()) > 0 then 'none' else 'all'#</hide>
</param>
<param>
<name>Label 0</name>
<key>label0</key>
<value></value>
<type>string</type>
<hide>$((int($num_opts()) > 0) and ($label0() and 'none' or 'part') or 'all')</hide>
</param>
<param>
<name>Option 1</name>
<key>option1</key>
<value>1</value>
<type>$type</type>
<hide>#if int($num_opts()) > 1 then 'none' else 'all'#</hide>
</param>
<param>
<name>Label 1</name>
<key>label1</key>
<value></value>
<type>string</type>
<hide>$((int($num_opts()) > 1) and ($label1() and 'none' or 'part') or 'all')</hide>
</param>
<param>
<name>Option 2</name>
<key>option2</key>
<value>2</value>
<type>$type</type>
<hide>#if int($num_opts()) > 2 then 'none' else 'all'#</hide>
</param>
<param>
<name>Label 2</name>
<key>label2</key>
<value></value>
<type>string</type>
<hide>$((int($num_opts()) > 2) and ($label2() and 'none' or 'part') or 'all')</hide>
</param>
<param>
<name>Option 3</name>
<key>option3</key>
<value>3</value>
<type>$type</type>
<hide>#if int($num_opts()) > 3 then 'none' else 'all'#</hide>
</param>
<param>
<name>Label 3</name>
<key>label3</key>
<value></value>
<type>string</type>
<hide>$((int($num_opts()) > 3) and ($label3() and 'none' or 'part') or 'all')</hide>
</param>
<param>
<name>Option 4</name>
<key>option4</key>
<value>4</value>
<type>$type</type>
<hide>#if int($num_opts()) > 4 then 'none' else 'all'#</hide>
</param>
<param>
<name>Label 4</name>
<key>label4</key>
<value></value>
<type>string</type>
<hide>$((int($num_opts()) > 4) and ($label4() and 'none' or 'part') or 'all')</hide>
</param>
<param>
<name>Widget</name>
<key>widget</key>
<value>combo_box</value>
<type>enum</type>
<hide>part</hide>
<option><name>Combo Box</name><key>combo_box</key></option>
<option><name>Radio Buttons</name><key>radio_buttons</key></option>
</param>
<param>
<name>Orientation</name>
<key>orient</key>
<value>Qt.QVBoxLayout</value>
<type>enum</type>
<hide>#if $widget() == 'radio_buttons' then 'part' else 'all'#</hide>
<option>
<name>Horizontal</name>
<key>Qt.QHBoxLayout</key>
</option>
<option>
<name>Vertical</name>
<key>Qt.QVBoxLayout</key>
</option>
</param>
<param>
<name>GUI Hint</name>
<key>gui_hint</key>
<value></value>
<type>gui_hint</type>
<hide>part</hide>
</param>
<doc>
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.
</doc>
</block>
|