bec_widgets.utils.bec_dispatcher#

Classes#

BECDispatcher

Utility class to keep track of slots connected to a particular redis connector

QtRedisConnector

Redis connector class. This class is a wrapper around the redis library providing

QtThreadSafeCallback

QtThreadSafeCallback is a wrapper around a callback function to make it thread-safe for Qt.

Module Contents#

class BECDispatcher(client=None, config: str | bec_lib.service_config.ServiceConfig | None = None, gui_id: str = None)#

Utility class to keep track of slots connected to a particular redis connector

connect_slot(slot: collections.abc.Callable, topics: bec_lib.endpoints.EndpointInfo | str | list[bec_lib.endpoints.EndpointInfo] | list[str], cb_info: dict | None = None, **kwargs) None#

Connect widget’s qt slot, so that it is called on new pub/sub topic message.

Parameters:
  • slot (Callable) – A slot method/function that accepts two inputs: content and metadata of the corresponding pub/sub message

  • list[str] (topics EndpointInfo | str | list[EndpointInfo] |) – A topic or list of topics that can typically be acquired via bec_lib.MessageEndpoints

  • cb_info (dict | None) – A dictionary containing information about the callback. Defaults to None.

disconnect_all(*args, **kwargs)#

Disconnect all slots from all topics.

Parameters:
  • *args – Arbitrary positional arguments

  • **kwargs – Arbitrary keyword arguments

disconnect_slot(slot: collections.abc.Callable, topics: bec_lib.endpoints.EndpointInfo | str | list[bec_lib.endpoints.EndpointInfo] | list[str])#

Disconnect a slot from a topic.

Parameters:
  • slot (Callable) – The slot to disconnect

  • list[str] (topics EndpointInfo | str | list[EndpointInfo] |) – A topic or list of topics to unsub from.

disconnect_topics(topics: str | list)#

Disconnect all slots from a topic.

Parameters:

topics (Union[str, list]) – The topic(s) to disconnect from

static generate_unique_identifier(length: int = 4) str#

Generate a unique identifier for the application.

Parameters:

length – The length of the identifier. Defaults to 4.

Returns:

The unique identifier.

Return type:

str

classmethod reset_singleton()#

Reset the singleton instance of the BECDispatcher.

start_cli_server(gui_id: str | None = None)#

Start the CLI server.

Parameters:

gui_id (str, optional) – The GUI ID. Defaults to None. If None, a unique identifier will be generated.

stop_cli_server()#

Stop the CLI server.

cli_server: bec_widgets.utils.rpc_server.RPCServer | None = None#
client: bec_lib.client.BECClient#
class QtRedisConnector(*args, **kwargs)#

Bases: bec_lib.redis_connector.RedisConnector

Redis connector class. This class is a wrapper around the redis library providing a simple interface to send and receive messages from a redis server.

Initialize the connector

Parameters:
  • bootstrap (list) – list of strings in the form “host:port”

  • redis_cls (redis.client, optional) – redis client class. Defaults to the standard client redis.Redis. Must not be an async client.

  • **kwargs – additional keyword arguments to pass to the redis client.

_execute_callback(cb, msg, kwargs)#
class QtThreadSafeCallback(cb: collections.abc.Callable, cb_info: dict | None = None)#

Bases: qtpy.QtCore.QObject

QtThreadSafeCallback is a wrapper around a callback function to make it thread-safe for Qt.

Initialize the QtThreadSafeCallback.

Parameters:
  • cb (Callable) – The callback function to be wrapped.

  • cb_info (dict, optional) – Additional information about the callback. Defaults to None.

__call__(msg_content, metadata)#
__eq__(other)#
__hash__()#
cb#
cb_info = None#
cb_ref#
cb_signal#
topics#