bauiv1lib.decui package

Functionality for interacting with dec-ui from the client.

class bauiv1lib.decui.DecUIController[source]

Bases: object

Manages interactions between DecUI clients and servers.

Can include logic to handle all requests locally or can submit them to be handled by some server or can do some combination thereof.

class ErrorType(*values)[source]

Bases: Enum

Types of errors that can occur in request processing.

COMMUNICATION_ERROR = 'communication'
GENERIC = 'generic'
NEED_UPDATE = 'need_update'
UNDER_CONSTRUCTION = 'under_construction'
create_window(request: DecUIRequest, transition: str | None = 'in_right', origin_widget: bui.Widget | None = None, auxiliary_style: bool = True) DecUIWindow[source]

Create a new window to handle a request.

error_response(error_type: ErrorType = ErrorType.GENERIC, custom_message: str | None = None) DecUIResponse[source]

Build a simple error message page.

A message is included based on error_type. Pass custom_message to override this.

Messages will be translated to the client language using the ‘serverResponses’ Lstr translation category.

fulfill_request(request: DecUIRequest) DecUIResponse[source]

Handle request fulfillment.

Expected to be overridden by child classes.

Be aware that this will always be called in a background thread.

This method is expected to always return a response, even in the case of errors. Use error_response() to translate error conditions to responses.

The one exception to this rule (no pun intended) is the efro.error.CleanError exception. This can be raised as a quick and dirty way to show custom error messages. The code raise CleanError('Something broke.') will have the same effect as return self.error_response(custom_message='Something broke.').

fulfill_request_web(request: DecUIRequest, url: str) DecUIResponse[source]

Fulfill a request by sending it to a webserver.

local_action(action: DecUILocalAction) None[source]

Do something locally on behalf of the dec-ui.

Controller classes can override this to expose named actions that can be triggered by dec-ui button presses, responses, etc.

Of course controllers can also perform arbitrary local actions alongside their normal request fulfillment; this is simply a way to do so without needing to provide actual ui pages alongside.

Be very careful and focused with what you expose here, especially if your dec-ui pages are coming from untrusted sources. Generally things like launching or joining games are good candidates for local actions.

replace(win: DecUIWindow, request: DecUIRequest, *, origin_widget: bui.Widget | None = None, is_refresh: bool = False) None[source]

Kick off a request to replace existing window contents.

restore(win: DecUIWindow, *, last_response: DecUIResponse | None) DecUIWindow[source]

Restore a window from previous state.

May immediately display old results or may kick off a new request.

run_action(window: DecUIWindow, widgetid: str | None, action: bacommon.decui.v1.Action | None, is_timed: bool = False) None[source]

Called when a button is pressed in a v1 ui.

class bauiv1lib.decui.DecUILocalAction(name: str, args: dict, widget: Widget | None, window: DecUIWindow)[source]

Bases: object

Context for a local-action.

args: dict
name: str
widget: Widget | None
window: DecUIWindow
class bauiv1lib.decui.DecUIWindow(controller: DecUIController, request: DecUIRequest, *, transition: str | None = 'in_right', origin_widget: bui.Widget | None = None, auxiliary_style: bool = True, restored: bool = False)[source]

Bases: MainWindow

UI provided by the cloud.

get_main_window_shared_state_id() str | None[source]

Provide a custom id for window shared state.

Unlike MainWindowState, which is used to save and restore a single main-window instance, shared-state is intended to hold values that can apply to multiple instances of a window.

By default, shared state uses the window class as an index (so is shared by all windows of the same class), but this method can be overridden to provide more distinct states. For example, a store-page main-window class might want to keep distinct states for different sub-pages it can display instead of having a single state for the whole class.

Note that shared state only persists for the current run of the app.

get_main_window_state() MainWindowState[source]

Return a WindowState to recreate this specific window.

Used to gracefully return to a window from another window or ui system.

lock_ui(origin_widget: Widget | None = None) None[source]

Stop UI interactions during some operation.

property locked: bool

Are we locked?

main_window_should_preserve_selection() bool[source]

Whether this window should auto-save/restore selection.

If enabled, selection will be stored in the window’s shared state. See get_main_window_shared_state_id() for more info about main-window shared-state.

The default value of None results in a warning to explicitly override this (as the implicit default will change from False to True after api 9 support ends).

property request: DecUIRequest

The current request.

Should only be accessed from the logic thread while the ui is unlocked.

property scroll_height: float

Height of our scroll area.

property scroll_width: float

Width of our scroll area.

set_last_response(response: DecUIResponse, success: bool) None[source]

Set a response to a request.

unlock_ui() None[source]

Resume normal UI interactions.

Subpackages