Karana.WebUI#
Classes and modules related to Web UI.
Submodules#
Attributes#
Classes#
Widget displaying a Slider triggering a server-side callback |
|
Package Contents#
- type Karana.WebUI.Json = None | str | int | float | list['Json'] | dict[str, 'Json']#
- class Karana.WebUI.Button(router: Router, text: str, on_press: collections.abc.Callable[[], None], tooltip: str = '')#
Bases:
Widget
- class Karana.WebUI.Channel#
- broadcastMessage(msg: str) None#
- defer(callback: collections.abc.Callable[[], None]) None#
- sendMessage(msg: str, client_id: SupportsInt | SupportsIndex) None#
- setOnConnect(callback: collections.abc.Callable[[SupportsInt | SupportsIndex], None]) None#
- setOnDisconnect(callback: collections.abc.Callable[[SupportsInt | SupportsIndex], None]) None#
- setOnMessage(callback: collections.abc.Callable[[str, SupportsInt | SupportsIndex], None]) None#
- sync() None#
- uuid() str#
- class Karana.WebUI.ClientApp(url: str)#
- static findExecutable() pathlib.Path | None#
- getStderr() str#
- getStdout() str#
- shutdown() None#
- class Karana.WebUI.ContentSource#
- class Karana.WebUI.Dock(router: Router, style: collections.abc.Mapping[str, str] = {})#
Bases:
Widget
- class Karana.WebUI.Dropdown(router: Router, text: str, choices: collections.abc.Sequence[str], on_change: collections.abc.Callable[[SupportsInt | SupportsIndex], None] = None, value_state: State = None)#
Bases:
Widget- setIndex(index: SupportsInt | SupportsIndex) None#
Set the current index of the dropdown
- Parameters:
index – The index of the current dropdown item
- class Karana.WebUI.HttpWsServer(port: SupportsInt | SupportsIndex)#
- broadcastMessage(msg: bytes) None#
Broadcast binary data to all clients.
- close() None#
- defer(callback: collections.abc.Callable[[], None]) None#
- getPort() int#
- getUrl() str#
- printConnectionInfo() None#
Print info to stdout about how to connect
- sendMessage(msg: bytes, client_id: SupportsInt | SupportsIndex) None#
Send binary data to a specific client.
- serveCasData(content: str, url_prefix: str = '', headers: collections.abc.Sequence[tuple[str, str]] = []) str#
- serveCasFile(path: os.PathLike | str | bytes, url_prefix: str = '', headers: collections.abc.Sequence[tuple[str, str]] = []) str#
- serveData(url: str, content: str, headers: collections.abc.Sequence[tuple[str, str]] = []) None#
- serveFile(url: str, path: os.PathLike | str | bytes, headers: collections.abc.Sequence[tuple[str, str]] = []) None#
- setOnConnect(callback: collections.abc.Callable[[SupportsInt | SupportsIndex], None]) None#
- setOnDisconnect(callback: collections.abc.Callable[[SupportsInt | SupportsIndex], None]) None#
- setOnMessage(callback: collections.abc.Callable[[str, SupportsInt | SupportsIndex], None]) None#
- sync() None#
- waitForClients(clients: SupportsInt | SupportsIndex = 1, timeout: SupportsFloat | SupportsIndex = 0.0) bool#
Wait for a given number of clients to connect. :param clients:
Number of clients to wait for
- Parameters:
timeout_seconds –
Timeout, if positive
- Returns:
True if the requested client count was reached
- class Karana.WebUI.InputGroup(router: Router, title: str = '', style: collections.abc.Mapping[str, str] = {})#
Bases:
Widget
- class Karana.WebUI.Layout(router: Router, style: collections.abc.Mapping[str, str] = {})#
Bases:
Widget
- class Karana.WebUI.Markdown(router: Router, text: str, in_line: bool = False)#
Bases:
Widget- setText(text: str) None#
- class Karana.WebUI.QuantityInput(router: Router, text: str, on_change: collections.abc.Callable[[SupportsFloat | SupportsIndex, str], None] = None, quantity_state: State = None)#
Bases:
Widget
- class Karana.WebUI.Router(server: HttpWsServer)#
- class Karana.WebUI.Selection(items: collections.abc.Sequence[Selection] = [])#
- class Item(id: SupportsInt | SupportsIndex, context: Karana.WebUI.Json = None)#
- context: Karana.WebUI.Json#
- property id: int#
- dump() Karana.WebUI.Json#
- class Karana.WebUI.Server(port: SupportsInt | SupportsIndex = 8765)#
- static canFindLocalClientExecutable() bool#
Check if the client executable can be found…. :returns: Whether the client executable can be found
- closeLocalClients() None#
Close all managed clients.
- guessUrl() str#
Generate a URL to connect to the sever.
Note that this URL is a best guess from the point of view of the server. It may not reflect the publicly accessible URL for the server.
- Returns:
The URL guess
- launchLocalClient(*, silent: bool = True) None#
Spawn a managed electron client as a subprocess. :param options:
Parameters struct for the local client.
- onThread() bool#
Check whether the current thread is the io thread :returns: Whether the current thread is the io thread
- port() int#
Get the port the server is bound to. :returns: The port number.
- printConnectionInfo() None#
Print info to stdout about how to connect
- sync() None#
Wait for currently queued tasks to complete
- waitForClients(clients: SupportsInt | SupportsIndex = 1, timeout_seconds: SupportsFloat | SupportsIndex = 0.0) None#
Wait for a given number of clients to connect. :param clients:
Number of clients to wait for.
- Parameters:
timeout –
Timeout in seconds, if positive
- class Karana.WebUI.Slider(router: Router, text: str, on_change: collections.abc.Callable[[SupportsFloat | SupportsIndex], None] = None, opts: SliderOptions = None, value_state: State = None)#
Bases:
Widget- setMax(max: SupportsFloat | SupportsIndex) None#
Set the max value of the slider :param max: The upper bound on possible values
- setMin(min: SupportsFloat | SupportsIndex) None#
Set the min value of the slider :param min: The lower bound on possible values
- setStep(step: SupportsFloat | SupportsIndex) None#
Set the step size of the slider :param step: The step size of values on the slider
- setValue(value: SupportsFloat | SupportsIndex) None#
Set the current value of the slider :param value: The value of the slider
- class Karana.WebUI.SliderOptions#
Widget displaying a Slider triggering a server-side callback
- property log_scale: bool#
Whether to use log scale (currently unsupported)
- property max: float#
Upper bound on possible values
- property min: float#
Lower bound on possible values
- property step: float#
Step size of values on slider
- property tooltip: str#
Tooltip to display on hover (if any)
- class Karana.WebUI.State(router: Router, init_value: Karana.WebUI.Json = None, sync: bool = True)#
- cancelOnChange(id: SupportsInt | SupportsIndex) None#
- get() Karana.WebUI.Json#
- onChange(on_change: collections.abc.Callable[[Karana.WebUI.Json], None]) int#
- set(new_value: Karana.WebUI.Json, skip_id: SupportsInt | SupportsIndex | None = None) None#
- class Karana.WebUI.Toggle(router: Router, text: str, on_toggle: collections.abc.Callable[[bool], None], tooltip: str = '', render_as_button: bool = False, toggle_state: State = None)#
Bases:
Widget- setValue(on: bool) None#
Set the current value of the toggle :param on: Whether the toggle should be set to on
- class Karana.WebUI.TreeView(router: Router, nodes: collections.abc.Sequence[TreeView] = [], edges: collections.abc.Sequence[TreeView] = [], on_select: collections.abc.Callable[[Selection], None] = None, on_refresh: collections.abc.Callable[[], None] = None, selection: State = None)#
Bases:
Widget- class Edge(parent_id: SupportsInt | SupportsIndex, child_id: SupportsInt | SupportsIndex)#
- property child_id: int#
- property parent_id: int#
- class Node(id: SupportsInt | SupportsIndex, label: str = 'unnamed', style_class: str = '', tooltip: str = '', collapsed: bool = False)#
- collapsed: bool#
- label: str#
- style_class: str#
- tooltip: str#
- property id: int#
- refresh() None#
Forces a refresh of the TreeView via its on_refresh() callback, if any was set.
Do not call this from the on_refresh callback itself, since that would create a cycle.
- setNodeLabel(id: SupportsInt | SupportsIndex, label: str) None#
- class Karana.WebUI.Widget(router: Router, esm: Any = '', css: Any = '', states: collections.abc.Mapping[str, State] = {}, style: collections.abc.Mapping[str, str] = {}, init_msg: str = '')#
- addDomClass(dom_class: str) None#
- addToDomRoot() None#
- domId() str#
- removeDomClass(dom_class: str) None#
- setEnabled(enabled: bool) None#
- setVisible(flag: bool) None#