p5control.gui
Qt-based gui elements, which can help you quickly create your own gui. The submodule widgets defines useful widgets.
p5control.gui.cleanupapp
This file defines the class CleanupApp, which subclasses QApplication with some
usefull additions. When the signal aboutToQuit is emitted, widget.cleanup() is called
for every widget, such that you can implement some custom functionality before the widget gets
destroyed, e.g. removing installed callbacks.
- class p5control.gui.cleanupapp.CleanupApp(app_name: str = 'p5control')
Bases:
QApplication- exec(*args, **kwargs)
Overwrites exec to explicitly call the garbage collector after the app has been closed and then logs any leaked_widgets.
- call_cleanup()
Allows for last second cleanup when closing the gui. For all widgets, the method
cleanupis called. This can as an example be use to remove callbacks when closing the gui.
- staticMetaObject = PySide6.QtCore.QMetaObject("CleanupApp" inherits "QApplication": )
p5control.gui.databuffer
This file defines a data buffer which collects data for a dataset on the data server.
- class p5control.gui.databuffer.DataBuffer(dgw: DataGateway, path: str, max_length: int = 1000, down_sample: int = 1)
Bases:
objectDataBuffer which subscribes to a path on the dataserver and buffers the incoming new data.
- Parameters:
dgw (DataGateway) – gateway to the dataserver
path (str) – dataset path in the hdf5 file
max_length (int) – upper limit for the buffer length
down_sample (int) – only safe every down_sample’th value
- callback(arr)
Callback which extends the array. If the buffer gets longer than the maximum length, the starting values are deleted and the buffer length is limited to the maximum length.
- Parameters:
arr (np.array, dict) – the new data to append to the dataset
- cleanup()
Remove callback
- clear()
Clear data buffer
- reload(max_length: int | None = None, down_sample: int | None = None)
update
max_lengthand/ordown_sampleand reload the buffered data from the dataset.
p5control.gui.guidatagw
This file defines GuiDataGateway which extends
p5control.gateway.datagw.DataGateway by opening a dialog if an connection error occurs.
This informs the user about the error and lets him handle the problem while the gui if paused,
such that it will not get into a broken state.
Since rpyc often only returns BaseNetref, which send and receive data if e.g.
attributes are accessed, we define the class WrapNetref to wrap these and catch
connection errors which might arise.
- class p5control.gui.guidatagw.WrapNetref(netref, dgw)
Bases:
objectWraps rpyc netref such that all requests made are handled in try catch expressions and a prompt is opened if the connection is closed.
- This class may not implement all necessary behavior, implemented:
iteration
class is the one behind the netref
netref can be pickled
- exception p5control.gui.guidatagw.GuiDataGatewayError
Bases:
Exceptionrelated to errors specifig to GuiDataGateway
- class p5control.gui.guidatagw.GuiDataGateway(addr: str = 'localhost', port: int = 30000, conn_timeout: float = 0.0, allow_callback: bool = False)
Bases:
DataGatewayWrapper for DataGateway to use in a GUI application.
Opens a message box if the connection to the dataserver fails and assures that the request returns something.
This is not thread safe, make sure that this gateway is only used by a single thread !!
- connect(config=None)
Attempt connection to the rpyc server.
- Parameters:
config (dict = None) – can be used to configure the connection to the rpyc server.
- Raises:
BaseGatewayError – Connection to the Server failed
- network_safe_getattr(obj: Any, attr: Any, call: bool = False)
Tries
getattr(obj, attr)and handles any connection problems, assures that the object is returned or the application is closed. Use this method to access attributes of any netref in a gui application.
- connect_to_filename(error: Exception, filename: str)
Blocks until the gateway is connected again, to a data server which serves the same hdf5 file as to one connection was lost to. Any connection with a different hdf5 file is rejected because it might not have the same content. The gui probably has loaded some references to this content and will break. Thus the connection is closed and the user is asked to host the old file again.
- Parameters:
error (Exception) – the error which made reconnecting necessary
filename (str) – the hdf5 file the data server needs to host to be an accepted connection.
- message_reconnect(error: Exception, filename: str)
return
QMessageBoxwhich informs the user about the lost connection to the data server and lets him press retry.- Parameters:
error (Exception) – the exception which led to the message box to be shown
filename (str) – the hdf5 file the data server needs to host to be an accepted connection.
- get_data(path, indices: slice = (), field: str | None = None)
Overwrite
p5control.gateway.datagw.DataGateway.get_data()to include gui error handling.
- register_callback(path, func, is_group: bool = False)
Overwrite
p5control.gateway.datagw.DataGateway.register_callback()to include gui error handling.
p5control.gui.guisettings
This module defines settings which are common througout the gui elements.
- p5control.gui.guisettings.DATA_BUFFER_MAX_LENGTH = 1000
max length for data buffer
- p5control.gui.guisettings.DOWN_SAMPLE = 1
Can be used to only request every DOWN_SAMPLEth item from the dataset.
Use both settings in conjunction to control the performance of the gui in order to not process to much data at any point.