adding support for fullscreen in HD screens
[enigma2-plugins.git] / webcamviewer / src / PictureScreen.py
1 from enigma import loadPic
2 from enigma import eTimer
3 from enigma import getDesktop
4
5 from Screens.Screen import Screen
6 from Components.AVSwitch import AVSwitch
7 from Components.config import config
8 from Components.Pixmap import Pixmap
9 from Components.ActionMap import ActionMap
10 from twisted.web.client import downloadPage
11
12 class PictureScreen(Screen):
13     skin = ""
14     prozessing =False # if fetching or converting is active
15     autoreload =False
16     def __init__(self, session,title,filename, slideshowcallback = None,args=0):
17         self.session=session
18         self.slideshowcallback=slideshowcallback
19         self.screentitle = title
20         ##
21         size_w = getDesktop(0).size().width()   
22         size_h = getDesktop(0).size().height()          
23         self.skin = """
24         <screen position="0,0" size="%i,%i" title="%s" flags=\"wfNoBorder\">
25              <widget name="pixmap" position="0,0" size="%i,%i" backgroundColor=\"black\"/>
26         </screen>""" % (size_w,size_h,filename,size_w,size_h)
27         Screen.__init__(self, session)
28         self.filename = filename
29         self["pixmap"] = Pixmap()
30         
31         self["actions"] = ActionMap(["WizardActions", "DirectionActions","ChannelSelectBaseActions","ShortcutActions"], 
32             {
33              "ok": self.do,
34              "back": self.exit,
35              "green":self.AutoReloaderSwitch,
36              }, -1)
37         
38         self.onLayoutFinish.append(self.do)
39         
40     def AutoReloaderSwitch(self):
41         if self.filename.startswith("http") or self.filename.startswith("ftp"):            
42             if self.autoreload is False:
43                 self.autoreload = True
44                 self.do()
45             else:
46                 self.autoreload = False
47             
48     def do(self): 
49         if self.prozessing:
50             pass       
51         elif self.filename.startswith("http") or self.filename.startswith("ftp"):            
52             self.fetchFile(self.filename)
53         else:
54             self.sourcefile = self.filename
55             self.setPicture(self.filename)
56
57     def exit(self):
58         self.cleanUP()
59         self.close()
60
61     def cleanUP(self):
62         try:
63             if os.path.exists("/tmp/loadedfile"):
64                 os.remove("/tmp/loadedfile")
65         except:## OSerror??
66             pass
67     
68     def fetchFile(self,url):
69         self.prozessing =True        
70         self.setTitle("loading File")
71         print "fetching URL ",url
72         self.sourcefile = "/tmp/loadedfile"
73         downloadPage(url,self.sourcefile).addCallback(self.fetchFinished).addErrback(self.fetchFailed)
74             
75         
76     def fetchFailed(self,string):
77         print "fetch failed",string
78         self.setTitle( "fetch failed: "+string)
79         
80     def fetchFinished(self,string):
81         print "fetching finished "
82         self.setPicture(self.sourcefile)   
83               
84     def setPicture(self,string):
85         self.setTitle(self.filename.split("/")[-1])        
86         pixmap = loadPic(string,getDesktop(0).size().width(),getDesktop(0).size().height(), AVSwitch().getAspectRatioSetting()/2,1, 0,1)
87         if pixmap is not None:
88             self["pixmap"].instance.setPixmap(pixmap)
89         self.prozessing =False
90         
91         if self.autoreload is True:
92                 self.cleanUP()
93                 self.do()
94         elif self.slideshowcallback is not None:
95                 self.closetimer = eTimer()
96                 self.closetimer.timeout.get().append(self.slideshowcallback)
97                 print "waiting ",config.plugins.pictureviewer.slideshowtime.value," seconds for next picture"
98                 self.closetimer.start(int(config.plugins.pictureviewer.slideshowtime.value))
99