1
+ import time
2
+ import random
3
+
4
+ import kodigui
5
+
6
+ from lib import util
7
+ from plexnet import plexapp
8
+
9
+ class Slideshow (kodigui .BaseWindow , util .CronReceiver ):
10
+ xmlFile = 'script-plex-slideshow.xml'
11
+ path = util .ADDON .getAddonInfo ('path' )
12
+ theme = 'Main'
13
+ res = '1080i'
14
+ width = 1920
15
+ height = 1080
16
+
17
+ TIME_BETWEEN_IMAGES = 15
18
+ TIME_HIDE_TITLE_IN_QUIZ = 5
19
+ TIME_DISPLAY_MOVE = 60
20
+
21
+ CONTROL_INFO_GROUP = 100
22
+
23
+ def __init__ (self , * args , ** kwargs ):
24
+ kodigui .BaseWindow .__init__ (self , * args , ** kwargs )
25
+ self .timeBetweenImages = self .TIME_BETWEEN_IMAGES
26
+ self .timeBetweenDisplayMove = self .TIME_DISPLAY_MOVE
27
+ self .timeTitleIsHidden = self .TIME_HIDE_TITLE_IN_QUIZ
28
+ self .quizMode = util .advancedSettings .screensaverQuiz
29
+ self .initialized = False
30
+
31
+ def onFirstInit (self ):
32
+ self .setProperty ('clock' , '' )
33
+ self .setProperty ('title' , '' )
34
+ self .setProperty ('thumb' , '' )
35
+ self .setProperty ('align' , '0' )
36
+
37
+ self .infoGroupControl = self .getControl (self .CONTROL_INFO_GROUP )
38
+
39
+ util .CRON .registerReceiver (self )
40
+ self .timeFormat = util .timeFormat .replace (":%S" , "" )
41
+ self .lastTime = ''
42
+ self .displayPosition = 0
43
+ self .changeTime = time .time () - 1
44
+ self .displayMoveTime = time .time () + self .timeBetweenDisplayMove
45
+ self .revealTitleTime = None
46
+
47
+ self .selectedServer = plexapp .SERVERMANAGER .selectedServer
48
+ self .index = - 1
49
+ self .images = []
50
+
51
+ self .initialized = True
52
+
53
+ def tick (self ):
54
+ if not self .initialized :
55
+ return
56
+
57
+ currentTime = time .time ()
58
+ timestr = time .strftime (self .timeFormat , time .localtime (currentTime ))
59
+ if not util .padHour and timestr [0 ] == "0" and timestr [1 ] != ":" :
60
+ timestr = timestr [1 :]
61
+
62
+ if currentTime > self .changeTime :
63
+ nextIndex = self .index + 1
64
+
65
+ if nextIndex >= len (self .images ):
66
+ if self .selectedServer != None :
67
+ self .images = self .selectedServer .library .randomArts ();
68
+ util .DEBUG_LOG ('[SS] Fetched {0} items' .format (len (self .images )))
69
+ nextIndex = 0
70
+
71
+ if len (self .images ) == 0 :
72
+ title = 'No Images'
73
+ url = ''
74
+ else :
75
+ image = self .images [nextIndex ]
76
+ title = image .get ('title' )
77
+ key = image .get ('key' )
78
+ url = self .selectedServer .getImageTranscodeURL (key , self .width , self .height )
79
+ if not self .quizMode :
80
+ self .setProperty ('title' , title )
81
+ else :
82
+ self .setProperty ('title' , '' )
83
+ self .quizTitle = title
84
+ self .revealTitleTime = currentTime + self .timeTitleIsHidden
85
+ self .setProperty ('thumb' , url )
86
+
87
+ self .index = nextIndex
88
+ self .changeTime = time .time () + self .timeBetweenImages
89
+
90
+ if self .revealTitleTime != None and currentTime > self .revealTitleTime :
91
+ self .setProperty ('title' , self .quizTitle )
92
+ self .revealTitleTime = None
93
+
94
+ if currentTime > self .displayMoveTime :
95
+ oldDisplayPosition = self .displayPosition
96
+ self .displayPosition = (oldDisplayPosition + random .randint (1 , 3 )) % 4
97
+
98
+ if (oldDisplayPosition & 2 ) != (self .displayPosition & 2 ):
99
+ self .setProperty ('align' , str ((self .displayPosition & 2 )>> 1 ))
100
+
101
+ if (oldDisplayPosition & 1 ) != (self .displayPosition & 1 ):
102
+ newY = self .height - self .infoGroupControl .getY () - self .infoGroupControl .getHeight ()
103
+ self .infoGroupControl .setPosition (self .infoGroupControl .getX (), newY )
104
+
105
+ self .displayMoveTime = currentTime + self .timeBetweenDisplayMove
106
+
107
+ if timestr != self .lastTime :
108
+ self .setProperty ('clock' , timestr )
0 commit comments