"""Application lifecycle events are managed here."""from__future__importannotationsfromdataclassesimportdataclassfrompathlibimportPathfromtypingimportTYPE_CHECKINGfromgaphor.abcimportServiceifTYPE_CHECKING:fromgaphor.applicationimportApplication,Session@dataclassclassServiceInitializedEvent:"""This event is emitted every time a new service has been initialized."""name:strservice:Service@dataclassclassServiceShutdownEvent:"""This event is emitted every time a service has been shut down."""name:strservice:Service@dataclassclassApplicationShutdown:"""This event is emitted from the application when it has been shut down."""application:ApplicationclassSessionCreated:"""The session is emitting this event when it's ready to shut down."""def__init__(self,application:Service,session:Session,filename:Path|None,template:Path|None=None,force:bool=False,interactive:bool=False,):self.application=applicationself.session=sessionself.filename=Path(filename)iffilenameelseNoneself.template=templateself.force=forceself.interactive=interactive@dataclassclassActiveSessionChanged:"""Event emitted when a session becomes the active session."""# NB. This is wrong: it should have the session as argumentservice:ServiceclassSessionShutdownRequested:"""When the application is asked to terminate, it will inform all sessions. The user can then save his/her work. """classSessionShutdown:"""The session is emitting this event when it's ready to shut down."""@dataclassclassModelSaved:filename:Path|None=None
[docs]classTransactionBegin:"""This event denotes the beginning of a transaction. Nested (sub-) transactions should not emit this signal. """def__init__(self,context):self.context=context
[docs]classTransactionCommit:"""This event is emitted when a transaction (toplevel) is successfully committed."""def__init__(self,context):self.context=context
[docs]classTransactionRollback:"""This event is emitted to tell the operation has failed. If a set of operations fail (e.i. due to an exception) the transaction should be marked for rollback. """def__init__(self,context):self.context=context
classActionEnabled:"""Signal if an action can be activated or not."""def__init__(self,action_name:str,enabled:bool)->None:self.scope,self.name=(action_name.split(".",2)if"."inaction_nameelse("win",action_name))self.enabled=enabledclassNotification:"""Inform the user about important events."""def__init__(self,message):self.message=message