## Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending#""" This module supports writing Deephaven application mode Python scripts. """fromtypingimportDictimportjpyfromdeephavenimportDHErrorfromdeephaven._wrapperimportJObjectWrapper,pythonify,javaify_JApplicationContext=jpy.get_type("io.deephaven.appmode.ApplicationContext")_JApplicationState=jpy.get_type("io.deephaven.appmode.ApplicationState")
[docs]classApplicationState(JObjectWrapper):""" The ApplicationState represents the state of an application. """j_object_type=_JApplicationState@propertydefj_object(self)->jpy.JType:returnself.j_app_statedef__init__(self,j_app_state):self.j_app_state=j_app_statedef__repr__(self):returnf"id: {self.j_app_state.id()}, name: {self.j_app_state.name()}"def__str__(self):returnrepr(self)def__getitem__(self,item):item=str(item)j_field=self.j_app_state.getField(item)ifnotj_field:raiseKeyError(item)returnpythonify(j_field.value())def__setitem__(self,key,value):key=str(key)self.j_app_state.setField(key,javaify(value))def__delitem__(self,key):key=str(key)value=self.j_app_state.removeField(key)ifnotvalue:raiseKeyError(key)@propertydeffields(self)->Dict[str,object]:fields={}j_fields=self.j_app_state.listFields()foriinrange(j_fields.size()):j_field=j_fields.get(i)fields[j_field.name()]=pythonify(j_field.value())returnfields
[docs]defget_app_state():""" Get the current application state object. Raises: DHError """try:returnApplicationState(j_app_state=_JApplicationContext.get())exceptExceptionase:raiseDHError(e,"failed to get the application state.")frome