aboutsummaryrefslogtreecommitdiffstats
path: root/gr-qtgui/grc/qtgui_time_sink_x.block.yml.py
blob: 271082dc8cb6890a61f13beb824c947509e0c0de (plain) (blame)
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#!/usr/bin/env python

import math
import re

EVERYTHING_BEFORE_PARAMS = """id: qtgui_time_sink_x
label: QT GUI Time Sink

parameters:
-   id: type
    label: Type
    dtype: enum
    default: complex
    options: [complex, float, msg_complex, msg_float]
    option_labels: [Complex, Float, Complex Message, Float Message]
    option_attributes:
        fcn: [time_sink_c, time_sink_f, time_sink_c, time_sink_f]
        t: [complex, float, message, message]
    hide: part
-   id: name
    label: Name
    dtype: string
    default: '""'
    hide: ${ ('none' if len(name) > 0 else 'part') }
-   id: ylabel
    label: Y Axis Label
    dtype: string
    default: Amplitude
    hide: part
-   id: yunit
    label: Y Axis Unit
    dtype: string
    default: '""'
    hide: part
-   id: size
    label: Number of Points
    dtype: int
    default: '1024'
    hide: ${ ('all' if type.startswith('msg') else 'none') }
-   id: srate
    label: Sample Rate
    dtype: float
    default: samp_rate
-   id: grid
    label: Grid
    dtype: enum
    default: 'False'
    options: ['True', 'False']
    option_labels: ['Yes', 'No']
    hide: part
-   id: autoscale
    label: Autoscale
    dtype: enum
    default: 'False'
    options: ['True', 'False']
    option_labels: ['Yes', 'No']
-   id: ymin
    label: Y min
    dtype: float
    default: '-1'
    hide: part
-   id: ymax
    label: Y max
    dtype: float
    default: '1'
    hide: part
-   id: nconnections
    label: Number of Inputs
    dtype: int
    default: '1'
    hide: ${ ('all' if type.startswith('msg') else 'part') }
-   id: update_time
    label: Update Period
    dtype: float
    default: '0.10'
    hide: part
-   id: entags
    label: Disp. Tags
    dtype: enum
    default: 'True'
    options: ['True', 'False']
    option_labels: ['Yes', 'No']
    hide: ${ ('all' if type.startswith('msg') else 'part') }
-   id: gui_hint
    label: GUI Hint
    dtype: gui_hint
    hide: part
-   id: tr_mode
    label: Trigger Mode
    category: Trigger
    dtype: enum
    default: qtgui.TRIG_MODE_FREE
    options: [qtgui.TRIG_MODE_FREE, qtgui.TRIG_MODE_AUTO, qtgui.TRIG_MODE_NORM, qtgui.TRIG_MODE_TAG]
    option_labels: [Free, Auto, Normal, Tag]
    hide: part
-   id: tr_slope
    label: Trigger Slope
    category: Trigger
    dtype: enum
    default: qtgui.TRIG_MODE_POS
    options: [qtgui.TRIG_SLOPE_POS, qtgui.TRIG_SLOPE_NEG]
    option_labels: [Positive, Negative]
    hide: part
-   id: tr_level
    label: Trigger Level
    category: Trigger
    dtype: float
    default: '0.0'
    hide: part
-   id: tr_delay
    label: Trigger Delay
    category: Trigger
    dtype: float
    default: '0'
    hide: part
-   id: tr_chan
    label: Trigger Channel
    category: Trigger
    dtype: int
    default: '0'
    hide: part
-   id: tr_tag
    label: Trigger Tag Key
    category: Trigger
    dtype: string
    default: '""'
    hide: part
-   id: ctrlpanel
    label: Control Panel
    category: Config
    dtype: enum
    default: 'False'
    options: ['True', 'False']
    option_labels: ['Yes', 'No']
    hide: part
-   id: legend
    label: Legend
    category: Config
    dtype: enum
    default: 'True'
    options: ['True', 'False']
    option_labels: ['Yes', 'No']
    hide: part
-   id: axislabels
    label: Axis Labels
    category: Config
    dtype: enum
    default: 'True'
    options: ['True', 'False']
    option_labels: ['Yes', 'No']
    hide: part
-   id: stemplot
    label: Stem Plot
    category: Config
    dtype: enum
    default: 'False'
    options: ['True', 'False']
    option_labels: ['Yes', 'No']
    hide: part"""

