Skip to main content

A package for OpenGL drawing using Pygame.

Project description

TachyPy

Docs Status

TachyPy is a psychophysics engine for Python focused on precise visual timing with OpenGL rendering, dual display/input backends, and experiment-friendly stimulus helpers.

Highlights

  • OpenGL stimulus rendering (Texture, Shapes, fixation, etc.).
  • Two window/input backends via Screen: pygame (default) and glfw.
  • Backend-aware input handling through ResponseHandler.
  • Multiple text paths:
    • Text (pygame-font first, Pillow fallback),
    • GLText (OpenGL bitmap glyphs),
    • GLTextSDF (distance-field text),
    • GLSystemText (system fonts via FreeType + HarfBuzz).
  • Psychophysics helpers (make_gabor, gratings, normalization, dithering).
  • Audio playback utility (Audio) with backend abstraction (sounddevice or dummy).
  • Test suite for core logic and regressions.

Installation

Install base package:

pip install tachypy

Editable install for development:

git clone https://github.com/Charestlab/tachypy.git
cd tachypy
pip install -e .

Optional extras:

pip install -e ".[test]"        # pytest
pip install -e ".[glfw]"        # GLFW backend
pip install -e ".[text]"        # Pillow text fallback
pip install -e ".[system_text]" # FreeType + HarfBuzz system-font text
pip install -e ".[audio_sd]"    # sounddevice backend

Quick Start

import os
from tachypy import Screen, ResponseHandler

backend = os.getenv("TACHYPY_BACKEND", "pygame")
screen = Screen(
    screen_number=0,
    fullscreen=False,
    width=1280,
    height=720,
    backend=backend,
)
responses = ResponseHandler(screen=screen)

running = True
while running:
    screen.fill((128, 128, 128))
    screen.flip()

    responses.get_events()
    if responses.should_quit() or responses.was_key_pressed("esc"):
        running = False
    if responses.was_key_pressed("space"):
        print("Space pressed")

screen.close()

To run the full demo:

python example_tachypy.py

Or explicitly choose backend:

TACHYPY_BACKEND=glfw python example_tachypy.py

Backend Notes

  • Screen(backend="pygame"): SDL/Pygame-managed window and events.
  • Screen(backend="glfw"): GLFW-managed window/events, with top-left logical coordinate handling aligned to TachyPy conventions.
  • For robust key/mouse behavior across backends, initialize ResponseHandler(screen=screen) so it can route event polling correctly.

Text Rendering Notes

  • Text is convenience-first and works for most instruction screens.
  • GLText/GLTextSDF/GLSystemText render text directly in OpenGL and are backend-independent.
  • If pygame.font is unavailable in your Python build, use .[text] or .[system_text] and switch to OpenGL text classes.

API Naming

The psychophysics module exposes modern English APIs (for example make_gabor, make_sine_grating, normalize_to_unit_interval). Legacy French names remain as compatibility wrappers and emit DeprecationWarning.

Testing

Run tests:

pip install -e ".[test]"
pytest

Current suite covers audio timing helpers, response/key state handling, backend behavior, psychophysics invariants, text layout/renderer basics, and other regression-prone utility paths.

For CI/headless testing, use:

TACHYPY_AUDIO_BACKEND=dummy pytest

Documentation

Expanded docs live in /docs and include:

  • getting started
  • backend behavior and input routing
  • text rendering options
  • audio backend guidance
  • examples and contribution workflow

Hosted docs (Read the Docs): https://tachypy.readthedocs.io/

Main Modules

  • screen.py: display/context lifecycle and backend abstraction.
  • responses.py: keyboard/mouse event handling and key-state queries.
  • text.py, gltext.py, gltext_sdf.py, glsystemtext.py: text rendering.
  • textures.py, shapes.py, draggable.py, scrollbar.py: visual primitives.
  • psychophysics.py: stimulus generation and normalization utilities.
  • audio.py: sound playback and timing helpers.

Contributing

  1. Fork and clone the repository.
  2. Create a branch for your change.
  3. Add tests for behavioral changes.
  4. Run pytest.
  5. Open a pull request.

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tachypy-0.1.5.tar.gz (58.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tachypy-0.1.5-py3-none-any.whl (46.4 kB view details)

Uploaded Python 3

File details

Details for the file tachypy-0.1.5.tar.gz.

File metadata

  • Download URL: tachypy-0.1.5.tar.gz
  • Upload date:
  • Size: 58.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for tachypy-0.1.5.tar.gz
Algorithm Hash digest
SHA256 134a053ccfdfc58e4fc0a190365feccbcc18d71b0e0011ffb8a0b8bade4176c0
MD5 4b716da9e62cdfbd1680a6173dd24191
BLAKE2b-256 fe0eceb25b49d0022deca7773c946f456becd7eaeb2d716dcd94795802901499

See more details on using hashes here.

File details

Details for the file tachypy-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: tachypy-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 46.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for tachypy-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 638c1e2eeefefce31290e9f58f4164d7090b7577a168e25cdc609e937d1e226a
MD5 52cbecfed981bb3772aaf163019c29b8
BLAKE2b-256 9cde75f2b69b1fe0fa902d3a90a70e5109a45454e43b90eb6c0593365c1b685b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page