Questions and dialogs
Ask the animator a question or show a dialog of your own.
A script can ask you one question, show a dialog of its own, show a message box or open a file dialog. It only describes what it wants. Buhayin builds the window from the editor's own controls and gives back what you chose.
Every call here waits for you, and the waiting does not count against the script's ten seconds. They need a window: in a script run from the command line, ask and the dialogs throw an error and the script stops.
One question
buhayin.ask(question)
await buhayin.ask({ title, text, choices })A box with a title, a line of text and one button for each of choices (one to 100 strings). It gives the choice you picked, or null when you cancel.
const answer = await buhayin.ask({ title: "Hide layers", text: "Hide every layer but this one?", choices: ["Hide them", "Leave them"] })
if (answer !== "Hide them") returnShort questions
Input
await Input.getText(label?, text?, title?)
await Input.getNumber(label?, value?, decimals?, minValue?, maxValue?, title?)
await Input.getItem(label?, itemList, currentItem?, editable?, title?)One question each. They give what you typed or picked, or null when you cancel. getNumber asks for a whole number unless you give decimals of 1 or more. getItem may leave out the label: Input.getItem(itemList, currentItem).
const name = await Input.getText("Layer name:", "Ball")
if (name === null) return
await buhayin.edit({ kind: "addLayer", name })Message boxes
MessageBox
await MessageBox.information(text, button0?, button1?, button2?, title?)
await MessageBox.warning(text, button0?, button1?, button2?, title?)
await MessageBox.critical(text, button0?, button1?, button2?, title?)Shows a message and gives the button you pressed. Name the buttons with MessageBox.Ok, Cancel, Yes, No, Save, Discard, Apply, Reset, Close, Open, Help, Abort, Retry, Ignore, SaveAll, RestoreDefaults, YesToAll and NoToAll.
const pressed = await MessageBox.warning("Delete every hidden layer?", MessageBox.Yes, MessageBox.No, 0, "Delete layers")
if (pressed !== MessageBox.Yes) returnFile dialogs
FileDialog
await FileDialog.getOpenFileName(filter?, title?)
await FileDialog.getSaveFileName(filter?, title?)
await FileDialog.getExistingDirectory(dir?, title?)
await FileDialog.getOpenFileNames(dir?, filter?, title?)You pick a file, a place to save, a folder or several files. The first three give a path, or null when you cancel. getOpenFileNames gives a list, empty when you cancel.
const path = await FileDialog.getOpenFileName("Text files (*.txt)", "Pick a list")
if (path === null) return
const text = await buhayin.file.read(path)A dialog of your own
Dialog
const dialog = new Dialog()
dialog.title = "Rename layers"
dialog.add(widget)
const accepted = await dialog.exec()A Dialog holds widgets in columns, and under them, if you call newTab, tabs of columns. exec shows it and gives true when you accept it. The widgets then hold what you left in them.
| Property or call | What it does |
|---|---|
title, caption | The dialog's title. caption is another name for title. |
width | The width in pixels. |
okButtonText, cancelButtonText | The words on the two buttons. |
add(widget) | Puts a widget in the current column. A widget goes into a dialog once. |
addSpace(size) | Puts a gap in the column. |
newColumn() | Starts the next column. |
newTab(label) | Starts a tab. What was added before the first newTab sits above the tabs. |
A dialog holds at most 500 items, 20 tabs and 10 columns, with boxes nested no more than 3 deep.
The widgets
| Widget | Properties |
|---|---|
Label | text |
LineEdit | label, text |
TextEdit | label, text |
CheckBox | text, checked |
RadioButton | text, checked. Radio buttons added one after another are one group, until an addSpace. |
NumberEdit | label, value, decimals, minimum, maximum |
SpinBox | label, value, minimum, maximum |
Slider | label, value, minimum, maximum as whole numbers, orientation ("horizontal" or "vertical"), callback |
ComboBox | label, itemList, currentItem, currentItemPos, editable |
DateEdit | label, date, minimum, maximum, order. A date is a JavaScript Date. Use DateEditEnum.DMY, MDY, YMD or YDM for order. |
TimeEdit | label, time, minimum, maximum, showSeconds, showAMPM |
GroupBox | title, with its own add, newColumn, addSpace and clear |
ScrollArea | add(widget), which holds one widget |
Button | label, callback |
Every widget also takes toolTip, whatsThis and minimumSize as { width, height }.
Buttons and sliders that call back
A Button, or a Slider, with a callback does not close the dialog. The callback is a function of your script or its name. It runs while the dialog stays open, then the dialog takes whatever your script left in the widgets. A callback that throws is printed and the dialog goes on. exec still gives true or false when you finally accept or cancel.
const count = new SpinBox()
count.label = "How many?"
count.value = 3
count.minimum = 1
count.maximum = 10
const preview = new Button("Show the count")
preview.callback = () => print("Count is " + count.value)
const dialog = new Dialog()
dialog.title = "Add layers"
dialog.add(count)
dialog.add(preview)
if (await dialog.exec()) {
print("You chose " + count.value)
}