Add-ons
Any program, in any language, can put its own buttons on Studio's Shot tab and show its window in a Studio dock.
Such a program is an add-on: a folder with a small JSON file that lists its buttons.
Bring your own program
Your program's window, in a Studio dock.
Each add-on button sits on Studio's Shot tab after the editor's own buttons, and opens a Studio dock with the add-on's own window inside. It sits beside Studio's panels but runs as a program of its own, apart from Studio.
- Each Studio gets its own copy of the program.
- The window fills the dock and follows it when you resize it. While you drag the dock somewhere else, the window steps out, and it comes back when you let go.
- Closing the dock hides the window and leaves the program running, so the dock opens again at once.
- If the program ends or crashes, the dock says it stopped and offers Restart. If the window stops answering, it leaves the dock until it answers again, and the dock says it isn't responding, also with Restart. Studio keeps working either way.
- When its Studio closes, or ShotScript Editor quits, the program is asked to close, and then it and everything it started are ended. If ShotScript Editor itself crashes, the program keeps running.
- Add-ons start only while ShotScript Editor is open. In ShotScript Editor's list, each Studio's row shows how many add-ons it has running.
Declare its buttons
An add-on is a folder with an addon.json that lists its buttons.
The folder goes inside ShotScript Editor's AddOns folder, %LOCALAPPDATA%\MimeStudio\AddOns, and is named after the add-on. Next to its addon.json it usually holds the program too:
{
"name": "Palette",
"buttons": [
{
"id": "Open",
"label": "Palette",
"window": { "title": "Palette", "kind": "exe", "entry": "Palette.exe" }
}
]
}name: the folder's name. Names and ids are letters and digits only, and one name is reserved for ShotScript Editor itself.buttons: one or more. Each button's id is used once in the add-on, andlabelis its text (the id when left out). A button with the same label as one of ShotScript Editor's own docks is left off the tab.icon: a Studio content address for the button's picture, such as anrbxassetid://one. Without it, the button gets a placeholder.window:kindisexe, so far the only kind, andtitlenames the dock (the label when left out).entryis the program: a .exe inside the folder, or the full path of one installed elsewhere, since PATH isn't searched.args, a list of strings, is passed to it.child, when true, is for a program that makes its own window inside the dock (see INTO THE DOCK below).- Nothing else in the file is read.
ShotScript Editor reads the folder when it opens. A new or removed add-on, or a button's new label, icon or title, puts ShotScript Editor on Update, and one click puts the buttons on the Shot tab. Only ShotScript Editor's own buttons change: anything you put on the tab yourself stays, and a copy of the ribbon is kept first. If an add-on can't be used, the Update screen names it and says why. A Studio that was already open shows the new buttons after you restart it.
Into the dock
Any window works, with no code for the dock.
When a dock opens, ShotScript Editor starts the add-on's program in the add-on's folder, with four environment variables:
STUDIO_PID: that Studio's process id.STUDIO_PLACE: the name of the place it has open.DOCK_HWND: the dock's window handle, as a decimal number, once ShotScript Editor has found the dock.ADDON_FOLDER: the add-on's own folder.
The program's first visible window then moves into the dock, loses its title bar and border, and fills the dock.
A program that sets "child": true makes its own child window of DOCK_HWND instead. When the dock gets a new window handle, ShotScript Editor sends WM_APP+1, with the new handle as its wParam, to the program's hidden window titled MimeStudioAddOn, and the program makes a new child window there.
Each add-on runs in a Windows job object of its own, so everything the program starts counts as the add-on. A launcher that starts the real program, an Electron app or a cmd wrapper all work, and the add-on has stopped only once the last of its programs ends.
An example in python
A window that shows what its dock was given.
Make a folder named Hello in ShotScript Editor's AddOns folder, with this addon.json:
{
"name": "Hello",
"buttons": [
{
"id": "Open",
"label": "Hello",
"window": {
"kind": "exe",
"entry": "<the full path of pythonw.exe>",
"args": ["hello.py"]
}
}
]
}Beside it, this hello.py:
import os
import tkinter as tk
root = tk.Tk()
root.title("Hello")
for name in ("STUDIO_PID", "STUDIO_PLACE", "DOCK_HWND", "ADDON_FOLDER"):
tk.Label(root, text=f"{name}: {os.environ.get(name, '')}").pack(anchor="w", padx=12)
root.mainloop()where pythonw in a terminal prints the full path for entry; in JSON, double each backslash in it. ShotScript Editor then shows Update: one click and a Studio restart, and the Shot tab has a Hello button that opens the window in a dock.
