Example: Preferences dialog
A settings dialog with tabbed sections, several input types, Save/Close, and JSON persistence. The most complete example — it touches most of the widget set.
Run it:
scriptweaver internal/scriptweaver/testdata/preferences.js
It shows TNotebook tabs plus
TEntry / TCombobox / TCheckButton /
TSpinbox, bound to a settings object and persisted with
sw.fs.
Tabs
A notebook holds one frame per tab:
const nb = app.TNotebook();
const general = nb.TFrame({ padding: 12 });
const editor = nb.TFrame({ padding: 12 });
nb.add(general, { text: 'General' });
nb.add(editor, { text: 'Editor' });
Binding settings to widgets
Two functions move data between the settings object and the widgets — load it
into the UI, and read it back on Save:
function settingsToWidgets() {
nameEntry.value = settings.name;
themeCombo.value = settings.theme;
fontSpin.value = String(settings.fontSize);
// the checkboxes bind BoolVars — see the Variables guide
}
function widgetsToSettings() {
settings.name = nameEntry.value;
settings.theme = themeCombo.value;
settings.fontSize = parseInt(fontSpin.value, 10);
}
Checkbuttons bind a BoolVar via their variable
option, so toggling the box updates settings automatically.
Save
function doSave() {
widgetsToSettings();
sw.fs.writeFile(dataFile, JSON.stringify(settings, null, 2));
sw.dialog.alert('Preferences saved.');
}
Full source: internal/scriptweaver/testdata/preferences.js.