Episode 8: The Main Window

Give the MainApp a caption, a grid, a theme, and arrange three widgets in it.

Every episode so far built gp.MainApp() with its defaults: a window called g.Pype Application, one widget filling it, the dark theme, and the screen kept awake. All four are parameters.

The window

caption is the title bar’s text and the process’s name on the taskbar. grid_size is rows and columns for the widgets. theme is "dark" or "system", which follows the operating system’s light or dark setting. prevent_sleep keeps the computer from sleeping while the window is open, which a recording session wants and a demo does not.

 7    # A caption for the title bar, a 2 x 2 grid for the widgets, the
 8    # system's light or dark theme, and the screen allowed to sleep
 9    app = gp.MainApp(caption="Alpha Monitor", grid_size=[2, 2],
10                     theme="system", prevent_sleep=False)
11    p = gp.Pipeline()
Three views of one signal

One generator, its alpha band, and its spectrum, each into a widget of its own: two TimeSeriesScope and a SpectrumScope.

13    source = gp.Generator(signal_amplitude=10, noise_amplitude=5)
14    alpha = gp.Bandpass(f_lo=8, f_hi=12)
15    fft = gp.FFT(window_size=250)
16
17    raw = gp.TimeSeriesScope(amplitude_limit=30)
18    filtered = gp.TimeSeriesScope(amplitude_limit=30)
19    spectrum = gp.SpectrumScope(amplitude_limit=20)
20
21    p.connect(source, raw)
22    p.connect(source, alpha)
23    p.connect(alpha, filtered)
24    p.connect(source, fft)
25    p.connect(fft, spectrum)
Place them on the grid

add_widget takes grid_positions, counted from 1 row by row, as in a 2 x 2 table: the raw scope spans positions 1 and 2, the whole top row; the other two take 3 and 4. A widget added without positions takes the next free cell.

27    # Grid positions count from 1, row by row: the raw scope takes the
28    # whole top row, the other two share the bottom one
29    app.add_widget(raw, grid_positions=[1, 2])
30    app.add_widget(filtered, grid_positions=[3])
31    app.add_widget(spectrum, grid_positions=[4])
Result

Run the script. The window is called Alpha Monitor, follows your system’s theme, and shows the raw signal across the top with the alpha band and the spectrum side by side below.

S2E8 example screenshot

Figure 29: A 2 x 2 grid: one widget across the top row, two below.

Summary

In this episode, you learned how to:

  • name the window and pick its theme

  • lay widgets out on a grid with grid_size and grid_positions

  • decide whether the screen may sleep

Proceed to Episode 9, where a ChannelLabeler gives channels their names.

Nodes in this episode: Generator, Bandpass, FFT, TimeSeriesScope, SpectrumScope

File s2e8_main_window.py – View file on GitHub

 1"""Season 2, Episode 8: the main window's caption, grid, theme and sleep."""
 2
 3import gpype as gp
 4
 5if __name__ == "__main__":
 6
 7    # A caption for the title bar, a 2 x 2 grid for the widgets, the
 8    # system's light or dark theme, and the screen allowed to sleep
 9    app = gp.MainApp(caption="Alpha Monitor", grid_size=[2, 2],
10                     theme="system", prevent_sleep=False)
11    p = gp.Pipeline()
12
13    source = gp.Generator(signal_amplitude=10, noise_amplitude=5)
14    alpha = gp.Bandpass(f_lo=8, f_hi=12)
15    fft = gp.FFT(window_size=250)
16
17    raw = gp.TimeSeriesScope(amplitude_limit=30)
18    filtered = gp.TimeSeriesScope(amplitude_limit=30)
19    spectrum = gp.SpectrumScope(amplitude_limit=20)
20
21    p.connect(source, raw)
22    p.connect(source, alpha)
23    p.connect(alpha, filtered)
24    p.connect(source, fft)
25    p.connect(fft, spectrum)
26
27    # Grid positions count from 1, row by row: the raw scope takes the
28    # whole top row, the other two share the bottom one
29    app.add_widget(raw, grid_positions=[1, 2])
30    app.add_widget(filtered, grid_positions=[3])
31    app.add_widget(spectrum, grid_positions=[4])
32
33    p.start()
34    app.run()
35    p.stop()
36    p.close()