Skip to content

Instantly share code, notes, and snippets.

@rainbowdesign
Created February 7, 2014 21:55
Show Gist options
  • Save rainbowdesign/8872759 to your computer and use it in GitHub Desktop.
Save rainbowdesign/8872759 to your computer and use it in GitHub Desktop.
Slideshow error
#To use it you need to put pictures into /pictures/
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition, SwapTransition,WipeTransition
from kivy.uix.image import AsyncImage
from kivy.uix.boxlayout import BoxLayout
import kivy
from kivy.uix.widget import Widget
from kivy.app import App
import os, glob
from kivy.lang import Builder
from kivy.uix.label import Label
import time
from threading import Timer
from random import random
kvs='''
BoxLayout:
orientation: 'vertical'
BoxLayout:
id: globebox
ScreenManager:
id: sm1
Screen:
name: '1'
BoxLayout:
id: box1
Screen:
name: '2'
BoxLayout:
id: box2
Screen:
name: '3'
BoxLayout:
id: box3
<FullImage>:
canvas:
Color:
rgb: (1, 1, 1)
Rectangle:
texture: self.texture
size: self.size
pos: self.pos
'''
root = Builder.load_string(kvs)
class FullImage(AsyncImage):
pass
filelist = glob.glob('pictures/*')
print filelist
def picpic():
print filelist
for num, pic in enumerate(filelist):
ran = random()*len(filelist)
if num+1 > ran: return pic
root.ids.sm1.transition=FadeTransition()
def chsc():
aaa= picpic()
print 'returns', aaa
aaa=FullImage(source = str(aaa))
print 'screen', root.ids.sm1.current
if root.ids.sm1.current == '1':
root.ids.box2.add_widget(aaa)
root.ids.sm1.current = '2'
root.ids.box3.clear_widgets()
print 'change to sc2'
elif root.ids.sm1.current == '2':
root.ids.box3.add_widget(aaa)
root.ids.sm1.current = '3'
root.ids.box1.clear_widgets()
print 'change to sc1'
elif root.ids.sm1.current == '3':
root.ids.box1.add_widget(aaa)
root.ids.sm1.current = '1'
root.ids.box2.clear_widgets()
print 'change to sc2'
print 'screen', root.ids.sm1.current
Timer(1, timing).start()
def timing():
if root.ids.sm1.current_screen.transition_progress> 0.90:
chsc()
class MainApp(App): #Main function#
def build(self):
chsc()
return root
if __name__ == '__main__':
MainApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment