Skip to main content

BaseCanvas

Description

BaseCanvas is a small helper-class that handles common tasks in pygame. I've built it because I'm constantly making side-projects, often related to simulations, data structures, little games and stuff and it's not pleasant to always have to paste boilerplate code just to get started. Feel free to contact me, for suggestions, complaints or anything, really.

Use

To get started simply:

  1. Import BaseCanvas

     from base_canvas import BaseCanvas
    
  2. Create a "Main Class" that inherits BaseCanvas

     class Main(BaseCanvas):
         pass
    
  3. Append the following at the end of the file in which your "Main Class" is:

    if __name__ == "__main__":
        main = Main()
        main.loop()
    

When running your program from the command-line a few parameters can be passed:

  • --width (an integer, if 0 fullscreen mode will be selected. Default to 800)
  • --height (an integer, if 0 fullscreen mode will be selected. Default to 800)
  • --fps (an integer. Default to 60)

lifecycle

The lifecycle of BaseCanvas is centered around inherited and overwritten hooks. They are 4 in total, each one with there own "responsibilities".

Setup hook

The setup hook (setup_hook) is the first one to be called, right after pygame is initiated. It's intended to do all sort of "variable initialization". It's called only once.

Init hook

The init hook (init_hook) is the second one to be called. It's intended to do all sort of pre-loop logic, such as, initializing certain classes, doing a flow-check (should the program run like this or like that), etc. As with the setup hook, it's called only once.

Loop hook

The loop hook (loop_hook) is the third and main hook. It's where all of your main program logic should happen, things like: drawing to the canvas, collision check, etc. It's called at every frame, right after filling the main canvas with the "BACKGROUND_COLOR" and before calling "pygame.display.update()".

Handle events hook

The handle events hook (handle_events_hook) is the fourth and last hook. It's also the only hook that receives an argument, the event itself. It's called at every frame. The event (argument) is one element of the list returned by "pygame.event.get()". Keep in mind that some events are "handled" by default. They are:

  • pygame.QUIT
  • pygame.KEYDOWN
    • pygame.K_ESCAPE
    • pygame.K_F11
  • pygame.VIDEORESIZE

Author

João Pedro Braz, São Paulo - Brazil.

Metadata

Release files for base-canvas 1.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for base-canvas 1.0.7
File Size Uploaded Provenance Actions
base-canvas-1.0.7.tar.gz 3.8 kB Without provenance Details for base-canvas-1.0.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for base-canvas 1.0.7
File Interpreter ABI Platform Actions
base_canvas-1.0.7-py3-none-any.whl Python 3 none any Details for base_canvas-1.0.7-py3-none-any.whl

Total release size: 10.4 kB

Release files / base-canvas-1.0.7.tar.gz

Download URL base-canvas-1.0.7.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0acb062258ac2f94906dbbbcd1a03ccfd9f4112f263c6dbb8a3c3142914e7efd
BLAKE2b-256 checksum
How to use checksums
cf33ca508e4b569d542e26444bbd70e52bf7ee805eb98455051a0f0ed55f9a19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

Release files / base_canvas-1.0.7-py3-none-any.whl

Download URL base_canvas-1.0.7-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99d35dd3b2fb9b57c4293db3b484e28a444e0ccb73a35a374571f882325acedc
BLAKE2b-256 checksum
How to use checksums
ee0afd0117011bfc46b6776330508217b2caef30b7bef54f26ebcb0cd6538565
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

Security for base-canvas 1.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page