`window()` creates a top-level custom Expr window. Add GUI components with `add()`, optionally attach a `menu()` object, then call `show()`.
A window is a host GUI object. It is shown asynchronously and should normally be kept in a session variable or object property while it is open.
`window` is not cloneable because it represents live host window state and callback state.
Creates a window object.
| Item | Description |
|---|---|
| Syntax | `window()` |
| Arguments | none |
| Returns | window object |
Default configuration:
| Setting | Default |
|---|---|
| Title | `Window` |
| Size | `400 x 300` |
| Position | `-1, -1` host/default position |
| Modal | `true` |
| Taskbar | `false` |
| Buttons | Close button only |
Example:
w = window() .title('Parameters') .size(360, 180) .buttons(false, true, true); w.show();
Window properties are read-only. Use methods such as `title()`, `size()`, `position()`, `modal()`, and `buttons()` to change the window.
| Property | Type | Description |
|---|---|---|
| `title` | string | Current window title. |
| `position_x` | number | Current window x position. |
| `position_y` | number | Current window y position. |
| `size_width` | number | Current window width. |
| `size_height` | number | Current window height. |
| `modal` | boolean | Current modal state. |
| `taskbar` | boolean | Whether the window is configured to appear in the taskbar. |
| `has_apply` | boolean | `true` when the built-in Apply button is enabled. |
| `has_ok` | boolean | `true` when the built-in OK button is enabled. |
| `has_close` | boolean | `true` when the built-in Close button is enabled. |
Example:
w = window().title('Probe').size(300, 160); print(w.title, ' ', w.size_width, ' x ', w.size_height);
Returns a display string for the object.
| Item | Description |
|---|---|
| Syntax | `value.to_string()` |
| Arguments | none |
| Returns | string |
Example:
text = value.to_string();
`clone()` is not supported for `window`.
Sets the window title.
| Item | Description |
|---|---|
| Syntax | `window.title(text)` |
| Arguments | `text`: title text |
| Returns | window object |
Example:
w = window().title('Tool Setup');
Sets the window size in pixels. Width and height are clamped to at least `1`.
| Item | Description |
|---|---|
| Syntax | `window.size(width, height)` |
| Arguments | `width`: width in pixels; `height`: height in pixels |
| Returns | window object |
Example:
w = window().size(420, 240);
Sets the top-left window position in pixels. `-1, -1` lets the host choose the position.
| Item | Description |
|---|---|
| Syntax | `window.position(x, y)` |
| Arguments | `x`: x position; `y`: y position |
| Returns | window object |
Example:
w = window().position(100, 80);
Enables or disables the built-in Apply, OK, and Close buttons.
| Item | Description |
|---|---|
| Syntax | `window.buttons(apply, ok, close)` |
| Arguments | `apply`: boolean; `ok`: boolean; `close`: boolean |
| Returns | window object |
Example:
w = window().buttons(true, true, true);
Sets whether the window is modal. With this form, taskbar visibility is chosen automatically: non-modal windows are shown in the taskbar, modal windows are not.
| Item | Description |
|---|---|
| Syntax | `window.modal(enabled)` |
| Arguments | `enabled`: boolean |
| Returns | window object |
Example:
w = window().modal(false);
Sets modal state and taskbar visibility explicitly.
| Item | Description |
|---|---|
| Syntax | `window.modal(enabled, showInTaskbar)` |
| Arguments | `enabled`: boolean; `showInTaskbar`: boolean |
| Returns | window object |
Example:
w = window().modal(false, true);
Enables or disables user resizing.
| Item | Description |
|---|---|
| Syntax | `window.resizable(enabled)` |
| Arguments | `enabled`: boolean |
| Returns | window object |
Example:
w = window().resizable(false);
Adds a GUI component to the window content area. A component can belong to only one window.
| Item | Description |
|---|---|
| Syntax | `window.add(component)` |
| Arguments | `component`: GUI component object |
| Returns | window object |
Example:
w = window().title('Input').size(300, 140); w.add(label().position(20, 20).size(180, 24).text('Name')); w.add(textinput().position(20, 48).size(220, 24).text('Part 1')); w.show();
Attaches a `menu()` object to the window.
| Item | Description |
|---|---|
| Syntax | `window.menu(menuObject)` |
| Arguments | `menuObject`: menu object |
| Returns | window object |
Example:
function on_open() { print('Open'); } m = menu(); file = m.add('File'); file.add('Open', on_open); w = window().menu(m).show();
Shows the window asynchronously and returns the window object immediately. Calling `show()` again after the window was closed creates and shows the live host window again.
| Item | Description |
|---|---|
| Syntax | `window.show()` |
| Arguments | none |
| Returns | window object |
Example:
w = window().title('Status').size(280, 120); w.show();
Requests the Close action. This follows the same request flow as `request_close()`, so an `on_request()` callback can veto the close by returning `false`.
| Item | Description |
|---|---|
| Syntax | `window.close()` |
| Arguments | none |
| Returns | window object |
Example:
w.close();
Returns whether the live host window currently exists and is visible.
| Item | Description |
|---|---|
| Syntax | `window.is_visible()` |
| Arguments | none |
| Returns | boolean |
Example:
if (w.is_visible()) { print('Window is open'); }
Simulates clicking the visible built-in Apply button. If the Apply button is not available or disabled, no action is performed.
| Item | Description |
|---|---|
| Syntax | `window.click_apply()` |
| Arguments | none |
| Returns | window object |
Simulates clicking the visible built-in OK button. If the OK button is not available or disabled, no action is performed.
| Item | Description |
|---|---|
| Syntax | `window.click_ok()` |
| Arguments | none |
| Returns | window object |
Simulates clicking the visible built-in Close button. If the Close button is not available or disabled, no action is performed.
| Item | Description |
|---|---|
| Syntax | `window.click_close()` |
| Arguments | none |
| Returns | window object |
Runs the Apply request flow even if the Apply button is not visible. This calls `on_request(2)` but does not close the window.
| Item | Description |
|---|---|
| Syntax | `window.request_apply()` |
| Arguments | none |
| Returns | window object |
Runs the OK request flow even if the OK button is not visible. This calls `on_request(1)`. If the request is allowed, the window closes and `on_closed(1)` is called.
| Item | Description |
|---|---|
| Syntax | `window.request_ok()` |
| Arguments | none |
| Returns | window object |
Runs the Close request flow even if the Close button is not visible. This calls `on_request(0)`. If the request is allowed, the window closes and `on_closed(0)` is called.
| Item | Description |
|---|---|
| Syntax | `window.request_close()` |
| Arguments | none |
| Returns | window object |
Sets a callback that is called when the live window is shown.
| Item | Description |
|---|---|
| Syntax | `window.on_showing(callback)` |
| Arguments | `callback`: callable with no arguments |
| Returns | window object |
Sets a callback that is called when Apply, OK, or Close is requested.
| Item | Description |
|---|---|
| Syntax | `window.on_request(callback)` |
| Arguments | `callback`: callable with one argument, the result code |
| Returns | window object |
For OK and Close requests, return `false` to keep the window open. Return `true` or return no value to allow the close. For Apply requests, the return value is ignored because Apply does not close the window.
Result codes:
| Code | Meaning |
|---|---|
| `0` | Close |
| `1` | OK |
| `2` | Apply |
Sets a callback that is called after the window closes.
| Item | Description |
|---|---|
| Syntax | `window.on_closed(callback)` |
| Arguments | `callback`: callable with one argument, the result code |
| Returns | window object |
Result codes are the same as for `on_request()`.
Sets a callback that is called after the window content area is resized.
| Item | Description |
|---|---|
| Syntax | `window.on_resize(callback)` |
| Arguments | `callback`: callable with four arguments: `x`, `y`, `width`, `height` |
| Returns | window object |
The callback receives content-area bounds, not the outer operating-system window frame.
class Demo() { request_count = 0; closed_count = 0; last_code = -1; wnd = none(); function on_request(code) { request_count = request_count + 1; last_code = code; // Veto the first close attempt. if (code == 0 && request_count == 1) { return false; } return true; } function on_closed(code) { closed_count = closed_count + 1; last_code = code; } function show() { wnd = window() .title('Demo') .size(300, 160) .buttons(false, true, true) .on_request(this.on_request) .on_closed(this.on_closed); wnd.add(label().position(20, 20).size(220, 24).text('Custom window')); wnd.show(); } } demo = Demo(); demo.show();
Previous: GUI objects
Next: panel