bauiv1lib.docui package¶
Functionality for using doc-ui on top of bauiv1.
- class bauiv1lib.docui.DocUIController[source]¶
Bases:
objectManages interactions between DocUI 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:
EnumTypes of errors that can occur in request processing.
- COMMUNICATION_ERROR = 'communication'¶
- GENERIC = 'generic'¶
- NEED_UPDATE = 'need_update'¶
- UNDER_CONSTRUCTION = 'under_construction'¶
- create_window(request: DocUIRequest, *, transition: str | None = 'in_right', origin_widget: bui.Widget | None = None, auxiliary_style: bool = True, uiopenstateid: str | None = None, suppress_win_extra_type_warning: bool = False) DocUIWindow[source]¶
Create a new window to handle a request.
- error_response(request: DocUIRequest, error_type: ErrorType = ErrorType.GENERIC, custom_message: str | None = None) DocUIResponse[source]¶
Build a simple error message page.
A message is included based on
error_type. Passcustom_messageto override this.Messages will be translated to the client language using the ‘serverResponses’ Lstr translation category.
- fulfill_request(request: DocUIRequest) DocUIResponse[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.CleanErrorexception. This can be raised as a quick and dirty way to show custom error messages. The coderaise CleanError('Something broke.')will have the same effect asreturn self.error_response(custom_message='Something broke.').
- fulfill_request_web(request: DocUIRequest, url: str) DocUIResponse[source]¶
Fulfill a request by sending it to a webserver.
- classmethod get_window_extra_type_id() str[source]¶
Return a string suitable for the
window_extra_type_idarg toauxiliary_window_activate().This ensures your doc-ui window is identified distinctly from other doc-ui windows for navigation purposes.
- local_action(action: DocUILocalAction) None[source]¶
Do something locally on behalf of the doc-ui.
Controller classes can override this to expose named actions that can be triggered by doc-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 doc-ui pages are coming from untrusted sources. Generally things like launching or joining games are good candidates for local actions.
- replace(win: DocUIWindow, request: DocUIRequest, *, origin_widget: bui.Widget | None = None, is_refresh: bool = False) None[source]¶
Kick off a request to replace existing window contents.
- restore(win: DocUIWindow, *, last_response: DocUIResponse | None) DocUIWindow[source]¶
Restore a window from previous state.
May immediately display old results or may kick off a new request.
Called when a window shared state is being restored.
- run_action(window: DocUIWindow, widgetid: str | None, action: bacommon.docui.v1.Action | None, is_timed: bool = False) None[source]¶
Called when a button is pressed in a v1 ui.
Called when a window shared state is being saved.
- class bauiv1lib.docui.DocUILocalAction(name: str, args: dict, widget: Widget | None, window: DocUIWindow)[source]¶
Bases:
objectContext for a local-action.
- window: DocUIWindow¶
- class bauiv1lib.docui.DocUIWindow(controller: DocUIController, request: DocUIRequest, *, transition: str | None = 'in_right', origin_widget: bui.Widget | None = None, auxiliary_style: bool = True, restored: bool = False, uiopenstateid: str | None = None, suppress_win_extra_type_warning: bool = False)[source]¶
Bases:
MainWindowWindow showing doc-ui content.
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.
Restore state from the provided shared state dict.
Can be overridden by subclasses to restore custom data.
Save state into the provided shared state dict.
Can be overridden by subclasses to save custom data.
- 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: DocUIRequest¶
The current request.
Should only be accessed from the logic thread while the ui is unlocked.
- set_last_response(response: DocUIResponse, success: bool) None[source]¶
Set a response to a request.