Skip to content
oldmangan edited this page Oct 8, 2026 · 1 revision

A floating window: drag it by its title bar, resize it from any edge or corner, maximise it, and keep several open at once. It is not modal by default, so the page and other windows stay usable. For a fixed, centred dialog, ModalWindow is still the simpler choice.

Added in #64.

from wapyt import Form, FormConfig, Toolbar, ToolbarButton, ToolbarConfig, Window, WindowConfig

win = Window(WindowConfig(title="Query", width=640, height=420, footer=True))
form = Form(FormConfig(fields=[...], submit_text=None), container=win.body)
Toolbar(ToolbarConfig(items=[ToolbarButton("run", "Run", variant="primary")]), container=win.footer)

win.on_move(lambda p: prefs.save("query_window", p))       # {"left", "top"}
win.on_resize(lambda p: prefs.save("query_size", p))       # {"width", "height", "maximized"}
win.show()

Config

WindowConfig
title Title bar text (shown as text)
width, height Starting size in pixels (default 480 x 320)
left, top Starting position in pixels; leave them out to centre it
min_width, min_height Smallest size a resize allows (default 200 x 120)
max_width, max_height Largest size (default: the browser window)
movable, resizable Drag to move, drag an edge to resize (both on)
modal A backdrop behind it, and Tab stays inside it
closable The close button, and Escape
maximizable The maximise button (and double-click / Enter on the title bar)
maximized Start maximised
footer A strip under the body for buttons: win.footer
dispose_on_close The close button and Escape remove the window instead of hiding it

Moving, resizing and stacking

  • Drag the title bar to move it. It can't go above the top of the browser window, and at least 48px of it always stays on screen, also when the browser window gets smaller.
  • Drag any edge or corner to resize it, within its minimum and maximum size.
  • The maximise button, a double-click on the title bar, or Enter on the focused title bar fill the browser window; the same again restores the previous size and place.
  • Several windows can be open. Pressing one brings it to the front (on_focus); a newly shown one opens in front. A non-modal window never goes above an open modal one.
  • Dragging over an iframe or a terminal doesn't lose the pointer.

Keyboard

The title bar can take focus (Tab to it, or click it): the arrow keys move the window by 10px (with Ctrl, 1px), Shift and the arrow keys resize it, and Enter maximises or restores. Escape closes the window when it is modal, or when focus is inside it. Showing a window moves focus to its first control; hiding it gives focus back to whatever had it.

Events and methods

Event Payload
on_show {}
on_hide {reason}: button, escape or code
on_close {reason}; the window is gone
on_move {left, top}, when the person moves it
on_resize {width, height, maximized} (plus left / top after an edge drag)
on_focus {}: it came to the front

show, hide, close, is_visible, bring_to_front, set_title, set_content, body, footer, set_position(left, top), get_position, set_size(width, height), get_size, center, maximize, restore, is_maximized. The setters don't fire events, so restoring a saved place doesn't echo back.

set_content("text") shows a string as text, not HTML; mount widgets into win.body instead.

Clone this wiki locally