Package: vsui-client
Volume Segmantics User Interface (Client)This is the client package for VSUI. It provides an interface for interacting with the api of a VSUI server.It is recommended to use the object-oriented interface, although use of the methods in_vsui_client.pyis possible to directly interact with the server. Communication is via a socketio connection to the server. The client only pushes notifications to the server, and cannot receive communications beyond the initial setup.Example Useimportloggingfromvsui_clientimportvsui_process,vsui_initvsui_process is a decorator that provides exception handling. Specifically, it catches all exceptions apart fromKeyboardInterrupt, to communicate the error to the server before the process exits. This includesSystemExitexceptions raised bysys.exit(). This exception handling behavior will only occur in wrapped functions, otherwise errors will result in undefined behaviour with regard to UI user feedback.Setup@vsui_process()defentrypoint_to_my_process():logger=logging.get_logger()vsui_enabled=Trueprocess_id='my_process'logging_component_id='Logs'VSUI=init_vsui(vsui_enabled,process_id,logging_component_id)VSUI.connect()handler=VSUI.get_handler()logger.addHandler(handler)Use in other modulesTo get your current instance of VSUI from another process, it is possible to import it from where it was initialised, but it is recommended to use thevsui_client.get_client()method instead. This will return a reference to the current instance.fromvsui_clientimportget_clientVSUI=get_client()Interacting with the serverThe VSUI server thinks in terms of processes, tasks and components. Your program wrapped by@vsui_process, and using an instance ofVSUIClient, is an example of a process. This should generally be a long-running task which you want to allow a user to setup via a GUI, and receive ongoing feedback from. Consult the VSUI documentation for more information about how to define a process.Use the VSUIClient class to interact with the server api. In the following documentationVSUIis in instance of VSUIClient.connect()This Initiates a connection to a vsui server on the given host and port. The connection is via a socket that remains open until manually disconnected, or the process closes.VSUI.connnect(host:str='host',port:str='port')disconnect()Disconnect the client from the server.VSUI.disconnect()edit element()This method allows you to update the data of a component on the server. The component must be defined in the process definition on the server. The data must be serialisable to json.VSUI.edit_element(element_uid:str,value:dict|str)deactivate_task()This method allows you to signal to the server that the task should be deactivated.VSUI.deactivate_task()notify()This method allows you to send a toast notification to the client. The notification will be displayed in a toast and will disappear after a short time.available types:successerrorinfowarningVSUI.notify(txt:str,type:str)set_task_id()This method allows you to set the task id of the process.VSUI.set_task_id(id:str)set_logging_target()This method allows you to set the component key of the task element that logs should be forwarded to.VSUI.set_logging_target(key:str)get_handler()This method allows you to get the logging handler that forwards logs to the server.VSUI.get_handler()encode_image()This method allows you to encode an image to base64.VSUI.encode_image(arr:np.ndarray,title:str,format:str,figsize:tuple,cmap:str)