Skip to main content

Page

Page is the top most container for all other controls. It is is automatically added when a new page is created or app session started.

Page control has a reserved page control ID. You cannot add Page control, however you can change its properties. Technically, the Page is a vertical Stack control, so it has similar behavior and shares some properties.

Properties​

NameTypeDefaultDescription
titlestring{page_name}Β -Β PgletA title of browser window.
verticalFillboolfalseDefines whether page contents takes 100% of the height of browser window.
horizontalAlignstringstartDefines how to align page children horizontally: start, end, center, space-between, space-around, space-evenly, baseline or stretch.
verticalAlignstringDefines how to align page children vertically: start, end, center, space-between, space-around, space-evenly, baseline or stretch.
widthstring100%The width of a page container.
paddingstring10pxThe padding of a page container.
gapstring10A gap between page child controls.
bgcolorstringPage background color.
hashstringRead-only window's width. Updated for multi-user apps only when browser window is
winWidthnumberRead-only window's width. Updated for multi-user apps only when browser window is resized.
winHeightnumberRead-only window's height. Updated for multi-user apps only when browser window is resized.
themestringlightPage's theme: light or dark.
themePrimaryColorstringTheme primary color. Use Fluent UI Theme Designer to build a custom theme.
themeTextColorstringTheme text color. Use Fluent UI Theme Designer to build a custom theme.
themeBackgroundColorstringTheme background color. Use Fluent UI Theme Designer to build a custom theme.
signinstringDisplays Sign In dialog with selected auth methods.
signinAllowDismissboolEnables user to dismiss Sign In dialog.
signinGroupsboolEnables Pglet OAuth app to ask for teams/groups read permission during OAuth authorization flow.
userAuthProviderstringAuthentication method used by a user to sign in: github, google or azure (Microsoft Account). Read-only, multi-user apps only.
userIdstringID of the signed in user. For GitHub auth method it's GitHub's user ID (number), for Google - email address and for Microsoft Account - user's GUID. Read-only, multi-user apps only.
userLoginstringFor GitHub auth method it's GitHub's username, for Google and Microsoft Account - email address. Read-only, multi-user apps only.
userNamestringDisplay name of the signed in user. Read-only, multi-user apps only.
userEmailstringEmail address of the signed in user. Read-only, multi-user apps only.
userClientIPstringIP address of the signed in user. Read-only, multi-user apps only.

Events​

NameDescription
hashChangeFires when URL hash part has changed.
resizeFires when page (browser window) has been resized.
connectFires when a web user connects to a page session. It is not triggered when an app page is first opened, but is triggered when the page is refreshed, or computer unlocked and browser reconnected.
disconnectFires when a web user disconnects from a page session, i.e. closes browser window.
closeFires when a session has expired after timeout (60 minutes by default).
signinFires when a web user authenticates with one of the enabled methods.
dismissSigninFires when a web user has clicked "close" button on "Sign in" dialog.
signoutFires when a web user has signed out by navigating to {pglet-server}/api/auth/signout URL or calling page.signout() method.

Examples​

Creating a new page with a random name and connecting to it:

import pglet
page = pglet.page()

Creating a page with a custom name:

import pglet
page = pglet.page("my-page")

By default, when connecting to a page its contents is cleared. To preserve page contents and connect it in update mode:

import pglet
page = pglet.page("my-page", update=True)

Create a new app with name app1 and wait for connections. web=True makes app UI displaying at Pglet service. main function is an entry point for a new user session. When a new user connects we just greem them with Hello, world! message:

import pglet

def main(page):
page.add(Text(value="Hello, world!"))

pglet.app("app1", web=True, target=main)

To update page title:

page.title = "My App!"
page.update()