Merge branch 'master' into tmbinc/FixTimingBugs
[enigma2.git] / lib / python / Plugins / Extensions / PicturePlayer / plugin.py
index 91644a2126346328170ec7763021efc599fae2f0..ea906f0dbe1c16fd3ae2a53aaa57e45460efc738 100644 (file)
@@ -1,5 +1,4 @@
-from enigma import *
-
+from enigma import eTimer, loadPic, getExif
 from Screens.Screen import Screen
 from Screens.ServiceInfo import ServiceInfoList, ServiceInfoListEntry
 from Components.ActionMap import ActionMap, NumberActionMap
 from Screens.Screen import Screen
 from Screens.ServiceInfo import ServiceInfoList, ServiceInfoListEntry
 from Components.ActionMap import ActionMap, NumberActionMap
@@ -9,14 +8,12 @@ from Components.Label import Label
 from Components.ConfigList import ConfigList
 from Components.config import *
 
 from Components.ConfigList import ConfigList
 from Components.config import *
 
-from Tools.Directories import resolveFilename, SCOPE_MEDIA
-from Components.FileList import FileEntryComponent, FileList
+from Tools.Directories import resolveFilename, fileExists, pathExists, createDir, SCOPE_MEDIA
+from Components.FileList import FileList
 from Components.AVSwitch import AVSwitch
 
 from Plugins.Plugin import PluginDescriptor
 
 from Components.AVSwitch import AVSwitch
 
 from Plugins.Plugin import PluginDescriptor
 
-import os
-
 config.pic = ConfigSubsection()
 config.pic.slidetime = ConfigInteger(default=10, limits=(5, 60))
 config.pic.resize = ConfigSelection(default="0", choices = [("0", _("simple")), ("1", _("better"))])
 config.pic = ConfigSubsection()
 config.pic.slidetime = ConfigInteger(default=10, limits=(5, 60))
 config.pic.resize = ConfigSelection(default="0", choices = [("0", _("simple")), ("1", _("better"))])
@@ -97,7 +94,7 @@ class ThumbView(Screen):
                        self["label0"].setText(_("no Picture found"))
                
                self.ThumbTimer = eTimer()
                        self["label0"].setText(_("no Picture found"))
                
                self.ThumbTimer = eTimer()
-               self.ThumbTimer.timeout.get().append(self.showThumb)
+               self.ThumbTimer.callback.append(self.showThumb)
 
                self.fillPage()
                
 
                self.fillPage()
                
@@ -153,14 +150,15 @@ class ThumbView(Screen):
                        cachefile = ""
                        if config.pic.cache.value:
                                cachedir = self.path + ".Thumbnails/"
                        cachefile = ""
                        if config.pic.cache.value:
                                cachedir = self.path + ".Thumbnails/"
-                               if not os.path.exists(cachedir):
-                                       os.mkdir(cachedir)
                                cachefile = cachedir + self.thumblist[self.thumbindex] + str(180) + str(160) + str(self.aspect)
                                cachefile = cachedir + self.thumblist[self.thumbindex] + str(180) + str(160) + str(self.aspect)
+                               if not pathExists(cachedir):
+                                       if not createDir(cachedir):
+                                               cachefile = ""
 
 
-                       ptr = loadPic(self.path + self.thumblist[self.thumbindex], 180, 160, self.aspect, int(config.pic.resize.value), int(config.pic.rotate.value),1, cachefile)
+                       ptr = loadPic(self.path + self.thumblist[self.thumbindex], 180, 160, self.aspect, int(config.pic.resize.value), int(config.pic.rotate.value), 1, cachefile, 1)
                        if ptr != None:
                                self["thumb"+str(self.thumbindex)].show()
                        if ptr != None:
                                self["thumb"+str(self.thumbindex)].show()
-                               self["thumb"+str(self.thumbindex)].instance.setPixmap(ptr.__deref__())
+                               self["thumb"+str(self.thumbindex)].instance.setPixmap(ptr)
                        
                        self.thumbindex += 1
                        if self.thumbindex < 6:
                        
                        self.thumbindex += 1
                        if self.thumbindex < 6:
