Inserts and commands
Items in the Insert menu, and commands in a Plugins menu.
Inserts
Items go in the Insert menu and the + of the layers, in a group: 'Layers', 'Text', 'Shapes', 'Pictures', or a new one.
inserts: [['Shapes', [
{ label: 'Badge', icon: 'Ellipse', about: 'A round badge in the color in hand',
run: (api) => api.project.add({ kind: 'shape', name: 'Badge', shape: 'Ellipse', w: 120, h: 120, color: api.project.color, radius: 0, stroke: 0 }) },
]]],
@plugin.insert('Badge', group='Shapes', icon='Ellipse', about='A round badge in the color in hand')
def badge(app):
app.add(kind='shape', name='Badge', shape='Ellipse', w=120, h=120, color=app.color, radius=0, stroke=0)
Commands
Commands go in a Plugins menu in the top bar, which appears when a plugin that is on has any. keys is shown beside the command.
commands: [
{ label: 'Say how many layers there are', run: (api) => api.say(`${api.project.layers.length} layers`) },
{ label: 'Add the image as a layer',
async run(api) { // one that takes its time is async
const picture = api.view.picture();
if (picture) await api.addPicture('Stamp', picture.toDataURL('image/png'));
} },
],
@plugin.command('Say how many layers there are')
def count(app):
app.say(f'{len(app.layers)} layers')
@plugin.command('Add the image as a layer')
async def stamp(app): # one that takes its time is written with "async def"
await app.add_picture('Stamp', app.picture())
A command, an insert or a tool can open a window, ask a question or show a notice: see Talking to the user.