LINE_PARAMS = """
-   id: label{i}
    label: Line {i} Label
    dtype: string
    default: 'Signal {i}'
    base_key: label1
    hide: ${{ ('part' if (
            int(nconnections) >= {i}
            or (type == "complex" and int(nconnections) >= {i_cplx})
            or (type == "msg_complex")) and (not type == "msg_float")
        else 'all')
        }}
    category: Config
-   id: width{i}
    label: Line {i} Width
    default: 1
    base_key: width1
    hide: ${{ ('part' if (
            int(nconnections) >= {i}
            or (type == "complex" and int(nconnections) >= {i_cplx})
            or (type == "msg_complex")) and (not type == "msg_float")
        else 'all')
        }}
    category: Config
-   id: color{i}
    label: Line {i} Color
    dtype: enum
    options: ['blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow', 'dark red', 'dark green', 'dark blue']
    option_labels: ['Blue', 'Red', 'Green', 'Black', 'Cyan', 'Magenta', 'Yellow', 'Dark Red', 'Dark Green', 'Dark Blue']
    default: '{i_color}'
    base_key: color1
    hide: ${{ ('part' if (
            int(nconnections) >= {i}
            or (type == "complex" and int(nconnections) >= {i_cplx})
            or (type == "msg_complex")) and (not type == "msg_float")
        else 'all')
        }}
    category: Config
-   id: style{i}
    label: Line {i} Style
    dtype: enum
    options: ['1','2','3','4','5','0']
    option_labels: ['Solid','Dash','Dots','Dash-Dot','Dash-Dot-Dot']
    default: 1
    base_key: style1
    hide: ${{ ('part' if (
            int(nconnections) >= {i}
            or (type == "complex" and int(nconnections) >= {i_cplx})
            or (type == "msg_complex")) and (not type == "msg_float")
        else 'all')
        }}
    category: Config
-   id: marker{i}
    label: Line {i} Marker
    dtype: enum
    options: ['-1','0','1','2','3','4','5','6','7','8','9']
    option_labels: ['None','Circle','Rectangle','Diamond','Triangle','Down Triangle','Left Triangle','Right Triangle','Cross','X-Cross']
    default: -1
    base_key: marker1
    hide: ${{ ('part' if (
            int(nconnections) >= {i}
            or (type == "complex" and int(nconnections) >= {i_cplx})
            or (type == "msg_complex")) and (not type == "msg_float")
        else 'all')
        }}
    category: Config
-   id: alpha{i}
    label: Line {i} Alpha
    dtype: real
    default: 1.0
    base_key: alpha1
    hide: ${{ ('part' if (
            int(nconnections) >= {i}
            or (type == "complex" and int(nconnections) >= {i_cplx})
            or (type == "msg_complex")) and (not type == "msg_float")
        else 'all')
        }}
    category: Config
"""

