<s> '''<STR_LIT>''' <EOL> from time import time <EOL> from kivy . app import App <EOL> from os . path import dirname , join <EOL> from kivy . lang import Builder <EOL> from kivy . properties import NumericProperty , StringProperty , BooleanProperty , ListProperty <EOL> from kivy . clock import Clock <EOL> from kivy . animation import Animation <EOL> from kivy . uix . screenmanager import Screen <EOL> class ShowcaseScreen ( Screen ) : <EOL> fullscreen = BooleanProperty ( False ) <EOL> def add_widget ( self , * args ) : <EOL> if '<STR_LIT:content>' in self . ids : <EOL> return self . ids . content . add_widget ( * args ) <EOL> return super ( ShowcaseScreen , self ) . add_widget ( * args ) <EOL> class ShowcaseApp ( App ) : <EOL> index = NumericProperty ( - <NUM_LIT:1> ) <EOL> current_title = StringProperty ( ) <EOL> time = NumericProperty ( <NUM_LIT:0> ) <EOL> show_sourcecode = BooleanProperty ( False ) <EOL> sourcecode = StringProperty ( ) <EOL> screen_names = ListProperty ( [ ] ) <EOL> hierarchy = ListProperty ( [ ] ) <EOL> def build ( self ) : <EOL> self . title = '<STR_LIT>' <EOL> Clock . schedule_interval ( self . _update_clock , <NUM_LIT:1> / <NUM_LIT> ) <EOL> self . screens = { } <EOL> self . available_screens = sorted ( [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . screen_names = self . available_screens <EOL> curdir = dirname ( __file__ ) <EOL> self . available_screens = [ join ( curdir , '<STR_LIT:data>' , '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( fn ) ) for fn in self . available_screens ] <EOL> self . go_next_screen ( ) <EOL> def on_pause ( self ) : <EOL> return True <EOL> def on_resume ( self ) : <EOL> pass <EOL> def on_current_title ( self , instance , value ) : <EOL> self . root . ids . spnr . text = value <EOL> def go_previous_screen ( self ) : <EOL> self . index = ( self . index - <NUM_LIT:1> ) % len ( self . available_screens ) <EOL> screen = self . load_screen ( self . index ) <EOL> sm = self . root . ids . sm <EOL> sm . switch_to ( screen , direction = '<STR_LIT:right>' ) <EOL> self . current_title = screen . name <EOL> self . update_sourcecode ( ) <EOL> def go_next_screen ( self ) : <EOL> self . index = ( self . index + <NUM_LIT:1> ) % len ( self . available_screens ) <EOL> screen = self . load_screen ( self . index ) <EOL> sm = self . root . ids . sm <EOL> sm . switch_to ( screen , direction = '<STR_LIT:left>' ) <EOL> self . current_title = screen . name <EOL> self . update_sourcecode ( ) <EOL> def go_screen ( self , idx ) : <EOL> self . index = idx <EOL> self . root . ids . sm . switch_to ( self . load_screen ( idx ) , direction = '<STR_LIT:left>' ) <EOL> self . update_sourcecode ( ) <EOL> def go_hierarchy_previous ( self ) : <EOL> ahr = self . hierarchy <EOL> if len ( ahr ) == <NUM_LIT:1> : <EOL> return <EOL> if ahr : <EOL> ahr . pop ( ) <EOL> if ahr : <EOL> idx = ahr . pop ( ) <EOL> self . go_screen ( idx ) <EOL> def load_screen ( self , index ) : <EOL> if index in self . screens : <EOL> return self . screens [ index ] <EOL> screen = Builder . load_file ( self . available_screens [ index ] . lower ( ) ) <EOL> self . screens [ index ] = screen <EOL> return screen <EOL> def read_sourcecode ( self ) : <EOL> fn = self . available_screens [ self . index ] . lower ( ) <EOL> with open ( fn ) as fd : <EOL> return fd . read ( ) <EOL> def toggle_source_code ( self ) : <EOL> self . show_sourcecode = not self . show_sourcecode <EOL> if self . show_sourcecode : <EOL> height = self . root . height * <NUM_LIT> <EOL> else : <EOL> height = <NUM_LIT:0> <EOL> Animation ( height = height , d = <NUM_LIT> , t = '<STR_LIT>' ) . start ( <EOL> self . root . ids . sv ) <EOL> self . update_sourcecode ( ) <EOL> def update_sourcecode ( self ) : <EOL> if not self . show_sourcecode : <EOL> self . root . ids . sourcecode . focus = False <EOL> return <EOL> self . root . ids . sourcecode . text = self . read_sourcecode ( ) <EOL> self . root . ids . sv . scroll_y = <NUM_LIT:1> <EOL> def showcase_floatlayout ( self , layout ) : <EOL> def add_button ( * t ) : <EOL> if not layout . get_parent_window ( ) : <EOL> return <EOL> if len ( layout . children ) > <NUM_LIT:5> : <EOL> layout . clear_widgets ( ) <EOL> layout . add_widget ( Builder . load_string ( '''<STR_LIT>''' ) ) <EOL> Clock . schedule_once ( add_button , <NUM_LIT:1> ) <EOL> Clock . schedule_once ( add_button ) <EOL> def showcase_boxlayout ( self , layout ) : <EOL> def add_button ( * t ) : <EOL> if not layout . get_parent_window ( ) : <EOL> return <EOL> if len ( layout . children ) > <NUM_LIT:5> : <EOL> layout . orientation = '<STR_LIT>' if layout . orientation == '<STR_LIT>' else '<STR_LIT>' <EOL> layout . clear_widgets ( ) <EOL> layout . add_widget ( Builder . load_string ( '''<STR_LIT>''' ) ) <EOL> Clock . schedule_once ( add_button , <NUM_LIT:1> ) <EOL> Clock . schedule_once ( add_button ) <EOL> def showcase_gridlayout ( self , layout ) : <EOL> def add_button ( * t ) : <EOL> if not layout . get_parent_window ( ) : <EOL> return <EOL> if len ( layout . children ) > <NUM_LIT:15> : <EOL> layout . rows = <NUM_LIT:3> if layout . rows is None else None <EOL> layout . cols = None if layout . rows == <NUM_LIT:3> else <NUM_LIT:3> <EOL> layout . clear_widgets ( ) <EOL> layout . add_widget ( Builder . load_string ( '''<STR_LIT>''' ) ) <EOL> Clock . schedule_once ( add_button , <NUM_LIT:1> ) <EOL> Clock . schedule_once ( add_button ) <EOL> def showcase_stacklayout ( self , layout ) : <EOL> orientations = ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> def add_button ( * t ) : <EOL> if not layout . get_parent_window ( ) : <EOL> return <EOL> if len ( layout . children ) > <NUM_LIT:11> : <EOL> layout . clear_widgets ( ) <EOL> cur_orientation = orientations . index ( layout . orientation ) <EOL> layout . orientation = orientations [ cur_orientation - <NUM_LIT:1> ] <EOL> layout . add_widget ( Builder . load_string ( '''<STR_LIT>''' ) ) <EOL> Clock . schedule_once ( add_button , <NUM_LIT:1> ) <EOL> Clock . schedule_once ( add_button ) <EOL> def showcase_anchorlayout ( self , layout ) : <EOL> def change_anchor ( self , * l ) : <EOL> if not layout . get_parent_window ( ) : <EOL> return <EOL> anchor_x = ( '<STR_LIT:left>' , '<STR_LIT>' , '<STR_LIT:right>' ) <EOL> anchor_y = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if layout . anchor_x == '<STR_LIT:left>' : <EOL> layout . anchor_y = anchor_y [ anchor_y . index ( layout . anchor_y ) - <NUM_LIT:1> ] <EOL> layout . anchor_x = anchor_x [ anchor_x . index ( layout . anchor_x ) - <NUM_LIT:1> ] <EOL> Clock . schedule_once ( change_anchor , <NUM_LIT:1> ) <EOL> Clock . schedule_once ( change_anchor , <NUM_LIT:1> ) <EOL> def _update_clock ( self , dt ) : <EOL> self . time = time ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> ShowcaseApp ( ) . run ( ) </s>
