bec_widgets.utils.bec_dispatcher ================================ .. py:module:: bec_widgets.utils.bec_dispatcher Classes ------- .. autoapisummary:: bec_widgets.utils.bec_dispatcher.BECDispatcher bec_widgets.utils.bec_dispatcher.QtRedisConnector bec_widgets.utils.bec_dispatcher.QtThreadSafeCallback Module Contents --------------- .. py: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 .. py:method:: 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. :param slot: A slot method/function that accepts two inputs: content and metadata of the corresponding pub/sub message :type slot: Callable :param topics EndpointInfo | str | list[EndpointInfo] | list[str]: A topic or list of topics that can typically be acquired via bec_lib.MessageEndpoints :param cb_info: A dictionary containing information about the callback. Defaults to None. :type cb_info: dict | None .. py:method:: disconnect_all(*args, **kwargs) Disconnect all slots from all topics. :param \*args: Arbitrary positional arguments :param \*\*kwargs: Arbitrary keyword arguments .. py:method:: 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. :param slot: The slot to disconnect :type slot: Callable :param topics EndpointInfo | str | list[EndpointInfo] | list[str]: A topic or list of topics to unsub from. .. py:method:: disconnect_topics(topics: Union[str, list]) Disconnect all slots from a topic. :param topics: The topic(s) to disconnect from :type topics: Union[str, list] .. py:method:: generate_unique_identifier(length: int = 4) -> str :staticmethod: Generate a unique identifier for the application. :param length: The length of the identifier. Defaults to 4. :returns: The unique identifier. :rtype: str .. py:method:: reset_singleton() :classmethod: Reset the singleton instance of the BECDispatcher. .. py:method:: start_cli_server(gui_id: str | None = None) Start the CLI server. :param gui_id: The GUI ID. Defaults to None. If None, a unique identifier will be generated. :type gui_id: str, optional .. py:method:: stop_cli_server() Stop the CLI server. .. py:attribute:: cli_server :type: bec_widgets.utils.rpc_server.RPCServer | None :value: None .. py:attribute:: client :type: bec_lib.client.BECClient .. py:class:: QtRedisConnector(*args, **kwargs) Bases: :py:obj:`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 :param bootstrap: list of strings in the form "host:port" :type bootstrap: list :param redis_cls: redis client class. Defaults to the standard client redis.Redis. Must not be an async client. :type redis_cls: redis.client, optional :param \*\*kwargs: additional keyword arguments to pass to the redis client. .. py:method:: _execute_callback(cb, msg, kwargs) .. py:class:: QtThreadSafeCallback(cb: collections.abc.Callable, cb_info: dict | None = None) Bases: :py:obj:`qtpy.QtCore.QObject` QtThreadSafeCallback is a wrapper around a callback function to make it thread-safe for Qt. Initialize the QtThreadSafeCallback. :param cb: The callback function to be wrapped. :type cb: Callable :param cb_info: Additional information about the callback. Defaults to None. :type cb_info: dict, optional .. py:method:: __call__(msg_content, metadata) .. py:method:: __eq__(other) .. py:method:: __hash__() .. py:attribute:: cb .. py:attribute:: cb_info :value: None .. py:attribute:: cb_ref .. py:attribute:: cb_signal .. py:attribute:: topics