respyra.core.display

PsychoPy window creation, stimulus helpers, and real-time waveform rendering.

Provides thin wrappers around PsychoPy’s visual and monitors modules that enforce project defaults ('height' units, black background, pre-created stimuli). Also contains SignalTrace, a pre-allocated ShapeStim for rendering scrolling waveforms without per-frame allocations, and draw_signal_trace(), a convenience wrapper with automatic caching.

respyra.core.display.create_monitor(name, width_cm, distance_cm, size_pix)[source]

Create, configure, and save a PsychoPy monitor profile.

Parameters:
  • name (str) – Profile name stored by PsychoPy’s monitor center.

  • width_cm (float) – Viewable width of the display in centimeters.

  • distance_cm (float) – Viewing distance from the participant’s eyes to the screen in cm.

  • size_pix (tuple of (int, int)) – Screen resolution as (width, height) in pixels.

Return type:

monitors.Monitor

respyra.core.display.create_window(fullscr=False, monitor=None, units='height', color=(-1, -1, -1), **kwargs)[source]

Create a PsychoPy window with sensible project defaults.

Parameters:
  • fullscr (bool) – Full-screen mode. Use False during development, True for data collection (enables VSync).

  • monitor (str or monitors.Monitor or None) – Monitor profile. A string is looked up by name; a Monitor object is used directly; None falls back to PsychoPy’s default.

  • units (str) – Coordinate system. ‘height’ works without calibration and keeps aspect-ratio-independent sizing.

  • color (tuple) – Background color in PsychoPy RGB (-1 to 1). Default is black.

  • **kwargs – Forwarded to visual.Window (e.g. screen, size, allowGUI, waitBlanking).

Return type:

visual.Window

respyra.core.display.show_text_and_wait(win, text, key_list=None, color='white')[source]

Draw a text screen and block until the participant presses a key.

Parameters:
  • win (visual.Window)

  • text (str) – Message to display (supports newlines).

  • key_list (list of str or None) – Acceptable keys. Defaults to ['space'].

  • color (str or tuple) – Text color.

Returns:

The key that was pressed.

Return type:

str

class respyra.core.display.SignalTrace(win, trace_rect=(-0.8, -0.3, 0.8, 0.3), y_range=(0, 50), color='green', line_width=2.0)[source]

Bases: object

Pre-created ShapeStim that renders a scrolling waveform.

Create once before your frame loop, then call draw() each frame with the latest data. This avoids re-creating stimulus objects inside the render loop.

Parameters:
  • win (visual.Window)

  • trace_rect (tuple of (left, bottom, right, top)) – Bounding box in window units for the waveform area.

  • y_range (tuple of (float, float)) – Expected (min, max) of the data values. Used to scale the trace vertically within trace_rect.

  • color (str or tuple) – Line color.

  • line_width (float) – Line width in pixels.

draw(data_points)[source]

Update vertices from data_points and draw to the back buffer.

Parameters:

data_points (list of float) – Force (or other signal) values. Mapped left-to-right across the trace rectangle, with y scaled to y_range.

respyra.core.display.draw_signal_trace(win, data_points, y_range=(0, 50), trace_rect=(-0.8, -0.3, 0.8, 0.3), color='green')[source]

Convenience function: draw a signal trace on win this frame.

Internally caches a SignalTrace per window so the ShapeStim is created only once — safe to call every frame without allocations.

Parameters:
  • win (visual.Window)

  • data_points (list of float) – Signal values to plot.

  • y_range (tuple of (float, float)) – Data range for vertical scaling.

  • trace_rect (tuple of (left, bottom, right, top)) – Bounding box in window units.

  • color (str or tuple) – Line color.