Scritp the context ================== Context objects are accessible from a Python script. ## Load configuration from JSON file A context configuration can be loaded from a JSON file using the [*load*](../../../argaze.md/#argaze.load) function. ```python from argaze import load # Load a context with load(configuration_filepath) as context: while context.is_running(): # Do something with context ... # Wait some time eventually ... ``` !!! note The **with** statement enables context by calling its **enter** method then ensures that its **exit** method is always called at the end. ## Load configuration from dictionary A context configuration can be loaded from a Python dictionary using the [*from_dict*](../../../argaze.md/#argaze.DataFeatures.from_dict) function. ```python from argaze import DataFeatures import my_package # Set working directory to enable relative file path loading DataFeatures.set_working_directory('path/to/folder') # Edit a dict with context configuration configuration = { "name": "My context", "parameter": ..., "pipeline": ... } # Load a context from a package with DataFeatures.from_dict(my_package.MyContext, configuration) as context: while context.is_running(): # Do something with context ... # Wait some time eventually ... ``` ## Manage context Check the context or the pipeline type to adapt features. ```python from argaze import ArFeatures # Assuming the context is loaded and is running ... # Check context type # Live processing case: calibration method is available if issubclass(type(context), ArFeatures.LiveProcessingContext): ... # Post processing case: more playback methods are available if issubclass(type(context), ArFeatures.PostProcessingContext): ... # Check pipeline type # Screen-based case: only gaze positions are processes if issubclass(type(context.pipeline), ArFeatures.ArFrame): ... # Head-mounted case: camera images also processes if issubclass(type(context.pipeline), ArFeatures.ArCamera): ... ``` ## Display context The context image can be displayed in low priority to not block pipeline processing. ```python # Assuming the context is loaded and is running ... # Display context if the pipeline is available try: ... = context.image(wait = False) except DataFeatures.SharedObjectBusy: pass ```