Python

A Python plugin makes a Plugin and adds to it with decorators.

The file must leave the plugin in a variable named plugin. Everything comes from the rassam module.

from rassam import Plugin, blank, button, choice, color, label, note, rule, slider, text, toggle

plugin = Plugin('example', 'Example', version='1.0', author='You', about='What it adds, in a sentence.')

Decorators

DecoratorThe function is given
@plugin.tool(name, icon=, about=, paints=, fields=)event. See Tools.
@plugin.element(name, w=, h=, group=, icon=, about=, fields=, ready=)pen, settings
@plugin.properties(title, fields=, kinds=)app, id, key, value
@plugin.effect(name, group=, category=, fields=)settings, tools
@plugin.filter(name, fields=)picture, settings
@plugin.backdrop(name)pen, frame
@plugin.overlay(name)pen, view, app
@plugin.dock(name, icon=, about=)host, app; it may give back what tidies up
@plugin.animation(name, frames=, resize=)doc, at; it gives back a canvas
@plugin.export(name, ending=, about=, fields=)work, app; it gives back the file
@plugin.insert(label, group=, icon=, about=)app
@plugin.command(label, keys=)app
@plugin.template(name, kind=, about=)nothing; it gives the document
@plugin.usesdoc
plugin.palette(name, colors)(a plain call)
plugin.size(name, width, height, group=, pixel_art=)(a plain call)
plugin.settings(field, field, ...)(a plain call: the plugin's own settings)

Fields and window items

CallMakes
slider(key, label, low, high, usual, step=1)A number.
color(key, label, usual)A color, '#RRGGBB'.
choice(key, label, choices, usual)One of several words.
toggle(key, label, usual)On or off.
text(key, label, usual)A line of words.
label(words), note(words, tone), rule()A window's words, a message box, a line across.
button(words, on_click)A window's own button. What on_click(values) gives back changes the fields (a dict) or says something (a string).
canvas(width, height)A new picture to draw on: what an animation gives back, what an export lays its pictures out on.
png_bytes(picture)A picture as the bytes of a PNG file.

Settings read as attributes or as a dict: settings.amount or settings['amount'].

The program

app has doc, layers, selected, size, color, layer(id), add(**values), add_all(layers, group), set(id, **values), mark(), select(id), say(text), log(text, level, detail), notify(text, tone), prefs(plugin_id), picture() and view (the canvas). What waits for an answer is awaited inside an async def: app.window(title, items, buttons), app.ask(title, text, buttons), app.message(title, text), app.add_picture(name, data). The names beside their TypeScript ones are on The API.

Reaching the page

A Python plugin has everything a TypeScript one has. Where it needs the page itself (a dock that builds its own view, an element that fetches a picture), it is reached through Pyodide's js module: from js import document, Image.

Python runs slower than JavaScript. An overlay or an animation that loops over every pixel for every picture is better written in TypeScript; one that draws with the pen is fine.