EVERYTHING_AFTER_PARAMS = """
asserts:
- ${nconnections <= (5 if type == 'complex' else 10)}

inputs:
-   domain: stream
    dtype: ${ type.t }
    multiplicity: ${ (0 if type.startswith('msg') else nconnections) }
    optional: true

templates:
    imports: |-
        from PyQt5 import Qt
        from gnuradio import qtgui
        from gnuradio.filter import firdes
        import sip
    callbacks:
    - set_time_domain_axis(${min}, ${max})
    - set_update_time(${update_time})
    - set_y_axis(${ymin}, ${ymax})
    - set_samp_rate(${srate})
    - self.${id}.set_trigger_mode(${tr_mode}, ${tr_slope}, ${tr_level}, ${tr_delay},
        ${tr_chan}, ${tr_tag})
    make: |-
        <%
            win = 'self._%s_win'%id
        %>\\
        qtgui.${type.fcn}(
            ${size}, #size
            ${srate}, #samp_rate
            ${name}, #name
            ${0 if type.startswith('msg') else nconnections} #number of inputs
        )
        self.${id}.set_update_time(${update_time})
        self.${id}.set_y_axis(${ymin}, ${ymax})

        self.${id}.set_y_label(${ylabel}, ${yunit})

        self.${id}.enable_tags(${entags})
        self.${id}.set_trigger_mode(${tr_mode}, ${tr_slope}, ${tr_level}, ${tr_delay}, ${tr_chan}, ${tr_tag})
        self.${id}.enable_autoscale(${autoscale})
        self.${id}.enable_grid(${grid})
        self.${id}.enable_axis_labels(${axislabels})
        self.${id}.enable_control_panel(${ctrlpanel})
        self.${id}.enable_stem_plot(${stemplot})

        % if legend == "False":
        self.${id}.disable_legend()
        % endif

        labels = [${label1}, ${label2}, ${label3}, ${label4}, ${label5},
            ${label6}, ${label7}, ${label8}, ${label9}, ${label10}]
        widths = [${width1}, ${width2}, ${width3}, ${width4}, ${width5},
            ${width6}, ${width7}, ${width8}, ${width9}, ${width10}]
        colors = ['${color1}', '${color2}', '${color3}', '${color4}', '${color5}',
            '${color6}', '${color7}', '${color8}', '${color9}', '${color10}']
        alphas = [${alpha1}, ${alpha2}, ${alpha3}, ${alpha4}, ${alpha5},
            ${alpha6}, ${alpha7}, ${alpha8}, ${alpha9}, ${alpha10}]
        styles = [${style1}, ${style2}, ${style3}, ${style4}, ${style5},
            ${style6}, ${style7}, ${style8}, ${style9}, ${style10}]
        markers = [${marker1}, ${marker2}, ${marker3}, ${marker4}, ${marker5},
            ${marker6}, ${marker7}, ${marker8}, ${marker9}, ${marker10}]


        % if type.endswith('complex'):
        for i in range(${2 if type.startswith('msg') else 2*int(nconnections)}):
            if len(labels[i]) == 0:
                if (i % 2 == 0):
                    self.${id}.set_line_label(i, "Re{{Data {0}}}".format(i/2))
                else:
                    self.${id}.set_line_label(i, "Im{{Data {0}}}".format(i/2))
            else:
                self.${id}.set_line_label(i, labels[i])
            self.${id}.set_line_width(i, widths[i])
            self.${id}.set_line_color(i, colors[i])
            self.${id}.set_line_style(i, styles[i])
            self.${id}.set_line_marker(i, markers[i])
            self.${id}.set_line_alpha(i, alphas[i])
        % else:
        for i in range(${1 if type.startswith('msg') else int(nconnections)}):
            if len(labels[i]) == 0:
                self.${id}.set_line_label(i, "Data {0}".format(i))
            else:
                self.${id}.set_line_label(i, labels[i])
            self.${id}.set_line_width(i, widths[i])
            self.${id}.set_line_color(i, colors[i])
            self.${id}.set_line_style(i, styles[i])
            self.${id}.set_line_marker(i, markers[i])
            self.${id}.set_line_alpha(i, alphas[i])
        % endif

        ${win} = sip.wrapinstance(self.${id}.pyqwidget(), Qt.QWidget)
        ${gui_hint() % win}

documentation: |-
    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.

file_format: 1
"""

def make_yml():
    """Return the YML file as a string"""
    default_colors = [
        'blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow',
        'dark red', 'dark green', 'dark blue'
    ]
    line_params_1 = LINE_PARAMS.format(i=1, i_cplx=1, i_color=default_colors[0])
    line_params_1 = re.sub(r'    base_key:.*\n', '', line_params_1)
    line_params_n = ''.join([
        LINE_PARAMS.format(
            i=i,
            i_cplx=int(math.ceil(float(i)/2)),
            i_color=default_colors[(i-1) % len(default_colors)],
        )
        for i in range(2, 11)
    ])
    return ''.join((
        EVERYTHING_BEFORE_PARAMS,
        line_params_1,
        line_params_n,
        EVERYTHING_AFTER_PARAMS,
    ))


if __name__ == '__main__':
    import sys
    try:
        filename = sys.argv[1]
    except IndexError:
        filename = __file__[:-3]
    data = make_yml()
    with open(filename, 'wb') as fp:
        fp.write(data.encode())