bec_widgets.cli.client_utils#

Client utilities for the BEC GUI.

Attributes#

Classes#

AvailableWidgetsNamespace

Namespace for available widgets in the BEC GUI.

BECGuiClient

BEC GUI client class. Container for GUI applications within Python.

RepeatTimer

RepeatTimer class.

WidgetNameSpace

Functions#

_filter_output(→ str)

Filter out the output from the process.

_get_output(→ None)

_start_plot_process(→ tuple[subprocess.Popen[str], ...)

Start the plot in a new process.

wait_for_server(client)

Context manager to wait for the server to start.

Module Contents#

class AvailableWidgetsNamespace#

Namespace for available widgets in the BEC GUI.

__repr__()#
class BECGuiClient(**kwargs)#

Bases: bec_widgets.cli.rpc.rpc_base.RPCBase

BEC GUI client class. Container for GUI applications within Python.

_add_widget(state: dict, parent: object) bec_widgets.cli.rpc.rpc_base.RPCReference | None#

Add a widget to the namespace

Parameters:
  • state (dict) – The state of the widget from the _server_registry.

  • parent (object) – The parent object.

_check_if_server_is_alive()#

Checks if the process is alive

_do_raise_all()#

Bring GUI windows to the front.

_do_show_all()#
_gui_post_startup()#
static _handle_registry_update(msg: dict[str, bec_lib.messages.GUIRegistryStateMessage], parent: BECGuiClient) None#
_hide_all()#
_new_impl(*, name: str | None, geometry: tuple[int, int, int, int] | None, launch_script: str, startup_profile: str | Literal['restore', 'skip'] | None, **kwargs)#
_raise_all()#
_show_all()#
_start(wait: bool = False) None#
_start_server(wait: bool = False) None#

Start the GUI server, and execute callback when it is launched

_update_dynamic_namespace(server_registry: dict)#

Update the dynamic name space with the given server registry. Setting the server registry to an empty dictionary will remove all widgets from the namespace.

Parameters:

server_registry (dict) – The server registry

change_theme(theme: Literal['light', 'dark'] | None = None) None#

Apply a GUI theme or toggle between dark and light.

Parameters:

theme (Literal["light", "dark"] | None) – Theme to apply. If None, the current theme is fetched from the GUI and toggled.

close()#

Deprecated. Use kill_server() instead.

connect_to_gui_server(gui_id: str) None#

Connect to a GUI server

delete(name: str) None#

Delete a dock area and its parent window.

Parameters:

name (str) – The name of the dock area.

delete_all() None#

Delete all dock areas.

hide()#

Hide the GUI window.

kill_server() None#

Kill the GUI server.

new(name: str | None = None, wait: bool = True, geometry: tuple[int, int, int, int] | None = None, launch_script: str = 'dock_area', startup_profile: str | Literal['restore', 'skip'] | None = None, **kwargs) bec_widgets.cli.client.AdvancedDockArea#

Create a new top-level dock area.

Parameters:
  • name (str, optional) – The name of the dock area. Defaults to None.

  • wait (bool, optional) – Whether to wait for the server to start. Defaults to True.

  • geometry (tuple[int, int, int, int] | None) – The geometry of the dock area (pos_x, pos_y, w, h).

  • launch_script (str) – The launch script to use. Defaults to “dock_area”.

  • startup_profile (str | Literal["restore", "skip"] | None) –

    Startup mode for the dock area:

    • None: start in transient empty workspace

    • ”restore”: restore last-used profile

    • ”skip”: skip profile initialization

    • ”<name>”: load the named profile

  • **kwargs – Additional keyword arguments passed to the dock area.

Returns:

The new dock area.

Return type:

client.AdvancedDockArea

Examples

>>> gui.new()  # Start with an empty unsaved workspace
>>> gui.new(startup_profile="restore")  # Restore last profile
>>> gui.new(startup_profile="my_profile")  # Load explicit profile
raise_window(wait: bool = True) None#

Bring GUI windows to the front. If the GUI server is not running, it will be started.

Parameters:

wait (bool) – Whether to wait for the server to start. Defaults to True.

show(wait=True) None#

Show the GUI window. If the GUI server is not running, it will be started.

Parameters:

wait (bool) – Whether to wait for the server to start. Defaults to True.

start(wait: bool = False) None#

Start the GUI server.

available_widgets#
property launcher: bec_widgets.cli.rpc.rpc_base.RPCBase#

The launcher object.

property window_list: list#

List with dock areas in the GUI.

property windows: dict#

Dictionary with dock areas in the GUI.

class RepeatTimer(interval, function, args=None, kwargs=None)#

Bases: threading.Timer

RepeatTimer class.

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is a list or tuple of arguments for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

run()#

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class WidgetNameSpace#
__repr__()#
_filter_output(output: str) str#

Filter out the output from the process.

_get_output(process, logger) None#
_start_plot_process(gui_id: str, gui_class_id: str, config: dict | str, gui_class: str = 'dock_area', logger=None) tuple[subprocess.Popen[str], threading.Thread | None]#

Start the plot in a new process.

Logger must be a logger object with “debug” and “error” functions, or it can be left to “None” as default. None means output from the process will not be captured.

wait_for_server(client: BECGuiClient)#

Context manager to wait for the server to start.

GUIRegistryStateMessage#
IGNORE_WIDGETS = ['LaunchWindow']#
type RegistryState = dict[Literal['gui_id', 'name', 'widget_class', 'config', '__rpc__', 'container_proxy'], str | bool | dict]#
config#