commited for debugging with 3c5x9
[enigma2-plugins.git] / webinterface / src / WebComponents / Sources / WAPfunctions.py
1 Version = '$Header$';
2
3 from enigma import *
4 from Components.Sources.Source import Source
5
6 import time, re#, sys
7 #import sys 
8
9 #sys.setdefaultencoding('utf8')
10
11 class WAPfunctions( Source):
12     FILLOPTIONLIST = 0
13     
14     def __init__(self, session,func = FILLOPTIONLIST):
15         self.func = func
16         Source.__init__(self)        
17         self.session = session
18         self.result = False,"unknown command"
19
20     def handleCommand(self,cmd):
21         print "WAPfunctions: handleCommand"
22         if self.func is self.FILLOPTIONLIST:
23             self.result = self.fillOptionList(cmd)
24         else:
25             self.result = False,"unknown command cmd(%s) self.func(%s)" % (cmd, self.func)
26
27     def fillOptionList(self,param):
28         # is there an easier and better way? :\ 
29         print "fillOptionList",param
30         #del param["sRef"]
31
32         input = 0
33         start = 1
34         end = 1
35         
36         timeNow = time.time()
37         timePlusTwo = timeNow + 7200
38         
39         t = {}
40         t["sday"]=time.strftime("%d", time.localtime(timeNow))
41         t["smonth"]=time.strftime("%m", time.localtime(timeNow))
42         t["syear"]=time.strftime("%Y", time.localtime(timeNow))
43         t["sminute"]=time.strftime("%M", time.localtime(timeNow))
44         t["shour"]=time.strftime("%H", time.localtime(timeNow))
45         
46         t["eday"]=time.strftime("%d", time.localtime(timePlusTwo))
47         t["emonth"]=time.strftime("%m", time.localtime(timePlusTwo))
48         t["eyear"]=time.strftime("%Y", time.localtime(timePlusTwo))
49         t["eminute"]=time.strftime("%M", time.localtime(timePlusTwo))
50         t["ehour"]=time.strftime("%H", time.localtime(timePlusTwo))
51         
52         key = ""
53         for i in param:
54             p = str(i)
55             if p != "sRef":
56                 key = p
57
58         print "key: ",key
59         cutKey = re.sub("^[es]", "", key, 1)
60         print "cutKey: ",cutKey
61         
62         if cutKey == "min":
63             start = 0
64             end = 59
65         elif cutKey == "hour":
66             start = 1
67             end = 24
68         elif cutKey == "day":
69             start = 1
70             end = 31
71         elif cutKey == "month":
72             start = 1
73             end = 12
74         else:
75             start = int(t[key])
76             end = int(t[key])+2
77         
78         if(param[key] == "now"):
79             input = int(t[key])
80         else:
81             input = int(param[key]) or 0
82         
83         self.result = self.fillOptionListAny(input,start,end)
84         return self.result
85     
86     def fillOptionListAny(self,input,start,end):
87         returnList = []
88         print input,start,end
89         for i in range(start,end+1,1):
90             returnList1 = []
91             returnList1.append(i)
92             returnList1.append(i)
93             if i==input:
94                 returnList1.append("selected")
95             else:
96                 returnList1.append("")
97             returnList.append(returnList1)
98         return returnList
99         
100     def getText(self):
101         print self.result
102         (result,text) = self.result
103         return text
104     
105     def getList(self):
106         print self.result
107         return self.result
108     
109     text = property(getText)
110     
111     ## part for listfiller requests
112     def command(self):
113         timerlist = []
114
115         return timerlist
116     
117     list = property(getList)
118     lut = {"Name":0
119           ,"Value":1
120           ,"Selected":2
121           }