@@ -198,13 +196,13 @@ class PicView(Screen):
                <screen position="0,0" size="720,576" flags="wfNoBorder" title="PicturePlayer" >
                        <eLabel position="0,0" zPosition="0" size="720,576" backgroundColor="black" />
                        <widget name="picture" position="80,50" size="560,450" zPosition="1" transparent="1" />
                <screen position="0,0" size="720,576" flags="wfNoBorder" title="PicturePlayer" >
                        <eLabel position="0,0" zPosition="0" size="720,576" backgroundColor="black" />
                        <widget name="picture" position="80,50" size="560,450" zPosition="1" transparent="1" />
-                       <widget name="point" position="80,515" size="15,15" zPosition="1" pixmap="BlinkingPoint-fs8.png" alphatest="on" />
+                       <widget name="point" position="80,515" size="14,14" zPosition="1" pixmap="skin_default/icons/record.png" alphatest="on" />
                        <widget name="file" position="150,510" size="350,30" font="Regular;20" halign="center" zPosition="1" transparent="1" />
                        <widget name="file" position="150,510" size="350,30" font="Regular;20" halign="center" zPosition="1" transparent="1" />
-                       <ePixmap position="500,515" size="36,20" pixmap="key_info-fs8.png" zPosition="1" alphatest="on" />
-                       <ePixmap position="550,515" size="20,20" pixmap="ico_mp_rewind.png"  zPosition="1" alphatest="on" />
-                       <widget name="play" position="575,515" size="20,20" pixmap="ico_mp_play.png"  zPosition="1" alphatest="on" />
-                       <widget name="pause" position="600,515" size="20,20" pixmap="ico_mp_pause.png"  zPosition="1" alphatest="on" />
-                       <ePixmap position="625,515" size="20,20" pixmap="ico_mp_forward.png"  zPosition="1" alphatest="on" />
+                       <ePixmap position="500,515" size="36,20" pixmap="skin_default/buttons/key_info.png" zPosition="1" alphatest="on" />
+                       <ePixmap position="550,515" size="20,20" pixmap="skin_default/icons/ico_mp_rewind.png"  zPosition="1" alphatest="on" />
+                       <widget name="play" position="575,515" size="20,20" pixmap="skin_default/icons/ico_mp_play.png"  zPosition="1" alphatest="on" />
+                       <widget name="pause" position="600,515" size="20,20" pixmap="skin_default/icons/ico_mp_pause.png"  zPosition="1" alphatest="on" />
+                       <ePixmap position="625,515" size="20,20" pixmap="skin_default/icons/ico_mp_forward.png"  zPosition="1" alphatest="on" />
                </screen>"""
        
        def __init__(self, session, filelist, name, path):
                </screen>"""
        
        def __init__(self, session, filelist, name, path):
@@ -246,11 +244,11 @@ class PicView(Screen):
                self["pause"] = Pixmap()
                
                self.decodeTimer = eTimer()
                self["pause"] = Pixmap()
                
                self.decodeTimer = eTimer()
-               self.decodeTimer.timeout.get().append(self.decodePic)
+               self.decodeTimer.callback.append(self.decodePic)
                self.decodeTimer.start(300, True)
 
                self.slideTimer = eTimer()
                self.decodeTimer.start(300, True)
 
                self.slideTimer = eTimer()
-               self.slideTimer.timeout.get().append(self.slidePic)
+               self.slideTimer.callback.append(self.slidePic)
                
                
        def Pause(self):
                
                
        def Pause(self):
@@ -299,7 +297,7 @@ class PicView(Screen):
                if self.currPic != None:
                        self.old = self.index
                        self["file"].setText(self.list[self.old][0] + "  (" + str(self.old+1) + "/" + str(self.maxentry+1) + ")")
                if self.currPic != None:
                        self.old = self.index
                        self["file"].setText(self.list[self.old][0] + "  (" + str(self.old+1) + "/" + str(self.maxentry+1) + ")")
-                       self["picture"].instance.setPixmap(self.currPic.__deref__())
+                       self["picture"].instance.setPixmap(self.currPic)
 
                self.next()
                self["point"].show()
 
                self.next()
                self["point"].show()
