forked from dersphere/script.screensaver.multi_slideshow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreensaver.py
executable file
·1497 lines (1240 loc) · 56 KB
/
screensaver.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 Tristan Fischer (sphere@dersphere.de)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import random
import sys
import simplejson as json
from PIL import Image, ExifTags
from os import path, remove
import re
import threading
import time
from contextlib import closing
import xbmc
import xbmcaddon
import xbmcvfs
from xbmcgui import ControlImage, ControlLabel, WindowDialog, Window, DialogProgress, getScreenWidth, getScreenHeight
addon = xbmcaddon.Addon()
ADDON_NAME = addon.getAddonInfo('name')
ADDON_PATH = addon.getAddonInfo('path')
MODES = (
'TableDrop',
'StarWars',
'RandomZoomIn',
'AppleTVLike',
'GridSwitch',
'SlidingPanels',
'Random',
)
SOURCES = (
'movies',
'image_folder',
'albums',
'shows',
)
PROPS = (
'fanart',
'thumbnail',
)
CHUNK_WAIT_TIME = 250
ACTION_IDS_EXIT = [9, 10, 13, 92]
class ScreensaverManager(object):
def __new__(cls):
mode = MODES[int(addon.getSetting('mode'))]
if mode == 'Random':
subcls = random.choice(ScreensaverBase.__subclasses__())
return subcls()
for subcls in ScreensaverBase.__subclasses__():
if subcls.MODE == mode:
return subcls()
raise ValueError('Not a valid ScreensaverBase subclass: %s' % mode)
class ExitMonitor(xbmc.Monitor):
def __init__(self, exit_callback):
self.exit_callback = exit_callback
def onScreensaverDeactivated(self):
self.exit_callback()
class ScreensaverWindow(WindowDialog):
def __init__(self, exit_callback):
self.exit_callback = exit_callback
def onAction(self, action):
action_id = action.getId()
if action_id in ACTION_IDS_EXIT:
self.exit_callback()
class Cache(threading.Thread):
def __init__(self, images):
threading.Thread.__init__(self)
self.pause = threading.Event()
self.stop = threading.Event()
self.idle = threading.Event()
self.images = images
self.rotated_pictures = []
self.cache_cycle_image = cycle(self.images)
def run(self):
while True:
time.sleep(0.05)
if ( not self.pause.isSet() ):
if ( len(screensaver.preload_controls) < screensaver.FAST_IMAGE_COUNT):
self.idle.clear()
image_url = next(self.cache_cycle_image)
self.preload_image(image_url)
self.idle.set()
if ( self.stop.isSet() ):
return
def preload_image(self, image_url):
# set the next image to an unvisible image-control for caching
self.log('caching image: %s' % repr(image_url))
image_url = self.rotate_image(image_url)
screensaver.preload_controls[image_url] = ControlImage(-1, -1, 1, 1, image_url, False)
screensaver.preload_controls[image_url].setVisible(False)
screensaver.xbmc_window.addControl(screensaver.preload_controls[image_url])
self.log('caching done')
def rotate_image(self, image_url):
source = SOURCES[int(addon.getSetting('source'))]
# Do it only for real paths
if source == 'image_folder':
ROTATED = False
# Hardcoded UTF-8 decoding due to problems with locales
f = open(image_url.encode("utf-8"), 'rb')
image = Image.open(f)
try:
exif=dict(list(image._getexif().items()))
except AttributeError:
exif=[]
try:
for orientation in list(ExifTags.TAGS.keys()):
if ExifTags.TAGS[orientation]=='Orientation':
break
if exif[orientation] == 3:
image=image.rotate(180, expand=True)
ROTATED = True
elif exif[orientation] == 6:
image=image.rotate(270, expand=True)
ROTATED = True
elif exif[orientation] == 8:
image=image.rotate(90, expand=True)
ROTATED = True
except ( IndexError, KeyError ):
pass
if ROTATED:
self.log('rotating image: %s' % repr(image_url))
filepath = path.join(xbmcvfs.translatePath("special://temp/"), path.split(image_url)[1])
self.log(filepath)
_, fext = path.splitext(filepath)
fformat = 'JPEG' if fext[1:].lower() == 'jpg' else fext[1:].upper()
image.save(filepath.encode('utf-8'), fformat)
self.rotated_pictures.append(filepath)
self.images[:] = [ x if x != image_url else filepath for x in self.images ]
image_url = filepath
image.close()
try:
for datetimeoriginal in list(ExifTags.TAGS.keys()):
if ExifTags.TAGS[datetimeoriginal]=='DateTimeOriginal':
break
screensaver.image_dates[image_url] = exif[datetimeoriginal]
except ( IndexError, KeyError ):
screensaver.image_dates[image_url] = ''
return image_url
else:
return image_url
def delete_rotated_image(self, image_url):
if image_url in self.rotated_pictures:
self.log('deleting image: %s' % repr(image_url))
try:
remove(image_url.encode('utf-8'))
self.log('image %s deleted' % repr(image_url))
except OSError as e:
self.log('error deleting image %s' % repr(image_url))
self.log(e)
def log(self, msg):
xbmc.log('%s: Cache: %s' % (ADDON_NAME, msg))
class ScreensaverBase(object):
MODE = None
IMAGE_CONTROL_COUNT = 10
FAST_IMAGE_COUNT = 10
NEXT_IMAGE_TIME = 2000
BORDER_WIDTH = 4
BORDER_COLOR = 0
BACKGROUND_IMAGE = 'black.jpg'
RECTANGLES = 0
RECTANGLES_ITER = 0
EFFECT_SPEED = 1.0
VIEW = 0
CONTINUOUS = False
def __init__(self):
self.log('__init__ start')
# Variables
self.exit_requested = False
self.background_control = None
self.dialog = None
self.recycle = False
self.total_images = 0
self.image_count = 0
self.image_dates = {}
# Controls
self.image_controls = []
self.global_controls = []
self.border_controls = []
self.black_label_controls = []
self.white_label_controls = []
self.top_image_controls = []
self.custom_controls = {}
self.preload_controls = {}
# Init
self.exit_monitor = ExitMonitor(self.stop)
self.xbmc_window = ScreensaverWindow(self.stop)
self.xbmc_window.show()
self.init_global_controls()
self.load_settings()
self.init_cycle_controls()
self.stack_cycle_controls()
self.log('__init__ end')
def init_global_controls(self):
self.screen_width = Window().getWidth()
self.screen_height = Window().getHeight()
self.log(str(self.screen_width) + ' x ' + str(self.screen_height))
#self.screen_width = getScreenWidth()
#self.screen_height = getScreenHeight()
##self.log(str(self.screen_width) + ' x ' + str(self.screen_height))
self.log('init_global_controls start')
loading_img = xbmcvfs.validatePath('/'.join((
ADDON_PATH, 'resources', 'media', 'loading.gif'
)))
self.background_control = ControlImage(0, 0, self.screen_width, self.screen_height, '')
self.global_controls = [
self.background_control
]
self.xbmc_window.addControls(self.global_controls)
self.log('init_global_controls end')
def load_settings(self):
pass
def init_cycle_controls(self):
self.log('init_cycle_controls start')
for i in range(self.IMAGE_CONTROL_COUNT):
img_control = ControlImage(0, 0, 0, 0, '', aspectRatio=1)
self.image_controls.append(img_control)
self.log('init_cycle_controls end')
def stack_cycle_controls(self):
self.log('stack_cycle_controls start')
# add controls to the window in same order as image_controls list
# so any new image will be in front of all previous images
self.xbmc_window.addControls(self.image_controls)
self.log('stack_cycle_controls end')
def start_loop(self):
self.log('start_loop start')
# Get images from source
images = self.get_images()
# Shuffle images if requested
if addon.getSetting('random_order') == 'true':
random.shuffle(images)
# Start the cacher with images
self.cacher = Cache(images)
self.cacher.start()
# Define controls for the cycling and get first values
image_url_cycle = cycle(images)
image_controls_cycle = cycle(self.image_controls)
image_url = next(image_url_cycle)
image_control = next(image_controls_cycle)
# Preload in case of first initating
self.log('initial caching started')
self.dialog.create('Caching images...', '' )
while len(self.preload_controls) < self.FAST_IMAGE_COUNT:
#time.sleep(10)
time.sleep(0.01)
self.dialog.update(int(100 * len(self.preload_controls) / self.FAST_IMAGE_COUNT), ' ')
self.dialog.close()
# Fade in the background
self.show_background()
# Do it for repetitive views only
if ( self.VIEW == 1 ):
# Let the cacher settle down
self.cacher.pause.set()
self.cacher.idle.wait()
# Set the timing to fast values
save_EFFECT_SPEED = self.EFFECT_SPEED
save_NEXT_IMAGE_TIME = self.NEXT_IMAGE_TIME
self.EFFECT_SPEED = 2.0
self.NEXT_IMAGE_TIME = 10
self.recycle = True
# Now load the images in
for image_url, control in list(self.preload_controls.items()):
# Wait
self.wait()
if not self.exit_requested:
image_control = next(image_controls_cycle)
self.log('loading image: %s' % repr(image_url))
self.process_image(image_control, image_url)
self.image_count += 1
# Tidy up and move on
try:
self.cacher.delete_rotated_image(image_url)
self.xbmc_window.removeControl(self.preload_controls[image_url])
del self.preload_controls[image_url]
except KeyError:
pass
self.cacher.pause.clear()
# Reset the timing
self.recycle = False
self.EFFECT_SPEED = save_EFFECT_SPEED
self.NEXT_IMAGE_TIME = save_NEXT_IMAGE_TIME
# Do the loop
while not self.exit_requested:
# Wait
self.wait()
self.log('Count preload_controls ' + str(len(self.preload_controls)))
self.log('Count image_controls ' + str(len(self.image_controls)))
self.log('Count top_image_controls ' + str(len(self.top_image_controls)))
self.log('Count border_controls ' + str(len(self.border_controls)))
self.log('Count RECTANGLES ' + str(self.RECTANGLES))
# Do it for a repetitively changing view
if ( self.VIEW == 1 ):
# Redraw the view in case we hit the repetitive condition
try:
iter_check = (self.image_count / self.RECTANGLES) % self.RECTANGLES_ITER
except ZeroDivisionError:
iter_check = 0
if self.image_count / self.RECTANGLES != 0 and iter_check == 0:
# Set the timing to fast values
self.recycle = True
save_EFFECT_SPEED = self.EFFECT_SPEED
save_NEXT_IMAGE_TIME = self.NEXT_IMAGE_TIME
self.EFFECT_SPEED = 2.0
self.NEXT_IMAGE_TIME = 10
# Set the current image controls to background color
self.log('setting image controls to background color')
for image_control in self.image_controls:
self.process_image(image_control, self.BORDER_COLOR)
image_control = next(image_controls_cycle)
# Tidy up and move on
try:
self.cacher.delete_rotated_image(image_url)
self.xbmc_window.removeControl(self.preload_controls[image_url])
del self.preload_controls[image_url]
except KeyError:
pass
# Remove extra controls if present
self.xbmc_window.removeControls(self.border_controls)
self.xbmc_window.removeControls(self.black_label_controls)
self.xbmc_window.removeControls(self.white_label_controls)
self.xbmc_window.removeControls(self.top_image_controls)
# Do the actual redraw of the rectangle view
self.stack_cycle_controls()
# Now load the images in. But first ensure that we have
# enough images in the cache
while len(self.preload_controls) < self.FAST_IMAGE_COUNT:
time.sleep(0.05)
else:
# Prevent the cacher from distrubing the animations
self.cacher.pause.set()
# Wait for the cacher to settle down
self.cacher.idle.wait()
# Load the images from cache into the new view
cache_counter = 1
while cache_counter <= self.FAST_IMAGE_COUNT:
# Get the image_url and the image_control
for image_url, control in list(self.preload_controls.items()):
break
image_control = next(image_controls_cycle)
self.log('loading image: %s' % repr(image_url))
self.process_image(image_control, image_url)
self.image_count += 1
cache_counter += 1
# Tidy up and move on
#try:
self.cacher.delete_rotated_image(image_url)
self.xbmc_window.removeControl(self.preload_controls[image_url])
del self.preload_controls[image_url]
#except KeyError:
# pass
# Let the cache do its work again
self.cacher.pause.clear()
# Reset the timing
self.recycle = False
self.EFFECT_SPEED = save_EFFECT_SPEED
self.NEXT_IMAGE_TIME = save_NEXT_IMAGE_TIME
# Fill up cache
while len(self.preload_controls) <= 2:
time.sleep(0.05)
# Get the image_url and the image_control
for image_url, control in list(self.preload_controls.items()):
break
image_control = next(image_controls_cycle)
if not self.CONTINUOUS:
# Disable caching
self.cacher.pause.set()
# Let the cacher settle down
self.cacher.idle.wait()
# Do the animation
self.log('using image: %s' % repr(image_url))
self.process_image(image_control, image_url)
# Tidy up and move on
#try:
self.cacher.delete_rotated_image(image_url)
self.xbmc_window.removeControl(self.preload_controls[image_url])
del self.preload_controls[image_url]
#except KeyError:
# pass
if self.CONTINUOUS is False:
# Enable caching
self.cacher.pause.clear()
self.image_count += 1
# Do the normal work
else:
# Fill up cache
while len(self.preload_controls) <= 2:
#xbmc.sleep(50)
time.sleep(0.05)
# Get the image_url from the cache
for image_url, control in list(self.preload_controls.items()):
break
image_control = next(image_controls_cycle)
if not self.CONTINUOUS:
# Disable caching
self.cacher.pause.set()
# Let the cacher settle down
self.cacher.idle.wait()
# Do the animation
self.log('using image: %s' % repr(image_url))
self.process_image(image_control, image_url)
# Tidy up and move on
try:
self.cacher.delete_rotated_image(image_url)
self.xbmc_window.removeControl(self.preload_controls[image_url])
del self.preload_controls[image_url]
except KeyError:
pass
if not self.CONTINUOUS:
# Enable caching
self.cacher.pause.clear()
self.image_count += 1
def get_images(self):
self.image_aspect_ratio = 16.0 / 9.0
source = SOURCES[int(addon.getSetting('source'))]
prop = PROPS[int(addon.getSetting('prop'))]
self.dialog = DialogProgress()
images = []
if source == 'movies':
images = self._get_json_images('VideoLibrary.GetMovies', 'movies', prop)
elif source == 'albums':
images = self._get_json_images('AudioLibrary.GetAlbums', 'albums', prop)
elif source == 'shows':
images = self._get_json_images('VideoLibrary.GetTVShows', 'tvshows', prop)
elif source == 'image_folder':
path = addon.getSetting('image_path')
self.log(path)
if path:
self.dialog.create('Getting images recursively')
images = self._get_folder_images(path)
self.dialog.close()
if not images:
cmd = 'XBMC.Notification("{header}", "{message}")'.format(
header=addon.getLocalizedString(32500),
message=addon.getLocalizedString(32501)
)
xbmc.executebuiltin(cmd)
images = (
self._get_json_images('VideoLibrary.GetMovies', 'movies', 'fanart')
or self._get_json_images('AudioLibrary.GetArtists', 'artists', 'fanart')
)
return images
def _get_json_images(self, method, key, prop):
self.log('_get_json_images start')
query = {
'jsonrpc': '2.0',
'id': 0,
'method': method,
'params': {
'properties': [prop],
}
}
response = json.loads(xbmc.executeJSONRPC(json.dumps(query)))
images = [
element[prop] for element
in response.get('result', {}).get(key, [])
if element.get(prop)
]
self.log('_get_json_images end')
return images
def _get_folder_dirs(self, dirs, path):
directories, files = xbmcvfs.listdir(path)
for directory in directories:
dirs.append(xbmcvfs.validatePath('/'.join((path, directory, ''))))
if addon.getSetting('recursive') == 'true':
for directory in directories:
if directory.startswith('.'):
continue
for sub_directory in self._get_folder_dirs([], xbmcvfs.validatePath('/'.join((path, directory, '')))):
dirs.append(xbmcvfs.validatePath(sub_directory))
return dirs
def _get_folder_images(self, path):
self.log('_get_folder_images started')
def _dive_into_dir(path):
directories, files = xbmcvfs.listdir(path)
images = [
xbmcvfs.validatePath(path + f) for f in files
if f.lower()[-3:] in ('jpg', 'png', 'bmp')
]
return images
dirs = self._get_folder_dirs([], path)
dir_count = 1
images = []
for directory in dirs:
progress_update = int(100 * dir_count / len(dirs))
self.dialog.update(progress_update, directory)
dir_count = dir_count + 1
images.extend(_dive_into_dir(directory))
return images
def show_background(self):
bg_img = xbmcvfs.validatePath('/'.join((
ADDON_PATH, 'resources', 'media', self.BACKGROUND_IMAGE
)))
self.background_control.setAnimations([(
'conditional',
'effect=fade start=0 end=100 time=500 delay=500 condition=true'
)])
self.background_control.setImage(bg_img)
def process_image(self, image_control, image_url):
# Needs to be implemented in sub class
raise NotImplementedError
def wait(self):
# wait in chunks of 500ms to react earlier on exit request
chunk_wait_time = int(CHUNK_WAIT_TIME)
remaining_wait_time = int(self.NEXT_IMAGE_TIME)
while remaining_wait_time > 0:
if self.exit_requested:
self.cacher.stop.set()
return
if remaining_wait_time < chunk_wait_time:
chunk_wait_time = remaining_wait_time
remaining_wait_time -= chunk_wait_time
#time.sleep(float(chunk_wait_time) / 1000)
xbmc.sleep(chunk_wait_time)
def stop(self):
self.log('stop')
self.exit_requested = True
self.exit_monitor = None
def close(self):
self.del_controls()
def del_controls(self):
self.log('del_controls start')
self.xbmc_window.removeControls(self.image_controls)
self.xbmc_window.removeControls(self.global_controls)
#self.xbmc_window.removeControls(self.preload_controls)
self.xbmc_window.removeControls(self.top_image_controls)
self.xbmc_window.removeControls(self.black_label_controls)
self.xbmc_window.removeControls(self.white_label_controls)
self.preload_controls = {}
self.custom_controls = {}
self.background_control = None
self.image_dates = []
self.image_controls = []
self.global_controls = []
self.black_label_controls = []
self.white_label_controls = []
self.top_image_controls = []
self.xbmc_window.close()
self.xbmc_window = None
self.log('del_controls end')
def log(self, msg):
xbmc.log('%s: %s' % (ADDON_NAME, msg))
class TableDropScreensaver(ScreensaverBase):
MODE = 'TableDrop'
BACKGROUND_IMAGE = 'table.jpg'
IMAGE_CONTROL_COUNT = 20
FAST_IMAGE_COUNT = 10
NEXT_IMAGE_TIME = 1500
MIN_WIDTH = 500
MAX_WIDTH = 700
def load_settings(self):
self.NEXT_IMAGE_TIME = int(addon.getSetting('tabledrop_wait'))
def process_image(self, image_control, image_url):
ROTATE_ANIMATION = (
'effect=rotate start=0 end=%d center=auto time=%d '
'delay=0 tween=circle condition=true'
)
DROP_ANIMATION = (
'effect=zoom start=%d end=100 center=auto time=%d '
'delay=0 tween=circle condition=true'
)
FADE_ANIMATION = (
'effect=fade start=0 end=100 time=200 '
'condition=true'
)
# hide the image
image_control.setVisible(False)
image_control.setImage('')
# re-stack it (to be on top)
self.xbmc_window.removeControl(image_control)
self.xbmc_window.addControl(image_control)
# calculate all parameters and properties
width = random.randint(self.MIN_WIDTH, self.MAX_WIDTH)
height = int(width / self.image_aspect_ratio)
x_position = random.randint(0, self.screen_width - width)
y_position = random.randint(0, self.screen_height - height)
drop_height = random.randint(400, 800)
drop_duration = drop_height * 1.5
rotation_degrees = random.uniform(-20, 20)
rotation_duration = drop_duration
animations = [
('conditional', FADE_ANIMATION),
('conditional',
ROTATE_ANIMATION % (rotation_degrees, rotation_duration)),
('conditional',
DROP_ANIMATION % (drop_height, drop_duration)),
]
# set all parameters and properties
image_control.setImage(image_url)
image_control.setPosition(x_position, y_position)
image_control.setWidth(width)
image_control.setHeight(height)
image_control.setAnimations(animations)
# show the image
image_control.setVisible(True)
#xbmc.sleep(int(drop_duration))
time.sleep(float(drop_duration) / 1000)
class StarWarsScreensaver(ScreensaverBase):
MODE = 'StarWars'
BACKGROUND_IMAGE = 'stars.jpg'
IMAGE_CONTROL_COUNT = 6
FAST_IMAGE_COUNT = 6
SPEED = 0.5
CONTINUOUS = True
def load_settings(self):
self.SPEED = float(addon.getSetting('starwars_speed'))
self.EFFECT_TIME = 9000.0 / self.SPEED
self.NEXT_IMAGE_TIME = self.EFFECT_TIME / 7.6
def process_image(self, image_control, image_url):
TILT_ANIMATION = (
'effect=rotatex start=0 end=55 center=auto time=0 '
'condition=true'
)
MOVE_ANIMATION = (
'effect=slide start=0,self.screen_width end=0,-2560 time=%d '
'tween=linear condition=true'
)
# hide the image
image_control.setImage('')
image_control.setVisible(False)
# re-stack it (to be on top)
self.xbmc_window.removeControl(image_control)
self.xbmc_window.addControl(image_control)
# calculate all parameters and properties
width = self.screen_width
height = self.screen_height
x_position = 0
y_position = 0
animations = [
('conditional', TILT_ANIMATION),
('conditional', MOVE_ANIMATION % self.EFFECT_TIME),
]
# set all parameters and properties
image_control.setPosition(x_position, y_position)
image_control.setWidth(width)
image_control.setHeight(height)
image_control.setAnimations(animations)
image_control.setImage(image_url)
# show the image
image_control.setVisible(True)
class RandomZoomInScreensaver(ScreensaverBase):
MODE = 'RandomZoomIn'
IMAGE_CONTROL_COUNT = 7
FAST_IMAGE_COUNT = 7
NEXT_IMAGE_TIME = 2000
EFFECT_TIME = 5000
def load_settings(self):
self.NEXT_IMAGE_TIME = int(addon.getSetting('randomzoom_wait'))
self.EFFECT_TIME = int(addon.getSetting('randomzoom_effect'))
def process_image(self, image_control, image_url):
ZOOM_ANIMATION = (
'effect=zoom start=1 end=100 center=%d,%d time=%d '
'tween=quadratic condition=true'
)
# hide the image
image_control.setVisible(False)
image_control.setImage('')
# re-stack it (to be on top)
self.xbmc_window.removeControl(image_control)
self.xbmc_window.addControl(image_control)
# calculate all parameters and properties
width = self.screen_width
height = self.screen_height
x_position = 0
y_position = 0
zoom_x = random.randint(0, self.screen_width)
zoom_y = random.randint(0, self.screen_height)
animations = [
('conditional', ZOOM_ANIMATION % (zoom_x, zoom_y, self.EFFECT_TIME)),
]
# set all parameters and properties
image_control.setImage(image_url)
image_control.setPosition(x_position, y_position)
image_control.setWidth(width)
image_control.setHeight(height)
image_control.setAnimations(animations)
# show the image
image_control.setVisible(True)
class AppleTVLikeScreensaver(ScreensaverBase):
MODE = 'AppleTVLike'
IMAGE_CONTROL_COUNT = 35
FAST_IMAGE_COUNT = 10
DISTANCE_RATIO = 0.7
SPEED = 1.0
CONCURRENCY = 1.0
def load_settings(self):
self.SPEED = float(addon.getSetting('appletvlike_speed'))
self.CONCURRENCY = float(addon.getSetting('appletvlike_concurrency'))
self.MAX_TIME = int(15000 / self.SPEED)
self.NEXT_IMAGE_TIME = int(4500.0 / self.CONCURRENCY / self.SPEED)
def stack_cycle_controls(self):
# randomly generate a zoom in percent as betavariant
# between 10 and 70 and assign calculated width to control.
# Remove all controls from window and re-add sorted by size.
# This is needed because the bigger (=nearer) ones need to be in front
# of the smaller ones.
# Then shuffle image list again to have random size order.
for image_control in self.image_controls:
zoom = int(random.betavariate(2, 2) * 40) + 10
#zoom = int(random.randint(10, 70))
width = int(self.screen_width / 100 * zoom)
image_control.setWidth(int(width))
self.image_controls = sorted(
self.image_controls, key=lambda c: c.getWidth()
)
self.xbmc_window.addControls(self.image_controls)
random.shuffle(self.image_controls)
def process_image(self, image_control, image_url):
MOVE_ANIMATION = (
'effect=slide start=0,self.screen_height end=0,-self.screen_height center=auto time=%s '
'tween=linear delay=0 condition=true'
)
image_control.setVisible(False)
image_control.setImage('')
# calculate all parameters and properties based on the already set
# width. We can not change the size again because all controls need
# to be added to the window in size order.
width = image_control.getWidth()
zoom = width * 100 / self.screen_width
height = int(width / self.image_aspect_ratio)
# let images overlap max 1/2w left or right
center = random.randint(0, self.screen_width)
x_position = int(center - width / 2)
y_position = 0
time = self.MAX_TIME / zoom * self.DISTANCE_RATIO * 100
animations = [
('conditional', MOVE_ANIMATION % time),
]
# set all parameters and properties
image_control.setImage(image_url)
image_control.setPosition(x_position, y_position)
image_control.setWidth(width)
image_control.setHeight(height)
image_control.setAnimations(animations)
# show the image
image_control.setVisible(True)
class GridSwitchScreensaver(ScreensaverBase):
MODE = 'GridSwitch'
ROWS_AND_COLUMNS = 4
RECTANGLES = 16
NEXT_IMAGE_TIME = 1000
EFFECT_TIME = 500
RANDOM_ORDER = False
VIEW = 0
IMAGE_CONTROL_COUNT = ROWS_AND_COLUMNS ** 2
FAST_IMAGE_COUNT = IMAGE_CONTROL_COUNT
def load_settings(self):
self.NEXT_IMAGE_TIME = int(addon.getSetting('gridswitch_wait'))
self.ROWS_AND_COLUMNS = int(addon.getSetting('gridswitch_rows_columns'))
self.RANDOM_ORDER = addon.getSetting('gridswitch_random') == 'true'
self.IMAGE_CONTROL_COUNT = self.ROWS_AND_COLUMNS ** 2
self.RECTANGLES = self.ROWS_AND_COLUMNS * self.ROWS_AND_COLUMNS
self.FAST_IMAGE_COUNT = self.IMAGE_CONTROL_COUNT
def stack_cycle_controls(self):
# Set position and dimensions based on stack position.
# Shuffle image list to have random order.
super(GridSwitchScreensaver, self).stack_cycle_controls()
for i, image_control in enumerate(self.image_controls):
current_row, current_col = divmod(i, self.ROWS_AND_COLUMNS)
width = int(self.screen_width / self.ROWS_AND_COLUMNS)
height = int(self.screen_height / self.ROWS_AND_COLUMNS)
x_position = int(width * current_col)
y_position = int(height * current_row)
image_control.setPosition(x_position, y_position)
image_control.setWidth(width)
image_control.setHeight(height)
if self.RANDOM_ORDER:
random.shuffle(self.image_controls)
def process_image(self, image_control, image_url):
if not self.image_count < self.FAST_IMAGE_COUNT:
FADE_OUT_ANIMATION = (
'effect=fade start=100 end=0 time=%d condition=true' % self.EFFECT_TIME
)
animations = [
('conditional', FADE_OUT_ANIMATION),
]
image_control.setAnimations(animations)
#xbmc.sleep(self.EFFECT_TIME)
time.sleep(float(self.EFFECT_TIME) / 1000)
image_control.setImage(image_url)
FADE_IN_ANIMATION = (
'effect=fade start=0 end=100 time=%d condition=true' % self.EFFECT_TIME
)
animations = [
('conditional', FADE_IN_ANIMATION),
]
image_control.setAnimations(animations)
class SlidingPanelsScreensaver(ScreensaverBase):
MODE = 'SlidingPanels'
ROWS_AND_COLUMNS = 4
NEXT_IMAGE_TIME = 1000
EFFECT_SPEED = 0.5
VIEW = 1
RECTANGLES = 5
RANDOM_ORDER = False
DESCRIPTION = False
BORDER = True
BORDER_WIDTH = 4
BORDER_COLOR = 0
BACKGROUND_IMAGE="black.jpg"
IMAGE_CONTROL_COUNT = RECTANGLES
FAST_IMAGE_COUNT = IMAGE_CONTROL_COUNT
def load_settings(self):
self.VIEW = int(addon.getSetting('slidingpanels_mode'))
self.ROWS_AND_COLUMNS = int(addon.getSetting('slidingpanels_rows_columns'))
self.RECTANGLES = int(addon.getSetting('slidingpanels_random_rectangles'))
self.RECTANGLES_ITER = int(addon.getSetting('slidingpanels_random_iteration'))
self.NEXT_IMAGE_TIME = int(addon.getSetting('slidingpanels_wait'))
self.EFFECT_SPEED = float(addon.getSetting('slidingpanels_speed'))
self.RANDOM_ORDER = addon.getSetting('slidingpanels_random') == 'true'
self.DESCRIPTION = addon.getSetting('slidingpanels_description') == 'true'
self.DESCRIPTION_POSITION = int(addon.getSetting('slidingpanels_description_position'))