#!/usr/bin/kivy from time import time from kivy.app import App from os.path import dirname, join from kivy.lang import Builder from kivy.properties import NumericProperty, StringProperty, BooleanProperty from kivy.clock import Clock from kivy.animation import Animation from kivy.uix.screenmanager import Screen class ShowcaseScreen(Screen): fullscreen = BooleanProperty(False) def add_widget(self, *args): if 'content' in self.ids: return self.ids.content.add_widget(*args) return super(ShowcaseScreen, self).add_widget(*args) class ShowcaseApp(App): index = NumericProperty(-1) current_title = StringProperty() time = NumericProperty(0) show_sourcecode = BooleanProperty(False) sourcecode = StringProperty() def build(self): Clock.schedule_interval(self._update_clock, 1 / 60.) self.screens = {} self.available_screens = [ 'buttons', 'togglebutton', 'sliders', 'progressbar', 'switchs', 'checkboxs', 'textinputs', 'accordions', 'filechoosers', 'carousels', 'bubbles', 'codeinput', 'dropdown', 'spinner', 'scatter', 'splitter', 'tabbedpanel', 'rstdocument', 'screenmanager'] curdir = dirname(__file__) self.available_screens = [join(curdir, 'data', 'screens', '{}.kv'.format(fn)) for fn in self.available_screens] self.go_next_screen() def go_previous_screen(self): self.index = (self.index - 1) % len(self.available_screens) screen = self.load_screen(self.index) sm = self.root.ids.sm sm.switch_to(screen, direction='right') self.current_title = screen.name self.update_sourcecode() def go_next_screen(self): self.index = (self.index + 1) % len(self.available_screens) screen = self.load_screen(self.index) sm = self.root.ids.sm sm.switch_to(screen, direction='left') self.current_title = screen.name self.update_sourcecode() def load_screen(self, index): if index in self.screens: return self.screens[index] screen = Builder.load_file(self.available_screens[index]) self.screens[index] = screen return screen def read_sourcecode(self): fn = self.available_screens[self.index] with open(fn) as fd: return fd.read() def toggle_source_code(self): self.show_sourcecode = not self.show_sourcecode if self.show_sourcecode: height = self.root.height * .3 else: height = 0 Animation(height=height, d=.3, t='out_quart').start( self.root.ids.sv) self.update_sourcecode() def update_sourcecode(self): if not self.show_sourcecode: return self.root.ids.sourcecode.text = self.read_sourcecode() self.root.ids.sv.scroll_y = 1 def _update_clock(self, dt): self.time = time() if __name__ == '__main__': ShowcaseApp().run()