Skip to content

Conversation

@hansthen
Copy link
Collaborator

@hansthen hansthen commented Jun 7, 2025

This allows javascript method calls to be generated using an empty method body and a signature. Useful for writing plugins.

As an example (and the driving motivation) I implemented this on the geoman plugin.

This allows javascript method calls to be generated using
an empty method body and a signature. Useful for writing plugins.

As an example (and the driving motivation) I implemented this on
the geoman plugin.
@hansthen hansthen requested a review from ocefpaf June 7, 2025 11:31
@ocefpaf
Copy link
Member

ocefpaf commented Jun 9, 2025

Interesting. I don't grasp everything here and the only feedback I can give you is that I would like more tests before we merge this one.

@hansthen
Copy link
Collaborator Author

hansthen commented Jun 9, 2025

I added a small snapshot test. What the decorator does is generate javascript code whenever a python method is called. So writing the following python client code:

# For manual testing of the global options
gm.set_global_options(
    {
        "snappable": True,
        "snapDistance": 20,
    }
)

# Make rectangles green
gm.enable_draw("Rectangle", path_options={"color": "green"})
gm.disable_draw()

will generate the following javascript code:

<name>.setGlobalOptions(
    {
        "snappable": true,
        "snapDistance": 20,
    }
)
<name>.enableDraw("Rectangle", {pathOptions: {"color": "green"}})
<name>.disableDraw()

@hansthen hansthen merged commit 0f04eeb into python-visualization:main Jun 11, 2025
15 checks passed
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