Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The Webview

One native window rendering a web frontend, and the Bridge to it. Dry’s one public object.

from dry import Webview

Every option is keyword-only, and every option is also a property.

Options

OptionTypeDefaultMeaning
titlestr'My Dry Webview'The window title. Cosmetic only
sizetuple[int, int](800, 600)Initial dimensions, logical pixels
min_sizetuple[int, int](800, 600)Minimum dimensions, logical pixels
decorationsboolTrueNative titlebar and borders
icon_pathstr | os.PathLike | NoneNoneWindow icon, .ico, Windows only
htmlstr | NoneNoneContent: an HTML string
urlstr | NoneNoneContent: an address to load
rootstr | os.PathLike | NoneNoneContent: a directory to serve
apidict[str, Callable] | NoneNoneThe names the frontend may Call
dev_toolsboolFalseEnable the web inspector
app_idstr | NonederivedDecides where this application’s data lives
user_data_folderstr | os.PathLike | Nonefrom app_idOverrides that location outright
defaultCallable[[Any], Any] | NoneNoneConverts a value outside the Bridge contract
on_closeCallable[[], object] | NoneNoneAsked before the window closes

Exactly one of html, url and root must be declared. Declaring a second raises immediately; declaring none raises at run().

Assigning an attribute that is not one of these raises AttributeError. Assigning any of them except title, size, min_size, decorations and icon_path after run() raises RuntimeError — see Window options.

Methods

MethodDoes
run()Opens the window and hands it the process. Never returns
on(name, listener)Registers a listener for an Event, and returns the listener
off(name, listener)Takes one registration off
emit(name, value=None)Emits an Event to the frontend
eval_js(script)Evaluates a script in the page, reading nothing back
state()Returns a WindowState: everything the window is doing, in one reading

on and off work before run(). emit and eval_js need a running window and raise a BridgeError without one; state() needs one and raises a RuntimeError without one.

The open window

Five of the options above go on applying once the window is open — title, size, min_size, decorations and icon_path — and beside them are five states that exist only then. These are not constructor arguments, and reading or assigning one before run() raises a RuntimeError naming it.

PropertyTypeMeans
positiontuple[int, int]Where the window’s top-left corner sits, logical pixels
visibleboolWhether it is on screen; False hides it without closing it
maximizedboolWhether it fills its screen
minimizedboolWhether it is minimized to the dock or taskbar
fullscreenboolWhether it has taken over its screen
from dry import WindowState

wv.state() returns a WindowState, a NamedTuple of maximized, minimized, fullscreen, visible, focused, size and position. The frontend asks for the same reading with await window.dry.state().

Every change made through these reaches the window Events exactly as a change the user made. See Runtime window control.

Read-only behaviour worth knowing

  • wv.root reads back a resolved pathlib.Path, whatever you assigned.
  • wv.icon_path reads back a POSIX-style str.
  • wv.user_data_folder reads back the folder in use, whether it came from the App id or from an override.

Exceptions

from dry import BridgeError, DryError, PanicError, WebviewError

See Errors and logging.