PEP8: Fix whitespace
[openblackhole/openblackhole-enigma2.git] / lib / python / Plugins / Extensions / PicturePlayer / ui.py
1 from enigma import ePicLoad, eTimer, getDesktop, gMainDC, eSize
2
3 from Screens.Screen import Screen
4 from Tools.Directories import resolveFilename, pathExists, SCOPE_MEDIA, SCOPE_CURRENT_SKIN
5
6 from Components.Pixmap import Pixmap, MovingPixmap
7 from Components.ActionMap import ActionMap, NumberActionMap
8 from Components.Sources.StaticText import StaticText
9 from Components.FileList import FileList
10 from Components.AVSwitch import AVSwitch
11 from Components.Sources.List import List
12 from Components.ConfigList import ConfigList, ConfigListScreen
13
14 from Components.config import config, ConfigSubsection, ConfigInteger, ConfigSelection, ConfigText, ConfigYesNo, KEY_LEFT, KEY_RIGHT, KEY_0, getConfigListEntry
15 import skin
16
17 def getScale():
18         return AVSwitch().getFramebufferScale()
19
20 config.pic = ConfigSubsection()
21 config.pic.framesize = ConfigInteger(default=30, limits=(5, 99))
22 config.pic.slidetime = ConfigInteger(default=10, limits=(1, 60))
23 config.pic.resize = ConfigSelection(default="1", choices = [("0", _("simple")), ("1", _("better"))])
24 config.pic.cache = ConfigYesNo(default=True)
25 config.pic.lastDir = ConfigText(default=resolveFilename(SCOPE_MEDIA))
26 config.pic.infoline = ConfigYesNo(default=True)
27 config.pic.loop = ConfigYesNo(default=True)
28 config.pic.bgcolor = ConfigSelection(default="#00000000", choices = [("#00000000", _("black")),("#009eb9ff", _("blue")),("#00ff5a51", _("red")), ("#00ffe875", _("yellow")), ("#0038FF48", _("green"))])
29 config.pic.autoOrientation = ConfigYesNo(default=False)
30 config.pic.textcolor = ConfigSelection(default="#0038FF48", choices = [("#00000000", _("black")),("#009eb9ff", _("blue")),("#00ff5a51", _("red")), ("#00ffe875", _("yellow")), ("#0038FF48", _("green"))])
31
32 class picshow(Screen):
33         skin = """
34                 <screen name="picshow" position="center,center" size="560,440" title="Picture player" >
35                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
36                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
37                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
38                         <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" />
39                         <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" />
40                         <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" />
41                         <widget source="label" render="Label" position="5,55" size="350,140" font="Regular;19" backgroundColor="#25062748" transparent="1"  />
42                         <widget name="thn" position="360,40" size="180,160" alphatest="on" />
43                         <widget name="filelist" position="5,205" zPosition="2" size="550,230" scrollbarMode="showOnDemand" />
44                 </screen>"""
45
46         def __init__(self, session):
47                 Screen.__init__(self, session)
48
49                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "DirectionActions", "MenuActions"],
50                 {
51                         "cancel": self.KeyExit,
52                         "red": self.KeyExit,
53                         "green": self.KeyGreen,
54                         "yellow": self.KeyYellow,
55                         "menu": self.KeyMenu,
56                         "ok": self.KeyOk
57                 }, -1)
58
59                 self["key_red"] = StaticText(_("Close"))
60                 self["key_green"] = StaticText(_("Thumbnails"))
61                 self["key_yellow"] = StaticText("")
62                 self["label"] = StaticText("")
63                 self["thn"] = Pixmap()
64
65                 currDir = config.pic.lastDir.value
66                 if not pathExists(currDir):
67                         currDir = "/"
68
69                 self.filelist = FileList(currDir, matchingPattern = "(?i)^.*\.(jpeg|jpg|jpe|png|bmp|gif)")
70                 self["filelist"] = self.filelist
71                 self["filelist"].onSelectionChanged.append(self.selectionChanged)
72
73                 self.ThumbTimer = eTimer()
74                 self.ThumbTimer.callback.append(self.showThumb)
75
76                 self.picload = ePicLoad()
77                 self.picload.PictureData.get().append(self.showPic)
78
79                 self.onLayoutFinish.append(self.setConf)
80
81         def showPic(self, picInfo=""):
82                 ptr = self.picload.getData()
83                 if ptr != None:
84                         self["thn"].instance.setPixmap(ptr.__deref__())
85                         self["thn"].show()
86
87                 text = picInfo.split('\n',1)
88                 self["label"].setText(text[1])
89                 self["key_yellow"].setText(_("Exif"))
90
91         def showThumb(self):
92                 if not self.filelist.canDescent():
93                         if self.filelist.getCurrentDirectory() and self.filelist.getFilename():
94                                 if self.picload.getThumbnail(self.filelist.getCurrentDirectory() + self.filelist.getFilename()) == 1:
95                                         self.ThumbTimer.start(500, True)
96
97         def selectionChanged(self):
98                 if not self.filelist.canDescent():
99                         self.ThumbTimer.start(500, True)
100                 else:
101                         self["label"].setText("")
102                         self["thn"].hide()
103                         self["key_yellow"].setText("")
104
105         def KeyGreen(self):
106                 #if not self.filelist.canDescent():
107                 self.session.openWithCallback(self.callbackView, Pic_Thumb, self.filelist.getFileList(), self.filelist.getSelectionIndex(), self.filelist.getCurrentDirectory())
108
109         def KeyYellow(self):
110                 if not self.filelist.canDescent():
111                         self.session.open(Pic_Exif, self.picload.getInfo(self.filelist.getCurrentDirectory() + self.filelist.getFilename()))
112
113         def KeyMenu(self):
114                 self.session.openWithCallback(self.setConf, Pic_Setup)
115
116         def KeyOk(self):
117                 if self.filelist.canDescent():
118                         self.filelist.descent()
119                 else:
120                         self.session.openWithCallback(self.callbackView, Pic_Full_View, self.filelist.getFileList(), self.filelist.getSelectionIndex(), self.filelist.getCurrentDirectory())
121
122         def setConf(self, retval=None):
123                 self.setTitle(_("Picture player"))
124                 sc = getScale()
125                 #0=Width 1=Height 2=Aspect 3=use_cache 4=resize_type 5=Background(#AARRGGBB)
126                 self.picload.setPara((self["thn"].instance.size().width(), self["thn"].instance.size().height(), sc[0], sc[1], config.pic.cache.value, int(config.pic.resize.value), "#00000000", config.pic.autoOrientation.value))
127
128         def callbackView(self, val=0):
129                 if val > 0:
130                         self.filelist.moveToIndex(val)
131
132         def KeyExit(self):
133                 del self.picload
134
135                 if self.filelist.getCurrentDirectory() is None:
136                         config.pic.lastDir.value = "/"
137                 else:
138                         config.pic.lastDir.value = self.filelist.getCurrentDirectory()
139
140                 config.pic.save()
141                 self.close()
142
143 #------------------------------------------------------------------------------------------
144
145 class Pic_Setup(Screen, ConfigListScreen):
146
147         def __init__(self, session):
148                 Screen.__init__(self, session)
149                 # for the skin: first try MediaPlayerSettings, then Setup, this allows individual skinning
150                 self.skinName = ["PicturePlayerSetup", "Setup"]
151                 self.setup_title = _("Settings")
152                 self.onChangedEntry = []
153                 self.session = session
154                 ConfigListScreen.__init__(self, [], session = session, on_change = self.changedEntry)
155                 self["actions"] = ActionMap(["SetupActions", "MenuActions"],
156                         {
157                                 "cancel": self.keyCancel,
158                                 "save": self.keySave,
159                                 "ok": self.keySave,
160                                 "menu": self.closeRecursive,
161                         }, -2)
162                 self["key_red"] = StaticText(_("Cancel"))
163                 self["key_green"] = StaticText(_("OK"))
164                 self.createSetup()
165                 self.onLayoutFinish.append(self.layoutFinished)
166
167         def layoutFinished(self):
168                 self.setTitle(self.setup_title)
169
170         def createSetup(self):
171                 setup_list = [
172                         getConfigListEntry(_("Slide show interval (sec.)"), config.pic.slidetime),
173                         getConfigListEntry(_("Scaling mode"), config.pic.resize),
174                         getConfigListEntry(_("Cache thumbnails"), config.pic.cache),
175                         getConfigListEntry(_("Show info line"), config.pic.infoline),
176                         getConfigListEntry(_("Frame size in full view"), config.pic.framesize),
177                         getConfigListEntry(_("Slide picture in loop"), config.pic.loop),
178                         getConfigListEntry(_("Background color"), config.pic.bgcolor),
179                         getConfigListEntry(_("Text color"), config.pic.textcolor),
180                         getConfigListEntry(_("Fulview resulution"), config.usage.pic_resolution),
181                         getConfigListEntry(_("Auto EXIF Orientation rotation/flipping"), config.pic.autoOrientation),
182                 ]
183                 self["config"].list = setup_list
184                 self["config"].l.setList(setup_list)
185
186         def keyLeft(self):
187                 ConfigListScreen.keyLeft(self)
188
189         def keyRight(self):
190                 ConfigListScreen.keyRight(self)
191
192         # for summary:
193         def changedEntry(self):
194                 for x in self.onChangedEntry:
195                         x()
196
197         def getCurrentEntry(self):
198                 return self["config"].getCurrent()[0]
199
200         def getCurrentValue(self):
201                 return str(self["config"].getCurrent()[1].getText())
202
203         def createSummary(self):
204                 from Screens.Setup import SetupSummary
205                 return SetupSummary
206
207 #---------------------------------------------------------------------------
208
209 class Pic_Exif(Screen):
210         skin = """
211                 <screen name="Pic_Exif" position="center,center" size="560,360" title="Info" >
212                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
213                         <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" />
214                         <widget source="menu" render="Listbox" position="5,50" size="550,310" scrollbarMode="showOnDemand" selectionDisabled="1" >
215                                 <convert type="TemplatedMultiContent">
216                                 {
217                                         "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)],
218                                         "fonts": [gFont("Regular", 20)],
219                                         "itemHeight": 30
220                                 }
221                                 </convert>
222                         </widget>
223                 </screen>"""
224
225         def __init__(self, session, exiflist):
226                 Screen.__init__(self, session)
227
228                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
229                 {
230                         "cancel": self.close
231                 }, -1)
232
233                 self["key_red"] = StaticText(_("Close"))
234
235                 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:"]
236                 list = []
237
238                 for x in range(len(exiflist)):
239                         if x>0:
240                                 list.append((exifdesc[x], exiflist[x]))
241                         else:
242                                 name = exiflist[x].split('/')[-1]
243                                 list.append((exifdesc[x], name))
244                 self["menu"] = List(list)
245                 self.onLayoutFinish.append(self.layoutFinished)
246
247         def layoutFinished(self):
248                 self.setTitle(_("Info"))
249
250 #----------------------------------------------------------------------------------------
251
252 T_INDEX = 0
253 T_FRAME_POS = 1
254 T_PAGE = 2
255 T_NAME = 3
256 T_FULL = 4
257
258 class Pic_Thumb(Screen):
259         def __init__(self, session, piclist, lastindex, path):
260
261                 self.textcolor = config.pic.textcolor.value
262                 self.color = config.pic.bgcolor.value
263                 self.spaceX, self.picX, self.spaceY, self.picY, textsize, thumtxt  = skin.parameters.get("PicturePlayerThumb",(35, 190, 30, 200, 20, 14))
264
265                 pic_frame = resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/pic_frame.png")
266
267                 size_w = getDesktop(0).size().width()
268                 size_h = getDesktop(0).size().height()
269                 self.thumbsX = size_w / (self.spaceX + self.picX) # thumbnails in X
270                 self.thumbsY = size_h / (self.spaceY + self.picY) # thumbnails in Y
271                 self.thumbsC = self.thumbsX * self.thumbsY # all thumbnails
272
273                 self.positionlist = []
274                 skincontent = ""
275
276                 posX = -1
277                 for x in range(self.thumbsC):
278                         posY = x / self.thumbsX
279                         posX += 1
280                         if posX >= self.thumbsX:
281                                 posX = 0
282
283                         absX = self.spaceX + (posX*(self.spaceX + self.picX))
284                         absY = self.spaceY + (posY*(self.spaceY + self.picY))
285                         self.positionlist.append((absX, absY))
286                         skincontent += "<widget source=\"label" + str(x) + "\" render=\"Label\" position=\"" + str(absX+5) + "," + str(absY+self.picY-textsize) + "\" size=\"" + str(self.picX - 10) + ","  + str(textsize) \
287                                         + "\" font=\"Regular;" + str(thumtxt) + "\" zPosition=\"2\" transparent=\"1\" noWrap=\"1\" foregroundColor=\"" + self.textcolor + "\" />"
288                         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\" alphatest=\"on\" />"
289
290                 # Screen, backgroundlabel and MovingPixmap
291                 self.skin = "<screen position=\"0,0\" size=\"" + str(size_w) + "," + str(size_h) + "\" flags=\"wfNoBorder\" > \
292                         <eLabel position=\"0,0\" zPosition=\"0\" size=\""+ str(size_w) + "," + str(size_h) + "\" backgroundColor=\"" + self.color + "\" />" \
293                         + "<widget name=\"frame\" position=\"" + str(self.spaceX)+ "," + str(self.spaceY)+ "\" size=\"" + str(self.picX) + "," + str(self.picY) + "\" pixmap=\"" + pic_frame + "\" zPosition=\"1\" alphatest=\"on\" />" \
294                         + skincontent + "</screen>"
295
296                 Screen.__init__(self, session)
297
298                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "DirectionActions", "MovieSelectionActions"],
299                 {
300                         "cancel": self.Exit,
301                         "ok": self.KeyOk,
302                         "left": self.key_left,
303                         "right": self.key_right,
304                         "up": self.key_up,
305                         "down": self.key_down,
306                         "showEventInfo": self.StartExif,
307                 }, -1)
308
309                 self["frame"] = MovingPixmap()
310                 for x in range(self.thumbsC):
311                         self["label"+str(x)] = StaticText()
312                         self["thumb"+str(x)] = Pixmap()
313
314                 self.Thumbnaillist = []
315                 self.filelist = []
316                 self.currPage = -1
317                 self.dirlistcount = 0
318                 self.path = path
319
320                 index = 0
321                 framePos = 0
322                 Page = 0
323                 for x in piclist:
324                         if x[0][1] == False:
325                                 self.filelist.append((index, framePos, Page, x[0][0],  path + x[0][0]))
326                                 index += 1
327                                 framePos += 1
328                                 if framePos > (self.thumbsC -1):
329                                         framePos = 0
330                                         Page += 1
331                         else:
332                                 self.dirlistcount += 1
333
334                 self.maxentry = len(self.filelist)-1
335                 self.index = lastindex - self.dirlistcount
336                 if self.index < 0:
337                         self.index = 0
338
339                 self.picload = ePicLoad()
340                 self.picload.PictureData.get().append(self.showPic)
341
342                 self.onLayoutFinish.append(self.setPicloadConf)
343
344                 self.ThumbTimer = eTimer()
345                 self.ThumbTimer.callback.append(self.showPic)
346
347         def setPicloadConf(self):
348                 sc = getScale()
349                 self.picload.setPara([self["thumb0"].instance.size().width(), self["thumb0"].instance.size().height(), sc[0], sc[1], config.pic.cache.value, int(config.pic.resize.value), self.color, config.pic.autoOrientation.value])
350                 self.paintFrame()
351
352         def paintFrame(self):
353                 #print "index=" + str(self.index)
354                 if self.maxentry < self.index or self.index < 0:
355                         return
356
357                 pos = self.positionlist[self.filelist[self.index][T_FRAME_POS]]
358                 self["frame"].moveTo( pos[0], pos[1], 1)
359                 self["frame"].startMoving()
360
361                 if self.currPage != self.filelist[self.index][T_PAGE]:
362                         self.currPage = self.filelist[self.index][T_PAGE]
363                         self.newPage()
364
365         def newPage(self):
366                 self.Thumbnaillist = []
367                 #clear Labels and Thumbnail
368                 for x in range(self.thumbsC):
369                         self["label"+str(x)].setText("")
370                         self["thumb"+str(x)].hide()
371                 #paint Labels and fill Thumbnail-List
372                 for x in self.filelist:
373                         if x[T_PAGE] == self.currPage:
374                                 self["label"+str(x[T_FRAME_POS])].setText("(" + str(x[T_INDEX]+1) + ") " + x[T_NAME])
375                                 self.Thumbnaillist.append([0, x[T_FRAME_POS], x[T_FULL]])
376
377                 #paint Thumbnail start
378                 self.showPic()
379
380         def showPic(self, picInfo=""):
381                 for x in range(len(self.Thumbnaillist)):
382                         if self.Thumbnaillist[x][0] == 0:
383                                 if self.picload.getThumbnail(self.Thumbnaillist[x][2]) == 1: #zu tun probier noch mal
384                                         self.ThumbTimer.start(500, True)
385                                 else:
386                                         self.Thumbnaillist[x][0] = 1
387                                 break
388                         elif self.Thumbnaillist[x][0] == 1:
389                                 self.Thumbnaillist[x][0] = 2
390                                 ptr = self.picload.getData()
391                                 if ptr != None:
392                                         self["thumb" + str(self.Thumbnaillist[x][1])].instance.setPixmap(ptr.__deref__())
393                                         self["thumb" + str(self.Thumbnaillist[x][1])].show()
394
395         def key_left(self):
396                 self.index -= 1
397                 if self.index < 0:
398                         self.index = self.maxentry
399                 self.paintFrame()
400
401         def key_right(self):
402                 self.index += 1
403                 if self.index > self.maxentry:
404                         self.index = 0
405                 self.paintFrame()
406
407         def key_up(self):
408                 self.index -= self.thumbsX
409                 if self.index < 0:
410                         self.index =self.maxentry
411                 self.paintFrame()
412
413         def key_down(self):
414                 self.index += self.thumbsX
415                 if self.index > self.maxentry:
416                         self.index = 0
417                 self.paintFrame()
418
419         def StartExif(self):
420                 if self.maxentry < 0:
421                         return
422                 self.session.open(Pic_Exif, self.picload.getInfo(self.filelist[self.index][T_FULL]))
423
424         def KeyOk(self):
425                 if self.maxentry < 0:
426                         return
427                 self.old_index = self.index
428                 self.session.openWithCallback(self.callbackView, Pic_Full_View, self.filelist, self.index, self.path)
429
430         def callbackView(self, val=0):
431                 self.index = val
432                 if self.old_index != self.index:
433                         self.paintFrame()
434         def Exit(self):
435                 del self.picload
436                 self.close(self.index + self.dirlistcount)
437
438 #---------------------------------------------------------------------------
439
440 class Pic_Full_View(Screen):
441         def __init__(self, session, filelist, index, path):
442
443                 self.textcolor = config.pic.textcolor.value
444                 self.bgcolor = config.pic.bgcolor.value
445                 space = config.pic.framesize.value
446
447                 self.size_w = size_w = getDesktop(0).size().width()
448                 self.size_h = size_h = getDesktop(0).size().height()
449
450                 if config.usage.pic_resolution.value and (size_w, size_h) != eval(config.usage.pic_resolution.value):
451                         (size_w, size_h) = eval(config.usage.pic_resolution.value)
452                         gMainDC.getInstance().setResolution(size_w, size_h)
453                         getDesktop(0).resize(eSize(size_w, size_h))
454
455                 self.skin = "<screen position=\"0,0\" size=\"" + str(size_w) + "," + str(size_h) + "\" flags=\"wfNoBorder\" > \
456                         <eLabel position=\"0,0\" zPosition=\"0\" size=\""+ str(size_w) + "," + str(size_h) + "\" backgroundColor=\""+ self.bgcolor +"\" /><widget name=\"pic\" position=\"" + str(space) + "," + str(space) + "\" size=\"" + str(size_w-(space*2)) + "," + str(size_h-(space*2)) + "\" zPosition=\"1\" alphatest=\"on\" /> \
457                         <widget name=\"point\" position=\""+ str(space+5) + "," + str(space+2) + "\" size=\"20,20\" zPosition=\"2\" pixmap=\"skin_default/icons/record.png\" alphatest=\"on\" /> \
458                         <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\" /> \
459                         <widget source=\"file\" render=\"Label\" position=\""+ str(space+45) + "," + str(space) + "\" size=\""+ str(size_w-(space*2)-50) + ",25\" font=\"Regular;20\" borderWidth=\"1\" borderColor=\"#000000\" halign=\"left\" foregroundColor=\"" + self.textcolor + "\" zPosition=\"2\" noWrap=\"1\" transparent=\"1\" /></screen>"
460
461                 Screen.__init__(self, session)
462
463                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "DirectionActions", "MovieSelectionActions"],
464                 {
465                         "cancel": self.Exit,
466                         "green": self.PlayPause,
467                         "yellow": self.PlayPause,
468                         "blue": self.nextPic,
469                         "red": self.prevPic,
470                         "left": self.prevPic,
471                         "right": self.nextPic,
472                         "showEventInfo": self.StartExif,
473                         "contextMenu": self.KeyMenu,
474                 }, -1)
475
476                 self["point"] = Pixmap()
477                 self["pic"] = Pixmap()
478                 self["play_icon"] = Pixmap()
479                 self["file"] = StaticText(_("please wait, loading picture..."))
480
481                 self.old_index = 0
482                 self.filelist = []
483                 self.lastindex = index
484                 self.currPic = []
485                 self.shownow = True
486                 self.dirlistcount = 0
487
488                 for x in filelist:
489                         if len(filelist[0]) == 3: #orig. filelist
490                                 if x[0][1] == False:
491                                         self.filelist.append(path + x[0][0])
492                                 else:
493                                         self.dirlistcount += 1
494                         elif len(filelist[0]) == 2: #scanlist
495                                 if x[0][1] == False:
496                                         self.filelist.append(x[0][0])
497                                 else:
498                                         self.dirlistcount += 1
499                         else: # thumbnaillist
500                                 self.filelist.append(x[T_FULL])
501
502                 self.maxentry = len(self.filelist)-1
503                 self.index = index - self.dirlistcount
504                 if self.index < 0:
505                         self.index = 0
506
507                 self.picload = ePicLoad()
508                 self.picload.PictureData.get().append(self.finish_decode)
509
510                 self.slideTimer = eTimer()
511                 self.slideTimer.callback.append(self.slidePic)
512
513                 if self.maxentry >= 0:
514                         self.onLayoutFinish.append(self.setPicloadConf)
515
516         def setPicloadConf(self):
517                 self.setConf()
518                 self["play_icon"].hide()
519                 if config.pic.infoline.value == False:
520                         self["file"].setText("")
521                 self.start_decode()
522
523         def setConf(self, retval=None):
524                 sc = getScale()
525                 #0=Width 1=Height 2=Aspect 3=use_cache 4=resize_type 5=Background(#AARRGGBB)
526                 self.picload.setPara([self["pic"].instance.size().width(), self["pic"].instance.size().height(), sc[0], sc[1], 0, int(config.pic.resize.value), self.bgcolor, config.pic.autoOrientation.value])
527
528         def ShowPicture(self):
529                 if self.shownow and len(self.currPic):
530                         self.shownow = False
531                         if config.pic.infoline.value:
532                                 self["file"].setText(self.currPic[0])
533                         else:
534                                 self["file"].setText("")
535                         self.lastindex = self.currPic[1]
536                         self["pic"].instance.setPixmap(self.currPic[2].__deref__())
537                         self.currPic = []
538
539                         self.next()
540                         self.start_decode()
541
542         def finish_decode(self, picInfo=""):
543                 self["point"].hide()
544                 ptr = self.picload.getData()
545                 if ptr != None:
546                         text = ""
547                         try:
548                                 text = picInfo.split('\n',1)
549                                 text = "(" + str(self.index+1) + "/" + str(self.maxentry+1) + ") " + text[0].split('/')[-1]
550                         except:
551                                 pass
552                         self.currPic = []
553                         self.currPic.append(text)
554                         self.currPic.append(self.index)
555                         self.currPic.append(ptr)
556                         self.ShowPicture()
557
558         def start_decode(self):
559                 self.picload.startDecode(self.filelist[self.index])
560                 self["point"].show()
561
562         def next(self):
563                 self.index += 1
564                 if self.index > self.maxentry:
565                         self.index = 0
566
567         def prev(self):
568                 self.index -= 1
569                 if self.index < 0:
570                         self.index = self.maxentry
571
572         def slidePic(self):
573                 print "slide to next Picture index=" + str(self.lastindex)
574                 if config.pic.loop.value==False and self.lastindex == self.maxentry:
575                         self.PlayPause()
576                 self.shownow = True
577                 self.ShowPicture()
578
579         def PlayPause(self):
580                 if self.slideTimer.isActive():
581                         self.slideTimer.stop()
582                         self["play_icon"].hide()
583                 else:
584                         self.slideTimer.start(config.pic.slidetime.value*1000)
585                         self["play_icon"].show()
586                         self.nextPic()
587
588         def prevPic(self):
589                 self.currPic = []
590                 self.index = self.lastindex
591                 self.prev()
592                 self.start_decode()
593                 self.shownow = True
594
595         def nextPic(self):
596                 self.shownow = True
597                 self.ShowPicture()
598
599         def StartExif(self):
600                 if self.maxentry < 0:
601                         return
602                 self.session.open(Pic_Exif, self.picload.getInfo(self.filelist[self.lastindex]))
603
604         def KeyMenu(self):
605                 self.session.openWithCallback(self.setConf, Pic_Setup)
606
607         def Exit(self):
608                 del self.picload
609
610                 if config.usage.pic_resolution.value and (self.size_w, self.size_h) != eval(config.usage.pic_resolution.value):
611                         gMainDC.getInstance().setResolution(self.size_w, self.size_h)
612                         getDesktop(0).resize(eSize(self.size_w, self.size_h))
613
614                 self.close(self.lastindex + self.dirlistcount)