psychopy#

Windows helpers for launching PsychoPy as a subprocess.

The PsychoPy stimulus lifecycle now lives on the shared SubprocessStimulusDevice engine (see mesofield.devices.psychopy_device); this module retains only the two Windows-specific helpers that the device and the GUI start gate still need:

  • get_psychopy_python_exe() – locate the standalone PsychoPy interpreter via the registry, so the stimulus script runs in PsychoPy’s own environment.

  • force_foreground() – raise a Qt widget over PsychoPy’s full-screen window so an operator keypress lands on our dialog, not the stimulus.

mesofield.devices.subprocesses.psychopy.force_foreground(widget)[source]#

Force widget to the foreground with keyboard focus.

PsychoPy runs its stimulus in a separate process whose full-screen window owns the foreground, and Windows blocks a background process from simply calling SetForegroundWindow. The reliable workaround is to momentarily attach our input thread to the current foreground window’s thread, raise our window, then detach. Without this the operator has to click the dialog by hand before a keypress reaches it. Best-effort and Windows-specific; any failure is swallowed (the dialog still works, it just may not auto-focus).

Return type:

None