forked from bitcraft/PURIKURA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kiosk.py
executable file
·283 lines (206 loc) · 8.41 KB
/
kiosk.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/env python
import os
os.chdir('/home/mjolnir/git/PURIKURA/')
import kivy
kivy.require('1.5.0')
from kivy.config import Config
DEFAULT_VKEYBOARD_LAYOUT = 'qwerty'
DEFAULT_VKEYBOARD_LAYOUT = 'email'
MAXIMUM_PRINTS = 3
# set keyboard behaviour to be a lit like ios
Config.set('kivy', 'keyboard_mode', 'dock')
Config.set('kivy', 'keyboard_layout', DEFAULT_VKEYBOARD_LAYOUT)
# for the touch screen controller monitor
Config.set('graphics', 'fullscreen', True)
Config.set('graphics', 'width', '1280')
Config.set('graphics', 'height', '1024')
Config.set('graphics', 'show_cursor', False)
Config.set('graphics', 'show_mousecursor', False)
# performance tweaks
Config.set('graphics', 'multisamples', 0)
import os, sys, glob, math
from kivy.animation import Animation
from kivy.app import App
from kivy.factory import Factory
from kivy.lang import Builder, Parser, ParserException
from kivy.properties import *
from kivy.uix.scrollview import ScrollView
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.codeinput import CodeInput
from kivy.animation import Animation
from kivy.clock import Clock
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.screenmanager import SlideTransition, TransitionBase
from kivy.loader import Loader
from kivy.core.image import Image as CoreImage
from kivy.uix.image import Image
from kivy.factory import Factory
thumbnails = "/home/mjolnir/events/kali-joshua/small"
detail = "/home/mjolnir/events/kali-joshua/medium"
def handle_print_number_error(value):
if value < 0:
return 0
elif value > MAXIMUM_PRINTS:
return MAXIMUM_PRINTS
def get_images():
return glob.glob('{0}/*.JPG'.format(thumbnails))
Builder.load_file('kiosk.kv')
# hack search method because one is not included with kivy
def search(root, uniqueid):
children = root.children[:]
while children:
child = children.pop()
children.extend(child.children[:])
try:
child.uniqueid
except:
continue
else:
if child.uniqueid == uniqueid:
return child
return None
def show_cursor(widget, arg):
pygame.mouse.set_visible(True)
def hide_cursor(widget, arg):
pygame.mouse.set_visible(False)
class PickerScreen(Screen):
def on_pre_enter(self):
self.layout = search(self, 'layout')
self.background = search(self, 'background')
self.scrollview = search(self, 'scrollview')
self.focus = None
# set the background to the correct position
self.on_picker_scroll(None, None)
self.scrollview.bind(scroll_x=self.on_picker_scroll)
self.scrollview.bind(pos=self.on_picker_move)
images = get_images()
width = math.ceil((len(images) / 2.0 * 312) / 1280.0)
self.max_width = width * 1280
# set the width to be much great than the screen
# somewhat proportionally to the number of images
rellayout = search(self, 'rellayout')
rellayout.size_hint = (width,1)
grid = search(self, 'grid')
Loader.loading_image = CoreImage('images/loading.gif')
Loader.num_workers = 4
Loader.max_upload_per_frame = 4
for image in get_images():
widget = Factory.AsyncImage(source=image, allow_stretch=True)
widget.bind(on_touch_down=self.on_image_touch)
grid.add_widget(widget)
self.scrollview_hidden = False
self._scrollview_pos_hint = self.scrollview.pos_hint
self._scrollview_pos = self.scrollview.pos
self._sv_hide_ani = None
self._sv_show_ani = None
self._focus_hide_ani = None
self._focus_show_ani = None
self._focus_widget = Image(source='images/loading.gif')
self._focus_widget.allow_stretch = True
self._focus_widget.pos_hint = {'center_x': .5}
self._focus_widget.y = 1024
self._focus_widget.size_hint = None, None
self._focus_widget.size = (600, 600)
self._focus_widget.bind(on_touch_down=self.on_image_touch)
self.layout.add_widget(self._focus_widget)
def on_image_touch(self, widget, mouse_point):
if widget.collide_point(mouse_point.x, mouse_point.y):
# show the focus widget
if self.scrollview_hidden:
self.scrollview_hidden = False
# cancel scrollview hiding animation
try:
self._sv_hide_ani.cancel(self.scrollview)
except AttributeError:
pass
# show the scrollview
x, y = self._scrollview_pos
self._sv_show_ani = Animation(x=x, y=y, t='in_out_quad', duration=.5)
self._sv_show_ani.start(self.scrollview)
# cancel the focus widget show animation
try:
self._focus_show_ani.cancel(self._focus_widget)
except AttributeError:
pass
# hide the focus widget
self._focus_hide_ani = Animation(y=1024,
size=(600,600),
t='in_out_quad',
duration=.5)
self._focus_hide_ani.start(self._focus_widget)
# hide the focus widget
elif self._focus_widget is not widget:
self.scrollview_hidden = True
# cancel the scrollview show animation
try:
self._sv_show_ani.cancel(self.scrollview)
except AttributeError:
pass
# hide the scrollview
self.sv_hide_ani = Animation(x=0, y=-450, t='in_out_quad', duration=.5)
self.sv_hide_ani.start(self.scrollview)
# make sure the focus animation is finished
try:
self._focus_hide_ani.cancel(self._focus_widget)
except AttributeError:
pass
# set the focus widget to have the same image as the one picked
# do a bit of mangling to get a more detailed image
filename = os.path.join(detail, os.path.basename(widget.source))
self._focus_widget.source = filename
# show the focus widget
self._focus_show_ani = Animation(y=200,
size=(800, 800),
t='in_out_quad',
duration=.5)
self._focus_show_ani.start(self._focus_widget)
def on_picker_move(self, widget, arg):
if widget is self.scrollview:
x, y = self.background.pos
self.background.pos = (x, -arg[1] / 50)
def on_picker_scroll(self, value1, value2):
self.background.pos = (self.scrollview.scroll_x*-600 - 100,
self.background.pos[1])
return False
class StartScreen(Screen):
pass
class EmailScreen(Screen):
prints = BoundedNumericProperty(0, min=0, max=MAXIMUM_PRINTS,
errorhandler = handle_print_number_error)
def on_add_print(self):
self.prints += 1
email_textinput = StringProperty()
def remove_print(self):
self.prints -= 1
def change_vkeyboard_email(self):
Config.set('kivy', 'keyboard_mode', 'dock')
Config.set('kivy', 'keyboard_layout', 'email')
def reset_email_textinput(self):
self.email_textinput = ''
def change_vkeyboard_normal(self):
Config.set('kivy', 'keyboard_layout', DEFAULT_VKEYBOARD_LAYOUT)
class PrintScreen(Screen):
pass
manager = ScreenManager()
manager.add_widget(PickerScreen(name='picker'))
manager.add_widget(StartScreen(name='start'))
manager.add_widget(EmailScreen(name='email'))
manager.add_widget(PrintScreen(name='print'))
# instant transition
manager.transition = TransitionBase(duration=0.01)
class KioskApp(App):
def build(self):
return manager
if __name__ == "__main__":
import pygame
app = KioskApp()
# disable the default mouse arrow cursor
cursor = pygame.cursors.load_xbm(
os.path.join('images', 'hand.xbm'),
os.path.join('images', 'hand-mask.xbm')
)
pygame.mouse.set_cursor(*cursor)
#pygame.mouse.set_visible(False)
app.run()