@@ -422,9 +420,9 @@ class PicSetup(Screen):
 class picmain(Screen):
        skin = """
                <screen position="160,90" size="400,390" title="PicturePlayer" >
 class picmain(Screen):
        skin = """
                <screen position="160,90" size="400,390" title="PicturePlayer" >
-                       <ePixmap position="10,40" size="36,20" pixmap="key_menu-fs8.png" transparent="1" alphatest="on" />
-                       <ePixmap position="10,70" size="36,20" pixmap="key_info-fs8.png" transparent="1" alphatest="on" />
-                       <ePixmap position="12,100" size="36,20" pixmap="key_red-fs8.png" transparent="1" alphatest="on" />
+                       <ePixmap position="10,40" size="36,20" pixmap="skin_default/buttons/key_menu.png" transparent="1" alphatest="on" />
+                       <ePixmap position="10,70" size="36,20" pixmap="skin_default/buttons/key_info.png" transparent="1" alphatest="on" />
+                       <ePixmap position="12,100" size="36,20" pixmap="skin_default/buttons/key_red.png" transparent="1" alphatest="on" />
                        <eLabel text="Settings" position="60,40" size="120,25" font="Regular;20" transparent="1" />
                        <eLabel text="Exif-Data" position="60,70" size="120,25" font="Regular;20" transparent="1" />
                        <eLabel text="Thumbnails" position="60,100" size="120,25" font="Regular;20" transparent="1" />
                        <eLabel text="Settings" position="60,40" size="120,25" font="Regular;20" transparent="1" />
                        <eLabel text="Exif-Data" position="60,70" size="120,25" font="Regular;20" transparent="1" />
                        <eLabel text="Thumbnails" position="60,100" size="120,25" font="Regular;20" transparent="1" />
@@ -451,15 +449,15 @@ class picmain(Screen):
                
                self.aspect = getAspect()
                currDir = config.pic.lastDir.value
                
                self.aspect = getAspect()
                currDir = config.pic.lastDir.value
-               if not os.path.exists(currDir):
+               if not pathExists(currDir):
                        currDir = "/"
                        currDir = "/"
-               
-               self.filelist = FileList(currDir, matchingPattern = "(?i)^.*\.(jpeg|jpg|png|bmp)")
+
+               self.filelist = FileList(currDir, matchingPattern = "(?i)^.*\.(jpeg|jpg|jpe|png|bmp|gif)")
                self["filelist"] = self.filelist
                self["thumbnail"] = Pixmap()
                
                self.ThumbTimer = eTimer()
                self["filelist"] = self.filelist
                self["thumbnail"] = Pixmap()
                
                self.ThumbTimer = eTimer()
-               self.ThumbTimer.timeout.get().append(self.showThumb)
+               self.ThumbTimer.callback.append(self.showThumb)
                self.ThumbTimer.start(500, True)
                
        def up(self):
                self.ThumbTimer.start(500, True)
                
        def up(self):
@@ -480,18 +478,18 @@ class picmain(Screen):
 
        def showThumb(self):
                if not self.filelist.canDescent():
 
        def showThumb(self):
                if not self.filelist.canDescent():
-                       print self.filelist.getCurrentDirectory()
                        cachefile = ""
                        if config.pic.cache.value:
                                cachedir = self.filelist.getCurrentDirectory() + ".Thumbnails/"
                        cachefile = ""
                        if config.pic.cache.value:
                                cachedir = self.filelist.getCurrentDirectory() + ".Thumbnails/"
-                               if not os.path.exists(cachedir):
-                                       os.mkdir(cachedir)
-                               cachefile = cachedir + self.filelist.getSelection()[0] + str(180) + str(160) + str(self.aspect)
+                               cachefile = cachedir + self.filelist.getFilename() + str(180) + str(160) + str(self.aspect)
+                               if not pathExists(cachedir):
+                                       if not createDir(cachedir):
+                                               cachefile = ""
 
 
-                       ptr = loadPic(self.filelist.getCurrentDirectory() + self.filelist.getSelection()[0], 180, 160, self.aspect, int(config.pic.resize.value), 0, 0, cachefile)
+                       ptr = loadPic(self.filelist.getCurrentDirectory() + self.filelist.getFilename(), 180, 160, self.aspect, int(config.pic.resize.value), 0, 0, cachefile, 1)
                        if ptr != None:
                                self["thumbnail"].show()
                        if ptr != None:
                                self["thumbnail"].show()
