add cvsignore
[enigma2.git] / lib / python / Plugins / Extensions / PicturePlayer / plugin.py
index 91644a2126346328170ec7763021efc599fae2f0..34e8c10f471e017e021d224458ef6f3cce1e13d0 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 Tools.Directories import resolveFilename, pathExists, createDir, SCOPE_MEDIA
 from Components.FileList import FileEntryComponent, FileList
 from Components.AVSwitch import AVSwitch
 
 from Plugins.Plugin import PluginDescriptor
 
 from Components.FileList import FileEntryComponent, FileList
 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"))])
@@ -153,9 +150,10 @@ 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)
                        if ptr != None:
 
                        ptr = loadPic(self.path + self.thumblist[self.thumbindex], 180, 160, self.aspect, int(config.pic.resize.value), int(config.pic.rotate.value),1, cachefile)
                        if ptr != None:
@@ -451,9 +449,9 @@ 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"] = self.filelist
                self["thumbnail"] = Pixmap()
                self.filelist = FileList(currDir, matchingPattern = "(?i)^.*\.(jpeg|jpg|png|bmp)")
                self["filelist"] = self.filelist
                self["thumbnail"] = Pixmap()
@@ -480,15 +478,15 @@ 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)
                        if ptr != None:
                                self["thumbnail"].show()
                                self["thumbnail"].instance.setPixmap(ptr.__deref__())
                        if ptr != None:
                                self["thumbnail"].show()
                                self["thumbnail"].instance.setPixmap(ptr.__deref__())
@@ -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,26 @@ class picmain(Screen):
 def main(session, **kwargs):
        session.open(picmain)
 
 def main(session, **kwargs):
        session.open(picmain)
 
+def filescan_open(list, session, **kwargs):
+       session.open(picmain) # list
+
+def filescan():
+       # we expect not to be called if the MediaScanner plugin is not available,
+       # thus we don't catch an ImportError exception here
+       from Plugins.Extensions.MediaScanner.plugin import Scanner, ScanPath
+       return \
+               Scanner(extensions = ["jpg", "jpe", "jpeg"], 
+                       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)", icon="pictureplayer.png", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=main),
+                PluginDescriptor(name="PicturePlayer", where = PluginDescriptor.WHERE_FILESCAN, fnc = filescan)]