kivy/examples/demo/showcase/main.py

94 lines
3.0 KiB
Python
Raw Normal View History

2013-09-30 13:31:03 +00:00
#!/usr/bin/kivy
from time import time
2011-01-28 01:02:37 +00:00
from kivy.app import App
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
from kivy.animation import Animation
from kivy.uix.screenmanager import Screen
2012-04-02 19:51:27 +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):
index = NumericProperty(-1)
current_title = StringProperty()
time = NumericProperty(0)
show_sourcecode = BooleanProperty(False)
sourcecode = StringProperty()
2011-01-28 01:02:37 +00:00
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)
2011-04-21 22:52:55 +00:00
self.update_sourcecode()
2011-06-06 14:40:03 +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
2013-03-19 19:13:58 +00:00
def _update_clock(self, dt):
self.time = time()
2011-01-28 01:02:37 +00:00
if __name__ == '__main__':
2011-01-28 01:02:37 +00:00
ShowcaseApp().run()