Skip to content

Add globals and callback handling#120

Open
tychedelia wants to merge 1 commit intoprocessing:mainfrom
tychedelia:globals-cbs
Open

Add globals and callback handling#120
tychedelia wants to merge 1 commit intoprocessing:mainfrom
tychedelia:globals-cbs

Conversation

@tychedelia
Copy link
Copy Markdown
Member

In Processing, globals and callbacks like width, height, mousePressed, etc. are members of the containing PApplet that the user's sketch runs in. This means that inside the user's draw function, the user can simply write width due to the elision of the this receiver in Java. Further, the draw loop can delegate callbacks to overrides on the user's PApplet.

In Python, this is problematic. For stylistic reasons, we do not want to have draw/setup require accepting a self receiver, as this would require writing self.width etc. anywhere the user wishes to access some Processing state. As such, in Python, we instead do a bit of magic in order make some global variables provide the same semantics as Processing.

This PR provides the following related changes to help support this:

  1. Adds a pattern around global variable updates to avoid overwriting user variables that may shadow our variable's names.
  2. Support for importing our main module as an alias, i.e. import mewnala as mn where mn.width delegates to the underlying getter via __getattr__.
  3. Callback functionality, where we introspect the global ns for a user's function.
  4. Input support to enable knowing when to fire callbacks.
  5. Misc surface methods for retrieving surface state.
  6. A new monitor API object. We don't support monitor selection fully yet but will in the future.
  7. Cleanup for ipython/jupyter hooks to make sure the above work.

@tychedelia tychedelia requested a review from catilac April 21, 2026 08:22
"key_code",
"key_is_pressed",
"display_width",
"display_height",
Copy link
Copy Markdown

@SableRaf SableRaf Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would display_density fit here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants