Package: pyllot
Application routing with event-driven finite-state machine.DocumentationSimple example# main.pyfromtypingimportNamedTuplefrompyllotimport(Router,ScreenBase,ScreenPresenting,ScreensFactoryBase,Transition,TransitionDirection,)classMyScreen(ScreenBase):defwill_present(self)->None:print(f'Will present "{self.screen_name}"')defdid_present(self)->None:print(f'Did present "{self.screen_name}"')defwill_disappear(self)->None:print(f'Will disappear "{self.screen_name}"')classHomeScreen(MyScreen):@propertydefscreen_name(self)->str:return"home"classVideoPlayerScreen(MyScreen):@propertydefscreen_name(self)->str:return"video_player"classState(NamedTuple):current_video_url:str|Nonedefhas_current_video(state:State)->bool:returnstate.current_video_urlisnotNoneclassMyPresenter(ScreenPresenting[MyScreen]):defpresent(self,screen:MyScreen)->None:print(f'Presenting "{screen.screen_name}"')classMyScreensFactory(ScreensFactoryBase[MyScreen]):defcreate(self,screen_name:str)->MyScreen:print(f'Creating screen "{screen_name}"')matchscreen_name:case"home":returnHomeScreen()case"video_player":returnVideoPlayerScreen()case_:raiseNotImplementedErrorHOME_TO_VIDEO_PLAYER:Transition[State]=Transition(source="home",destination="video_player",direction=TransitionDirection.PUSH,condition=has_current_video,)VIDEO_PLAYER_TO_HOME:Transition[State]=Transition(source="video_player",destination="home",direction=TransitionDirection.POP,condition=lambdastate:nothas_current_video(state),)defmain()->None:router:Router[State,MyScreen]=Router(initial_screen=HomeScreen(),presenter=MyPresenter(),screens_factory=MyScreensFactory(),)router.add_transition(Transition(source="home",destination="video_player",direction=TransitionDirection.PUSH,condition=has_current_video,))router.add_transition(Transition(source="video_player",destination="home",direction=TransitionDirection.POP,condition=lambdastate:nothas_current_video(state),))print("Presenting video player...")router.on_state(State(current_video_url="https://tombartk.com/funny_cats.mp4"))print("\nGoing back to home screen...")router.on_state(State(current_video_url=None))if__name__=="__main__":main()$python3main.py

Presentingvideoplayer...
Creatingscreen"video_player"Willdisappear"home"Willpresent"video_player"Presenting"video_player"Didpresent"video_player"Goingbacktohomescreen...
Willdisappear"video_player"Willpresent"home"Presenting"home"Didpresent"home"InstallationPyllot is available aspylloton PyPI:pipinstallpyllotUsageFor detailed quickstart and API reference, visit theDocumentation.LicenseCopyright (C) 2023 tombartk 

This program is free software: you can redistribute it and/or modify it under the terms
of the GNU Affero General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program.
If not, see https://www.gnu.org/licenses/.