Dialog Widgets¶
Dialog¶
Modal or non-modal dialog with configurable buttons.
Constructor: new Widgets.Dialog(title, buttons, {autoclose, resizable, moveable, modal})
Arguments:
title– dialog titlebuttons– array of button labels (e.g.["OK", "Cancel"])
Options:
autoclose– close dialog when a button is pressedresizable– allow resizingmoveable– allow draggingmodal– modal overlay
Methods:
Method |
Description |
|---|---|
|
Return the content container to add widgets into. |
Callbacks:
activated– fired with the button label when a button is pressed.
let dlg = new Widgets.Dialog("Confirm", ["OK", "Cancel"], {
modal: true, autoclose: true
});
dlg.resize(300, 150);
let content = dlg.get_content_area();
let label = new Widgets.Label("Are you sure?");
content.add_widget(label, 1);
dlg.add_callback('activated', (w, btn) => {
console.log("User chose:", btn);
});
dlg.show();
ColorDialog¶
Color picker dialog with SV plane, hue strip, and RGB/HSV/hex inputs.
Constructor: new Widgets.ColorDialog({color, title, modal, moveable})
Options:
color– initial color as hex stringtitle– dialog titlemodal– modal overlaymoveable– allow dragging
Methods:
Method |
Description |
|---|---|
|
Return selected color as hex string. |
|
Set the current color. |
|
Show the dialog (optionally at a specific position). Inherited from Dialog. |
|
Inherited from Dialog. |
Callbacks:
activated– fires with the chosen colour when OK is clicked.pick– fires interactively as the user drags inside the picker.move/close– inherited from Dialog.
let picker = new Widgets.ColorDialog({color: "#ff6600", modal: true});
picker.add_callback('activated', (w, btn) => {
if (btn === "OK") {
console.log("Chosen color:", w.get_color());
}
});
picker.show();
FileDialog¶
File open/save dialog. Uses the browser’s native file picker for opening and programmatic download for saving. This is a non-visual (Callback-based) object.
Constructor: new Widgets.FileDialog({mode, accept})
Options:
mode–"open"or"save"accept– file type filter (e.g.".png,.jpg,image/*")
Methods:
Method |
Description |
|---|---|
|
Show the file-open picker. |
|
Trigger a file download. |
|
Set or get mode. |
|
Set or get file type filter. |
Callbacks:
activated– fired when a file is selected (open) or saved.progress– fired with progress updates during file reading.
let fd = new Widgets.FileDialog({mode: "open", accept: ".txt,.csv"});
fd.add_callback('activated', (w, fileData) => {
console.log("File loaded:", fileData.name);
});
fd.open();