-                               self["thumbnail"].instance.setPixmap(ptr.__deref__())
+                               self["thumbnail"].instance.setPixmap(ptr)
                else:
                        self["thumbnail"].hide()
 
                else:
                        self["thumbnail"].hide()
 
@@ -499,10 +497,10 @@ class picmain(Screen):
                if self.filelist.canDescent():
                        self.filelist.descent()
                else:
                if self.filelist.canDescent():
                        self.filelist.descent()
                else:
-                       self.session.openWithCallback(self.returnVal, PicView, self.filelist.getFileList(), self.filelist.getSelection()[0], self.filelist.getCurrentDirectory())
+                       self.session.openWithCallback(self.returnVal, PicView, self.filelist.getFileList(), self.filelist.getFilename(), self.filelist.getCurrentDirectory())
                        
        def StartThumb(self):
                        
        def StartThumb(self):
-               self.session.openWithCallback(self.returnVal, ThumbView, self.filelist.getFileList(), self.filelist.getSelection()[0], self.filelist.getCurrentDirectory())
+               self.session.openWithCallback(self.returnVal, ThumbView, self.filelist.getFileList(), self.filelist.getFilename(), self.filelist.getCurrentDirectory())
 
        def returnVal(self, val=0):
                if val > 0:
 
        def returnVal(self, val=0):
                if val > 0:
@@ -513,7 +511,7 @@ class picmain(Screen):
 
        def StartExif(self):
                if not self.filelist.canDescent():
 
        def StartExif(self):
                if not self.filelist.canDescent():
-                       self.session.open(ExifView, self.filelist.getCurrentDirectory() + self.filelist.getFilename(), self.filelist.getSelection()[0])
+                       self.session.open(ExifView, self.filelist.getCurrentDirectory() + self.filelist.getFilename(), self.filelist.getFilename())
 
        def Settings(self):
                self.session.open(PicSetup)
 
        def Settings(self):
                self.session.open(PicSetup)
@@ -523,6 +521,7 @@ class picmain(Screen):
                        config.pic.lastDir.value = "/"
                else:
                        config.pic.lastDir.value = self.filelist.getCurrentDirectory()
                        config.pic.lastDir.value = "/"
                else:
                        config.pic.lastDir.value = self.filelist.getCurrentDirectory()
+
                config.pic.save()
                self.close()
 
                config.pic.save()
                self.close()
 
@@ -531,5 +530,32 @@ class picmain(Screen):
 def main(session, **kwargs):
        session.open(picmain)
 
 def main(session, **kwargs):
        session.open(picmain)
 
+def filescan_open(list, session, **kwargs):
+       # Recreate List as expected by PicView
+       filelist = [((file.path, False), None) for file in list]
+       session.open(PicView, filelist, "", "")
+
+def filescan(**kwargs):
+       from Components.Scanner import Scanner, ScanPath
+
+       # Overwrite checkFile to only detect local
+       class LocalScanner(Scanner):
+               def checkFile(self, file):
+                       return fileExists(file.path)
+
+       return \
+               LocalScanner(mimetypes = ["image/jpeg", "image/png", "image/gif", "image/bmp"],
+                       paths_to_scan = 
+                               [
+                                       ScanPath(path = "DCIM", with_subdirs = True),
+                                       ScanPath(path = "", with_subdirs = False),
+                               ],
+                       name = "Pictures", 
+                       description = "View Photos...",
+                       openfnc = filescan_open,
+               )
+
 def Plugins(**kwargs):
 def Plugins(**kwargs):
-       return PluginDescriptor(name="PicturePlayer", description="Picture Viewer (BMP, PNG, JPG)", icon="pictureplayer.png", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main)
+       return \
+               [PluginDescriptor(name="PicturePlayer", description="Picture Viewer (BMP, PNG, JPG, GIF)", icon="pictureplayer.png", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main),
+                PluginDescriptor(name="PicturePlayer", where = PluginDescriptor.WHERE_FILESCAN, fnc = filescan)]