-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmode3.py
171 lines (117 loc) · 4.42 KB
/
mode3.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Discovering
from kivy.core.window import Window
from kivy.uix.widget import Widget
from kivy.app import App
from kivy.clock import Clock
from kivy.animation import Animation
from kivy.uix.stencilview import StencilView
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.button import Button
from kivy.core.image import Image
from kivy.core.text import LabelBase
from kivy.graphics import *
from lib.utils import *
import lib.config, lib.kwargs
# Configuration
TIMEOUT_DELAY = 60 # before it jumps to next mode if not touched
########################################################################
class Discovering(Widget):
def __init__(self, **kwargs):
lib.kwargs.set_kwargs(self, **kwargs)
super(Discovering, self).__init__(**kwargs)
self.all_zones_of_interest_viewedMessageSent = False
self.last_touch = 0
# First item of self.shapes is the background
self.background_path = "images/bgs/" + str(self.clientIdIndex + 1) + ".jpg"
self.bg_img = Image(self.background_path)
with self.canvas:
Color(1,1,1,0.75)
Rectangle(texture=self.bg_img.texture, size=self.bg_img.size, pos=(0,0))
# zones of interest
self.shapes = []
self.descriptions = []
for zi in lib.config.zones_of_interest[self.clientIdIndex]:
self.shapes.append( ZoneOfInterest(img=Image(zi[0]), pos=zi[1]) )
self.descriptions.append( ZoneOfDescription(img=Image(zi[2]), pos=zi[3]) )
for shape in self.shapes:
# add to the view
self.add_widget(shape)
# basis
def start(self):
print "Discovering start() called"
Clock.schedule_once(self.checkIfModeIsCompleted, 1)
self.last_touch = Clock.get_time()
Clock.schedule_interval(self.checkTimeout, 5)
self.pulse()
def stop(self):
print "Discovering stop() called"
self.reset()
self.unpulse()
Clock.unschedule(self.checkIfModeIsCompleted)
Clock.unschedule(self.checkTimeout)
def fadein(self):
pass
def fadeout(self):
pass
def reset(self, instance=False):
self.all_zones_of_interest_viewedMessageSent = False
for shape in self.shapes:
self.remove_widget(self.descFor(shape))
shape.viewed = False
# Custom methods
def checkIfModeIsCompleted(self, instance=False):
# exits if not all shapes are viewed
for shape in self.shapes:
if not shape.viewed:
return
if not self.all_zones_of_interest_viewedMessageSent:
print "All zones of interest viewed"
self.controller.sendMessage("all_zones_of_interest_viewed") # go to next mode
self.all_zones_of_interest_viewedMessageSent = True
def descFor(self, shape):
return self.descriptions[self.shapes.index(shape)]
# Custom callbacks
def pulse(self):
for shape in self.shapes:
Clock.schedule_interval(shape.pulse_widget_alpha, 0.1)
def unpulse(self):
for shape in self.shapes:
Clock.unschedule(shape.pulse_widget_alpha)
def checkTimeout(self, dt=False):
if (Clock.get_time() - self.last_touch) > TIMEOUT_DELAY:
print "Timeout on mode 3, sending message to switch mode."
self.controller.sendMessage("all_zones_of_interest_viewed")
# Kivy callbacks
def on_touch_down(self, touch):
pass
def on_touch_move(self, touch):
pass
def on_touch_up(self, touch):
# check if mode is complete before so I can read the text.
# Next touch will throw a message to the server
self.last_touch = Clock.get_time()
self.checkIfModeIsCompleted()
# Clock.schedule_once(self.checkIfModeIsCompleted(), 5.0)
for shape in self.shapes:
# add interaction
if shape.collide_point(*touch.pos):
if self.children.count(self.descFor(shape)) < 1:
# displays text box
print self.descFor(shape)
self.add_widget(self.descFor(shape))
shape.viewed = True
########################################################################
if __name__ == '__main__':
class DiscoveringApp(App):
def build(self):
base = Widget()
discovering = Discovering()
base.add_widget(discovering)
discovering.start()
# clearbtn = Button(text="clear", font_size=14)
# clearbtn.bind(on_release=discovering.clear)
# base.add_widget(clearbtn)
return base
DiscoveringApp().run()