2013-09-30 13:31:03 +00:00
|
|
|
#!/usr/bin/kivy
|
2013-08-12 08:45:54 +00:00
|
|
|
from time import time
|
2011-01-28 01:02:37 +00:00
|
|
|
from kivy.app import App
|
2013-08-12 08:45:54 +00:00
|
|
|
from os.path import dirname, join
|
|
|
|
from kivy.lang import Builder
|
|
|
|
from kivy.properties import NumericProperty, StringProperty, BooleanProperty
|
2013-03-19 19:13:58 +00:00
|
|
|
from kivy.clock import Clock
|
2013-08-12 08:45:54 +00:00
|
|
|
from kivy.animation import Animation
|
|
|
|
from kivy.uix.screenmanager import Screen
|
2012-04-02 19:51:27 +00:00
|
|
|
|
|
|
|
|
2013-08-12 08:45:54 +00:00
|
|
|
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)
|
|
|
|
|
2013-03-19 19:13:58 +00:00
|
|
|
|
2011-01-28 01:02:37 +00:00
|
|
|
class ShowcaseApp(App):
|
|
|
|
|
2013-08-12 08:45:54 +00:00
|
|
|
index = NumericProperty(-1)
|
|
|
|
current_title = StringProperty()
|
|
|
|
time = NumericProperty(0)
|
|
|
|
show_sourcecode = BooleanProperty(False)
|
|
|
|
sourcecode = StringProperty()
|
2012-03-11 01:16:02 +00:00
|
|
|
|
2011-01-28 01:02:37 +00:00
|
|
|
def build(self):
|
2013-08-12 08:45:54 +00:00
|
|
|
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
|
2013-08-14 08:36:21 +00:00
|
|
|
sm.switch_to(screen, direction='right')
|
2013-08-12 08:45:54 +00:00
|
|
|
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
|
2013-08-14 08:36:21 +00:00
|
|
|
sm.switch_to(screen, direction='left')
|
2013-08-12 08:45:54 +00:00
|
|
|
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
|
2013-03-27 17:47:34 +00:00
|
|
|
|
2013-08-12 08:45:54 +00:00
|
|
|
Animation(height=height, d=.3, t='out_quart').start(
|
|
|
|
self.root.ids.sv)
|
2011-04-21 22:52:55 +00:00
|
|
|
|
2013-08-12 08:45:54 +00:00
|
|
|
self.update_sourcecode()
|
2011-06-06 14:40:03 +00:00
|
|
|
|
2013-08-12 08:45:54 +00:00
|
|
|
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
|
2011-03-21 16:04:50 +00:00
|
|
|
|
2013-03-19 19:13:58 +00:00
|
|
|
|
2013-08-12 08:45:54 +00:00
|
|
|
def _update_clock(self, dt):
|
|
|
|
self.time = time()
|
2011-01-28 01:02:37 +00:00
|
|
|
|
2012-07-29 19:43:01 +00:00
|
|
|
if __name__ == '__main__':
|
2011-01-28 01:02:37 +00:00
|
|
|
ShowcaseApp().run()
|