4.2.5r2
[enigma2.git] / usr / lib / enigma2 / python / Plugins / Extensions / PicturePlayer / plugin.py
1 from enigma import ePicLoad, eRect, eSize, eTimer, getDesktop, gPixmapPtr
2
3 from Screens.Screen import Screen
4 from Tools.Directories import resolveFilename, pathExists, fileExists, SCOPE_MEDIA
5 from Plugins.Plugin import PluginDescriptor
6
7 from Components.Pixmap import Pixmap, MovingPixmap
8 from Components.ActionMap import HelpableActionMap, ActionMap
9 from Components.Sources.StaticText import StaticText
10 from Components.FileList import FileList
11 from Components.AVSwitch import AVSwitch
12 from Components.Sources.List import List
13 from Components.ConfigList import ConfigListScreen
14
15 from Components.config import config, ConfigSubsection, ConfigInteger, ConfigSelection, ConfigText, ConfigEnableDisable, getConfigListEntry
16
17 def getScale():
18         return AVSwitch().getFramebufferScale()
19
20 config.pic = ConfigSubsection()
21 config.pic.framesize = ConfigInteger(default=30, limits=(0, 99))
22 config.pic.slidetime = ConfigInteger(default=10, limits=(5, 60))
23 config.pic.resize = ConfigSelection(default="2", choices = [("0", _("simple")), ("1", _("better")), ("2", _("fast JPEG"))])
24 config.pic.resize.value = 2 # 2 = fast JPEG (non JPEG fallback to 1)
25 config.pic.cache = ConfigEnableDisable(default=True)
26 config.pic.lastDir = ConfigText(default=resolveFilename(SCOPE_MEDIA))
27 config.pic.infoline = ConfigEnableDisable(default=True)
28 config.pic.loop = ConfigEnableDisable(default=True)
29 config.pic.bgcolor = ConfigSelection(default="#00000000", choices = [("#00000000", _("black")),("#009eb9ff", _("blue")),("#00ff5a51", _("red")), ("#00ffe875", _("yellow")), ("#0038FF48", _("green"))])
30 config.pic.textcolor = ConfigSelection(default="#0038FF48", choices = [("#00000000", _("black")),("#009eb9ff", _("blue")),("#00ff5a51", _("red")), ("#00ffe875", _("yellow")), ("#0038FF48", _("green"))])
31 config.pic.thumbDelay = ConfigInteger(default=500, limits=(0,999))
32
33 def setPixmap(dest, ptr, scaleSize, aspectRatio):
34         if scaleSize.isValid() and aspectRatio.isValid():
35                 pic_scale_size = ptr.size().scale(scaleSize, aspectRatio)
36
37                 pic_size = ptr.size()
38                 pic_width = pic_size.width()
39                 pic_height = pic_size.height()
40
41                 dest_size = dest.getSize()
42                 dest_width = dest_size.width()
43                 dest_height = dest_size.height()
44
45                 pic_scale_width = pic_scale_size.width()
46                 pic_scale_height = pic_scale_size.height()
47
48 #               print "pic size %dx%d" %(pic_width, pic_height)
49 #               print "pic scale size %dx%d" %(pic_scale_width, pic_scale_height)
50 #               print "dest area size %dx%d" %(dest_width, dest_height)
51
52                 if pic_scale_width == dest_width: # v center
53                         dest_rect = eRect(0, (dest_height - pic_scale_height) / 2, pic_scale_width, pic_scale_height)
54                 else: # h center
55                         dest_rect = eRect((dest_width - pic_scale_width) / 2, 0, pic_scale_width, pic_scale_height)
56
57 #               print "dest rect", (dest_rect.left(), dest_rect.top(), dest_rect.width(), dest_rect.height())
58
59                 dest.instance.setScale(1)
60                 dest.instance.setScaleDest(dest_rect)
61         else:
62 #               print "no scale!"
63                 dest.instance.setScale(0)
64         dest.instance.setPixmap(ptr)
65
66 class picshow(Screen):
67         skin = """
68                 <screen name="picshow" position="center,center" size="560,440" title="PicturePlayer" >
69                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
70                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
71                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
72                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
73                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
74                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
75                         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
76                         <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
77                         <widget source="label" render="Label" position="5,55" size="350,140" font="Regular;19" backgroundColor="#25062748" transparent="1"  />
78                         <widget name="thn" position="360,40" size="180,160" />
79                         <widget name="filelist" position="5,205" zPosition="2" size="550,230" scrollbarMode="showOnDemand" />
80                 </screen>"""
81
82         def __init__(self, session):
83                 Screen.__init__(self, session)
84
85                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "DirectionActions"],
86                 {
87                         "cancel": self.KeyExit,
88                         "red": self.KeyExit,
89                         "green": self.KeyGreen,
90                         "yellow": self.KeyYellow,
91                         "blue": self.KeyBlue,
92                         "ok": self.KeyOk
93                 }, -1)
94
95                 self["key_red"] = StaticText(_("Close"))
96                 self["key_green"] = StaticText(_("Thumbnails"))
97                 self["key_yellow"] = StaticText("")
98                 self["key_blue"] = StaticText(_("Setup"))
99                 self["label"] = StaticText("")
100                 self["thn"] = Pixmap()
101
102                 currDir = config.pic.lastDir.value
103                 if not pathExists(currDir):
104                         currDir = "/"
105
106                 self.filelist = FileList(currDir, matchingPattern = "(?i)^.*\.(jpeg|jpg|jpe|png|bmp|gif)")
107                 self["filelist"] = self.filelist
108                 self["filelist"].onSelectionChanged.append(self.selectionChanged)
109
110                 self.ThumbTimer = eTimer()
111                 self.ThumbTimer_conn = self.ThumbTimer.timeout.connect(self.showThumb)
112
113                 self.picload = ePicLoad()
114                 self.picload_conn = self.picload.PictureData.connect(self.showPic)
115
116                 self.onLayoutFinish.append(self.setConf)
117
118         def showPic(self, picInfo=""):
119                 ptr = self.picload.getData()
120                 if ptr != None:
121                         setPixmap(self["thn"], ptr, self._scaleSize, self._aspectRatio)
122                         self["thn"].show()
123
124                 text = picInfo.split('\n',1)
125                 self["label"].setText(text[1])
126                 self["key_yellow"].setText(_("Exif"))
127
128         def showThumb(self):
129                 if not self.filelist.canDescent():
130                         if self.filelist.getCurrentDirectory() and self.filelist.getFilename():
131                                 if self.picload.getThumbnail(self.filelist.getCurrentDirectory() + self.filelist.getFilename()) == 1:
132                                         self.ThumbTimer.start(config.pic.thumbDelay.value, True)
133
134         def selectionChanged(self):
135                 if not self.filelist.canDescent():
136                         self.ThumbTimer.start(config.pic.thumbDelay.value, True)
137                 else:
138                         self["label"].setText("")
139                         self["thn"].hide()
140                         self["key_yellow"].setText("")
141
142         def KeyGreen(self):
143                 #if not self.filelist.canDescent():
144                 self.session.openWithCallback(self.callbackView, Pic_Thumb, self.filelist.getFileList(), self.filelist.getSelectionIndex(), self.filelist.getCurrentDirectory())
145
146         def KeyYellow(self):
147                 if not self.filelist.canDescent():
148                         self.session.open(Pic_Exif, self.picload.getInfo(self.filelist.getCurrentDirectory() + self.filelist.getFilename()))
149
150         def KeyBlue(self):
151                 self.session.openWithCallback(self.setConf ,Pic_Setup)
152
153         def KeyOk(self):
154                 if self.filelist.canDescent():
155                         self.filelist.descent()
156                 else:
157                         self.session.openWithCallback(self.callbackView, Pic_Full_View, self.filelist.getFileList(), self.filelist.getSelectionIndex(), self.filelist.getCurrentDirectory())
158
159         def setConf(self):
160                 self.setTitle(_("PicturePlayer"))
161                 sc = getScale()
162                 self._aspectRatio = eSize(sc[0], sc[1])
163                 self._scaleSize = self["thn"].instance.size()
164                 #0=Width 1=Height 2=Aspect 3=use_cache 4=resize_type 5=Background(#AARRGGBB)
165                 params = (self._scaleSize.width(), self._scaleSize.height(), sc[0], sc[1], config.pic.cache.value, int(config.pic.resize.value), "#00000000")
166                 self.picload.setPara(params)
167
168         def callbackView(self, val=0):
169                 if val > 0:
170                         self.filelist.moveToIndex(val)
171
172         def KeyExit(self):
173                 self.ThumbTimer.stop()
174                 del self.picload_conn
175                 del self.picload
176
177                 if self.filelist.getCurrentDirectory() is None:
178                         config.pic.lastDir.value = "/"
179                 else:
180                         config.pic.lastDir.value = self.filelist.getCurrentDirectory()
181
182                 config.pic.save()
183                 self.close()
184
185 #------------------------------------------------------------------------------------------
186
187 class Pic_Setup(Screen, ConfigListScreen):
188
189         def __init__(self, session):
190                 Screen.__init__(self, session)
191                 # for the skin: first try MediaPlayerSettings, then Setup, this allows individual skinning
192                 self.skinName = ["PicturePlayerSetup", "Setup" ]
193                 self.setup_title = _("Settings")
194                 self.onChangedEntry = [ ]
195                 self.session = session
196
197                 self["actions"] = ActionMap(["SetupActions"],
198                         {
199                                 "cancel": self.keyCancel,
200                                 "save": self.keySave,
201                                 "ok": self.keySave,
202                         }, -2)
203
204                 self["key_red"] = StaticText(_("Cancel"))
205                 self["key_green"] = StaticText(_("OK"))
206
207                 self.list = []
208                 ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.changedEntry)
209                 self.createSetup()
210                 self.onLayoutFinish.append(self.layoutFinished)
211
212         def layoutFinished(self):
213                 self.setTitle(self.setup_title)
214
215         def createSetup(self):
216                 self.list = []
217                 self.list.append(getConfigListEntry(_("Slideshow: Interval between pictures (sec)"), config.pic.slidetime))
218                 self.list.append(getConfigListEntry(_("Slideshow: Repeat"), config.pic.loop))
219                 self.list.append(getConfigListEntry(_("Fullscreen: Show info line"), config.pic.infoline))
220                 self.list.append(getConfigListEntry(_("Fullscreen: Text color"), config.pic.textcolor))
221                 self.list.append(getConfigListEntry(_("Fullscreen: Background color"), config.pic.bgcolor))
222                 self.list.append(getConfigListEntry(_("Fullscreen: Frame size"), config.pic.framesize))
223                 self.list.append(getConfigListEntry(_("Thumbnails: Enable cache"), config.pic.cache))
224                 self.list.append(getConfigListEntry(_("Thumbnails: Delay before loading (msec)"), config.pic.thumbDelay))
225                 self["config"].list = self.list
226                 self["config"].l.setList(self.list)
227
228         def keyLeft(self):
229                 ConfigListScreen.keyLeft(self)
230
231         def keyRight(self):
232                 ConfigListScreen.keyRight(self)
233
234         # for summary:
235         def changedEntry(self):
236                 for x in self.onChangedEntry:
237                         x()
238
239         def getCurrentEntry(self):
240                 return self["config"].getCurrent()[0]
241
242         def getCurrentValue(self):
243                 return str(self["config"].getCurrent()[1].getText())
244
245         def createSummary(self):
246                 from Screens.Setup import SetupSummary
247                 return SetupSummary
248
249 #---------------------------------------------------------------------------
250
251 class Pic_Exif(Screen):
252         skin = """
253                 <screen name="Pic_Exif" position="center,center" size="560,360" title="Info" >
254                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
255                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
256                         <widget source="menu" render="Listbox" position="5,50" size="550,310" scrollbarMode="showOnDemand" selectionDisabled="1" >
257                                 <convert type="TemplatedMultiContent">
258                                 {
259                                         "template": [  MultiContentEntryText(pos = (5, 5), size = (250, 30), flags = RT_HALIGN_LEFT, text = 0), MultiContentEntryText(pos = (260, 5), size = (290, 30), flags = RT_HALIGN_LEFT, text = 1)],
260                                         "fonts": [gFont("Regular", 20)],
261                                         "itemHeight": 30
262                                 }
263                                 </convert>
264                         </widget>
265                 </screen>"""
266
267         def __init__(self, session, exiflist):
268                 Screen.__init__(self, session)
269
270                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
271                 {
272                         "cancel": self.close
273                 }, -1)
274
275                 self["key_red"] = StaticText(_("Close"))
276
277                 exifdesc = [_("filename")+':', "EXIF-Version:", "Make:", "Camera:", "Date/Time:", "Width / Height:", "Flash used:", "Orientation:", "User Comments:", "Metering Mode:", "Exposure Program:", "Light Source:", "CompressedBitsPerPixel:", "ISO Speed Rating:", "X-Resolution:", "Y-Resolution:", "Resolution Unit:", "Brightness:", "Exposure Time:", "Exposure Bias:", "Distance:", "CCD-Width:", "ApertureFNumber:"]
278                 list = []
279
280                 for x in range(len(exiflist)):
281                         if x>0:
282                                 list.append((exifdesc[x], exiflist[x]))
283                         else:
284                                 name = exiflist[x].split('/')[-1]
285                                 list.append((exifdesc[x], name))
286                 self["menu"] = List(list)
287                 self.onLayoutFinish.append(self.layoutFinished)
288
289         def layoutFinished(self):
290                 self.setTitle(_("Info"))
291
292 #----------------------------------------------------------------------------------------
293
294 T_INDEX = 0
295 T_FRAME_POS = 1
296 T_PAGE = 2
297 T_NAME = 3
298 T_FULL = 4
299
300 class Pic_Thumb(Screen):
301         def __init__(self, session, piclist, lastindex, path):
302
303                 self.textcolor = config.pic.textcolor.value
304                 self.color = config.pic.bgcolor.value
305                 textsize = 20
306                 self.spaceX = 35
307                 self.picX = 190
308                 self.spaceY = 30
309                 self.picY = 200
310
311                 size_w = getDesktop(0).size().width()
312                 size_h = getDesktop(0).size().height()
313                 self.thumbsX = size_w / (self.spaceX + self.picX) # thumbnails in X
314                 self.thumbsY = size_h / (self.spaceY + self.picY) # thumbnails in Y
315                 self.thumbsC = self.thumbsX * self.thumbsY # all thumbnails
316
317                 self.positionlist = []
318                 skincontent = ""
319
320                 posX = -1
321                 for x in range(self.thumbsC):
322                         posY = x / self.thumbsX
323                         posX += 1
324                         if posX >= self.thumbsX:
325                                 posX = 0
326
327                         absX = self.spaceX + (posX*(self.spaceX + self.picX))
328                         absY = self.spaceY + (posY*(self.spaceY + self.picY))
329                         self.positionlist.append((absX, absY))
330                         skincontent += "<widget source=\"label" + str(x) + "\" render=\"Label\" position=\"" + str(absX+5) + "," + str(absY+self.picY-textsize) + "\" size=\"" + str(self.picX - 10) + ","  + str(textsize) + "\" font=\"Regular;14\" zPosition=\"2\" transparent=\"1\" noWrap=\"1\" foregroundColor=\"" + self.textcolor + "\" />"
331                         skincontent += "<widget name=\"thumb" + str(x) + "\" position=\"" + str(absX+5)+ "," + str(absY+5) + "\" size=\"" + str(self.picX -10) + "," + str(self.picY - (textsize*2)) + "\" zPosition=\"2\" transparent=\"1\" />"
332
333                 # Screen, backgroundlabel and MovingPixmap
334                 self.skin = "<screen position=\"0,0\" size=\"" + str(size_w) + "," + str(size_h) + "\" flags=\"wfNoBorder\" > \
335                         <eLabel position=\"0,0\" zPosition=\"0\" size=\""+ str(size_w) + "," + str(size_h) + "\" backgroundColor=\"" + self.color + "\" /> \
336                         <widget name=\"frame\" position=\"35,30\" size=\"190,200\" pixmap=\"pic_frame.png\" zPosition=\"1\" alphatest=\"on\" />"  + skincontent + "</screen>"
337
338                 Screen.__init__(self, session)
339
340                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "DirectionActions", "MovieSelectionActions"],
341                 {
342                         "cancel": self.Exit,
343                         "ok": self.KeyOk,
344                         "left": self.key_left,
345                         "right": self.key_right,
346                         "up": self.key_up,
347                         "down": self.key_down,
348                         "showEventInfo": self.StartExif,
349                 }, -1)
350
351                 self["frame"] = MovingPixmap()
352                 for x in range(self.thumbsC):
353                         self["label"+str(x)] = StaticText()
354                         self["thumb"+str(x)] = Pixmap()
355
356                 self.Thumbnaillist = []
357                 self.filelist = []
358                 self.currPage = -1
359                 self.dirlistcount = 0
360                 self.path = path
361
362                 index = 0
363                 framePos = 0
364                 Page = 0
365                 for x in piclist:
366                         if x[0][1] == False:
367                                 self.filelist.append((index, framePos, Page, x[0][0],  path + x[0][0]))
368                                 index += 1
369                                 framePos += 1
370                                 if framePos > (self.thumbsC -1):
371                                         framePos = 0
372                                         Page += 1
373                         else:
374                                 self.dirlistcount += 1
375
376                 self.maxentry = len(self.filelist)-1
377                 self.index = lastindex - self.dirlistcount
378                 if self.index < 0:
379                         self.index = 0
380
381                 self.picload = ePicLoad()
382                 self.picload_conn = self.picload.PictureData.connect(self.showPic)
383
384                 self.onLayoutFinish.append(self.setPicloadConf)
385
386                 self.ThumbTimer = eTimer()
387                 self.ThumbTimer_conn = self.ThumbTimer.timeout.connect(self.showPic)
388
389         def setPicloadConf(self):
390                 sc = getScale()
391                 self._aspectRatio = eSize(sc[0], sc[1])
392                 self._scaleSize = self["thumb0"].instance.size()
393                 self.picload.setPara([self._scaleSize.width(), self._scaleSize.height(), sc[0], sc[1], config.pic.cache.value, int(config.pic.resize.value), self.color])
394                 self.paintFrame()
395
396         def paintFrame(self):
397                 #print "index=" + str(self.index)
398                 if self.maxentry < self.index or self.index < 0:
399                         return
400
401                 pos = self.positionlist[self.filelist[self.index][T_FRAME_POS]]
402                 self["frame"].moveTo( pos[0], pos[1], 1)
403                 self["frame"].startMoving()
404
405                 if self.currPage != self.filelist[self.index][T_PAGE]:
406                         self.currPage = self.filelist[self.index][T_PAGE]
407                         self.newPage()
408
409         def newPage(self):
410                 self.Thumbnaillist = []
411                 #clear Labels and Thumbnail
412                 for x in range(self.thumbsC):
413                         self["label"+str(x)].setText("")
414                         self["thumb"+str(x)].hide()
415                 #paint Labels and fill Thumbnail-List
416                 for x in self.filelist:
417                         if x[T_PAGE] == self.currPage:
418                                 self["label"+str(x[T_FRAME_POS])].setText("(" + str(x[T_INDEX]+1) + ") " + x[T_NAME])
419                                 self.Thumbnaillist.append([0, x[T_FRAME_POS], x[T_FULL]])
420
421                 #paint Thumbnail start
422                 self.showPic()
423
424         def showPic(self, picInfo=""):
425                 for x in range(len(self.Thumbnaillist)):
426                         if self.Thumbnaillist[x][0] == 0:
427                                 if self.picload.getThumbnail(self.Thumbnaillist[x][2]) == 1: #zu tun probier noch mal
428                                         self.ThumbTimer.start(config.pic.thumbDelay.value, True)
429                                 else:
430                                         self.Thumbnaillist[x][0] = 1
431                                 break
432                         elif self.Thumbnaillist[x][0] == 1:
433                                 self.Thumbnaillist[x][0] = 2
434                                 ptr = self.picload.getData()
435                                 if ptr != None:
436                                         setPixmap(self["thumb" + str(self.Thumbnaillist[x][1])], ptr, self._scaleSize, self._aspectRatio)
437                                         self["thumb" + str(self.Thumbnaillist[x][1])].show()
438
439         def key_left(self):
440                 self.index -= 1
441                 if self.index < 0:
442                         self.index = self.maxentry
443                 self.paintFrame()
444
445         def key_right(self):
446                 self.index += 1
447                 if self.index > self.maxentry:
448                         self.index = 0
449                 self.paintFrame()
450
451         def key_up(self):
452                 self.index -= self.thumbsX
453                 if self.index < 0:
454                         self.index =self.maxentry
455                 self.paintFrame()
456
457         def key_down(self):
458                 self.index += self.thumbsX
459                 if self.index > self.maxentry:
460                         self.index = 0
461                 self.paintFrame()
462
463         def StartExif(self):
464                 if self.maxentry < 0:
465                         return
466                 self.session.open(Pic_Exif, self.picload.getInfo(self.filelist[self.index][T_FULL]))
467
468         def KeyOk(self):
469                 if self.maxentry < 0:
470                         return
471                 self.old_index = self.index
472                 self.session.openWithCallback(self.callbackView, Pic_Full_View, self.filelist, self.index, self.path)
473
474         def callbackView(self, val=0):
475                 self.index = val
476                 if self.old_index != self.index:
477                         self.paintFrame()
478         def Exit(self):
479                 del self.picload_conn
480                 del self.picload
481                 self.close(self.index + self.dirlistcount)
482
483 #---------------------------------------------------------------------------
484
485 class Pic_Full_View(Screen):
486         def __init__(self, session, filelist, index, path):
487
488                 self.textcolor = config.pic.textcolor.value
489                 self.bgcolor = config.pic.bgcolor.value
490                 space = config.pic.framesize.value
491                 size_w = getDesktop(0).size().width()
492                 size_h = getDesktop(0).size().height()
493
494                 self.skin = "<screen position=\"0,0\" size=\"" + str(size_w) + "," + str(size_h) + "\" flags=\"wfNoBorder\" > \
495                         <eLabel position=\"0,0\" zPosition=\"0\" size=\""+ str(size_w) + "," + str(size_h) + "\" backgroundColor=\""+ self.bgcolor +"\" /> \
496                         <widget name=\"pic\" position=\"" + str(space) + "," + str(space) + "\" size=\"" + str(size_w-(space*2)) + "," + str(size_h-(space*2)) + "\" zPosition=\"1\" /> \
497                         <widget name=\"point\" position=\""+ str(space+5) + "," + str(space+2) + "\" size=\"20,20\" zPosition=\"2\" pixmap=\"skin_default/icons/record.png\" alphatest=\"on\" /> \
498                         <widget name=\"play_icon\" position=\""+ str(space+25) + "," + str(space+2) + "\" size=\"20,20\" zPosition=\"2\" pixmap=\"skin_default/icons/ico_mp_play.png\"  alphatest=\"on\" /> \
499                         <widget source=\"file\" render=\"Label\" position=\""+ str(space+45) + "," + str(space) + "\" size=\""+ str(size_w-(space*2)-50) + ",25\" font=\"Regular;20\" halign=\"left\" foregroundColor=\"" + self.textcolor + "\" zPosition=\"2\" noWrap=\"1\" transparent=\"1\" /></screen>"
500
501                 Screen.__init__(self, session)
502
503                 self["PicturePlayerActions"] = HelpableActionMap(self, "PicturePlayerActions",
504                 {
505                         "cancel":       (self.Exit, _("Exit")),
506                         "playpause":    (self.PlayPause, _("Play/Pause")),
507                         "next":         (self.nextPic, _("Next")),
508                         "previous":     (self.prevPic, _("Prev")),
509                         "info":         (self.StartExif, _("Info"))
510                 }, -2);
511
512                 self["point"] = Pixmap()
513                 self["pic"] = Pixmap()
514                 self["play_icon"] = Pixmap()
515                 self["file"] = StaticText(_("please wait, loading picture..."))
516
517                 self.picVisible = False
518                 self._layoutFinished = False
519                 self.setFileList(filelist, index, path)
520
521                 self.picload = ePicLoad()
522                 self.picload_conn = self.picload.PictureData.connect(self.finish_decode)
523
524                 self.slideTimer = eTimer()
525                 self.slideTimer_conn = self.slideTimer.timeout.connect(self.slidePic)
526
527                 self.onLayoutFinish.append(self._onLayoutFinished)
528
529         def setFileList(self, filelist, index, path):
530                 self.picReady = False
531                 self.old_index = 0
532                 self.filelist = []
533                 self.lastindex = index
534                 self.shownow = True
535                 self.dirlistcount = 0
536                 self.direction = 1 #cache next picture
537
538                 for x in filelist:
539                         if len(filelist[0]) == 3: #orig. filelist
540                                 if x[0][1] == False:
541                                         self.filelist.append(path + x[0][0])
542                                 else:
543                                         self.dirlistcount += 1
544                         elif len(filelist[0]) == 2: #scanlist
545                                 if x[0][1] == False:
546                                         self.filelist.append(x[0][0])
547                                 else:
548                                         self.dirlistcount += 1
549                         else: # thumbnaillist
550                                 self.filelist.append(x[T_FULL])
551
552                 self.maxentry = len(self.filelist)-1
553                 self.index = index - self.dirlistcount
554                 if self.index < 0:
555                         self.index = 0
556                 if self._layoutFinished and self.maxentry >= 0:
557                         self.start_decode()
558
559         def _onLayoutFinished(self):
560                 self._layoutFinished = True
561                 if self.maxentry >= 0:
562                         self.setPicloadConf()
563
564         def setPicloadConf(self):
565                 sc = getScale()
566                 self._aspectRatio = eSize(sc[0], sc[1])
567                 self._scaleSize = self["pic"].instance.size()
568                 self.picload.setPara((self._scaleSize.width(), self._scaleSize.height(), sc[0], sc[1], 0, int(config.pic.resize.value), self.bgcolor))
569
570                 self["play_icon"].hide()
571                 if not config.pic.infoline.value:
572                         self["file"].setText("")
573                 self.start_decode()
574
575         def ShowPicture(self):
576                 if self.shownow and self.pic_ready:
577                         if self.picVisible:
578                                 self.picVisible = False
579                                 empty = gPixmapPtr()
580                                 self["pic"].instance.setPixmap(empty)
581
582                         ptr = self.picload.getData()
583                         if ptr != None:
584                                 text = ""
585                                 try:
586                                         text = self.picInfo.split('\n',1)
587                                         text = "(" + str(self.index+1) + "/" + str(self.maxentry+1) + ") " + text[0].split('/')[-1]
588                                 except:
589                                         pass
590
591                                 self.shownow = False
592                                 if not config.pic.infoline.value:
593                                         self["play_icon"].hide()
594                                         self["file"].setText("")
595                                 else:
596                                         self["file"].setText(text)
597                                 self.lastindex = self.index
598
599                                 setPixmap(self["pic"], ptr, self._scaleSize, self._aspectRatio)
600                                 self.picVisible = True
601                         else:
602                                 print "picture ready but no picture avail!!!!!!!"
603
604                         print "direction", self.direction
605                         if self.direction > 0:
606                                 self.next()
607                         else:
608                                 self.prev()
609                         self.start_decode()
610
611         def finish_decode(self, picInfo=""):
612                 self["point"].hide()
613                 self.picInfo = picInfo
614                 self.pic_ready = True
615                 self.ShowPicture()
616
617         def start_decode(self):
618                 self.pic_ready = False
619                 self.picload.startDecode(self.filelist[self.index])
620                 self["point"].show()
621
622         def next(self):
623                 self.direction = 1
624                 self.index += 1
625                 if self.index > self.maxentry:
626                         self.index = 0
627
628         def prev(self):
629                 self.direction = -1
630                 self.index -= 1
631                 if self.index < 0:
632                         self.index = self.maxentry
633
634         def slidePic(self):
635                 print "slide to next Picture index=" + str(self.lastindex)
636                 if config.pic.loop.value==False and self.lastindex == self.maxentry:
637                         self.PlayPause()
638                 self.shownow = True
639                 self.ShowPicture()
640
641         def PlayPause(self):
642                 if self.slideTimer.isActive():
643                         self.slideTimer.stop()
644                         self["play_icon"].hide()
645                 else:
646                         self.slideTimer.start(config.pic.slidetime.value*1000)
647                         self["play_icon"].show()
648                         self.nextPic()
649
650         def prevPic(self):
651                 self.shownow = True
652                 if self.direction < 0:
653                         self.ShowPicture()
654                 else:
655                         self.index = self.lastindex
656                         self.prev()
657                         self.start_decode()
658
659         def nextPic(self):
660                 self.shownow = True
661                 if self.direction > 0:
662                         self.ShowPicture()
663                 else:
664                         self.index = self.lastindex
665                         self.next()
666                         self.start_decode()
667
668         def StartExif(self):
669                 if self.maxentry < 0:
670                         return
671                 self.session.open(Pic_Exif, self.picload.getInfo(self.filelist[self.lastindex]))
672
673         def Exit(self):
674                 self.slideTimer.stop()
675                 del self.picload_conn
676                 del self.picload
677                 self.close(self.lastindex + self.dirlistcount)
678
679 #------------------------------------------------------------------------------------------
680
681 def main(session, **kwargs):
682         session.open(picshow)
683
684 def filescan_open(list, session, **kwargs):
685         # Recreate List as expected by PicView
686         filelist = [((file.path, False), None) for file in list]
687         session.open(Pic_Full_View, filelist, 0, file.path)
688
689 def filescan(**kwargs):
690         from Components.Scanner import Scanner, ScanPath
691
692         # Overwrite checkFile to only detect local
693         class LocalScanner(Scanner):
694                 def checkFile(self, file):
695                         return fileExists(file.path)
696
697         return \
698                 LocalScanner(mimetypes = ["image/jpeg", "image/png", "image/gif", "image/bmp"],
699                         paths_to_scan = 
700                                 [
701                                         ScanPath(path = "DCIM", with_subdirs = True),
702                                         ScanPath(path = "", with_subdirs = False),
703                                 ],
704                         name = "Pictures", 
705                         description = _("View Photos..."),
706                         openfnc = filescan_open,
707                 )
708
709 def Plugins(**kwargs):
710         return \
711                 [PluginDescriptor(name=_("PicturePlayer"), description=_("fileformats (BMP, PNG, JPG, GIF)"), icon="pictureplayer.png", where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc=main),
712                  PluginDescriptor(name=_("PicturePlayer"), where = PluginDescriptor.WHERE_FILESCAN, needsRestart = False, fnc = filescan)]