-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmode4.py
140 lines (96 loc) · 3.98 KB
/
mode4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Credits
from kivy.core.window import Window
from kivy.uix.widget import Widget
from kivy.app import App
from kivy.clock import Clock, ClockBase
from kivy.animation import Animation
from kivy.uix.boxlayout import BoxLayout
from kivy.core.image import Image
from kivy.uix.label import Label
from kivy.graphics import *
from lib.utils import ZoneOfInterest
import lib.config, lib.kwargs
# Configuration
TOUCH_DELAY = 15.0 # seconds before a touch switch to mode 1
PERSPECTIVE_DELAY = 10.0 # seconds before switching the background to perspective
CREDIT_DELAY = 10.0 # seconds before it displays credits
SCREENSAVER_DELAY = 30.0 # before jumping to next mode, mode 1
########################################################################
class Credits(Widget):
def __init__(self, **kwargs):
lib.kwargs.set_kwargs(self, **kwargs)
super(Credits, self).__init__(**kwargs)
self.credits_touchedMessageSent = False
self.credits_timeoutMessageSent = False
self.last_runtime = 0.0
self.credits = ZoneOfInterest(img=Image("images/credits.png"), pos=(11, 200))
self.credits.alpha = 0.99
self.label = Label(text="Composition VIII, Kandinsky",
font_size=25,
color=(0,0,0,1),
pos=(600,25),
font_name="fonts/Akkurat.ttf")
self.background_path = "images/bgs/" + str(self.clientIdIndex + 1) + ".jpg"
self.perspective_path = "images/perspectives/" + str(self.clientIdIndex + 1) + ".jpg"
self.background = ZoneOfInterest(img=Image(self.background_path))
self.perspective = ZoneOfInterest(img=Image(self.perspective_path))
# basis
def start(self):
print "Credits start() called"
self.background.alpha = 0.0
self.perspective.alpha = 0.0
self.add_widget(self.background)
self.add_widget(self.perspective)
self.background.fadeIn()
if self.clientIdIndex == 0:
self.add_widget(self.label)
Clock.schedule_once(self.switchToPerspective, PERSPECTIVE_DELAY)
if self.clientIdIndex == 3:
Clock.schedule_once(self.displayCredits, CREDIT_DELAY)
Clock.schedule_once(self.announceTheEnd, SCREENSAVER_DELAY) # restart screensaver
self.last_runtime = Clock.get_boottime()
def stop(self):
print "Credits stop() called"
self.remove_widget(self.background)
self.remove_widget(self.perspective)
self.remove_widget(self.credits)
self.reset()
Clock.unschedule(self.switchToPerspective)
Clock.unschedule(self.displayCredits)
Clock.unschedule(self.announceTheEnd)
def reset(self):
self.credits_touchedMessageSent = False
self.credits_timeoutMessageSent = False
# Custom methods
# Custom callbacks
def switchToPerspective(self, instance=False):
self.remove_widget(self.label)
self.background.alpha = 0.99
self.background.fadeOut()
self.perspective.alpha = 0.0
self.perspective.fadeIn()
def displayCredits(self, instance=False):
self.add_widget(self.credits)
def announceTheEnd(self, instance=False):
if not self.credits_timeoutMessageSent:
print "This is the end."
self.controller.sendMessage("credits_timeout") # go back to mode1, ScreenSaver
self.credits_timeoutMessageSent = True
# Kivy callbacks
def on_touch_down(self, touch):
# Doesn't do anything if touched within the tenth first seconds.
if abs(Clock.get_boottime() - self.last_runtime) > TOUCH_DELAY:
if not self.credits_touchedMessageSent:
print "Credits touched at, ", Clock.get_boottime()
self.controller.sendMessage("credits_touched") # go back to mode2, Learning
self.credits_touchedMessageSent = True
########################################################################
if __name__ == '__main__':
class CreditsApp(App):
def build(self):
base = Widget()
credit = Credits()
base.add_widget(credit)
credit.start()
return base
CreditsApp().run()