moving the list generation to a seperate method
[enigma2.git] / lib / python / Components / MovieList.py
1 from HTMLComponent import *
2 from GUIComponent import *
3
4 from enigma import eListboxPythonMultiContent, eListbox, gFont
5
6 from enigma import eServiceReference, eServiceCenter, \
7         eServiceCenterPtr, iListableServicePtr, \
8         iStaticServiceInformationPtr
9
10 RT_HALIGN_LEFT = 0
11 RT_HALIGN_RIGHT = 1
12 RT_HALIGN_CENTER = 2
13 RT_HALIGN_BLOCK = 4
14
15 RT_VALIGN_TOP = 0
16 RT_VALIGN_CENTER = 8
17 RT_VALIGN_BOTTOM = 16
18
19 RT_WRAP = 32
20
21
22 #
23 # | name of movie              |
24 #
25 def MovieListEntry(serviceref, serviceHandler):
26         res = [ serviceref ]
27
28         info = serviceHandler.info(serviceref)
29         
30         if info is None:
31                 # ignore service which refuse to info
32                 return
33         
34         len = info.getLength(serviceref)
35         if len:
36                 len = "%d:%02d" % (len / 60, len % 60)
37         else:
38                 len = "?:??"
39         
40         res.append((0, 0, 400, 30, 0, RT_HALIGN_LEFT, info.getName(serviceref)))
41         res.append((0, 30, 200, 20, 1, RT_HALIGN_LEFT, "Toller Film"))
42         res.append((0, 50, 200, 20, 1, RT_HALIGN_LEFT, "Aufgenommen: irgendwann"))
43         res.append((200, 50, 200, 20, 1, RT_HALIGN_RIGHT, len))
44         
45         return res
46
47 class MovieList(HTMLComponent, GUIComponent):
48         def __init__(self, root):
49                 GUIComponent.__init__(self)
50                 self.l = eListboxPythonMultiContent()
51                 self.load(root)
52                 self.l.setList(self.list)
53                 self.l.setFont(0, gFont("Arial", 30))
54                 self.l.setFont(1, gFont("Arial", 18))
55         
56         def getCurrent(self):
57                 return self.l.getCurrentSelection()
58         
59         def GUIcreate(self, parent):
60                 self.instance = eListbox(parent)
61                 self.instance.setContent(self.l)
62                 self.instance.setItemHeight(75)
63         
64         def GUIdelete(self):
65                 self.instance.setContent(None)
66                 self.instance = None
67
68         def load(self, root):
69                 # this lists our root service, then building a 
70                 # nice list
71                 
72                 self.list = [ ]
73                 self.root = root
74                 
75                 serviceHandler = eServiceCenter.getInstance()
76                 list = serviceHandler.list(root)
77                 
78                 if list is None:
79                         raise "listing of movies failed"
80
81                 movieList = [ ]
82                 while 1:
83                         s = list.getNext()
84                         if not s.valid():
85                                 del list
86                                 break
87                         movieList.append(s)
88                 
89                 # now process them...
90                 for ref in movieList:
91                         self.list.append(MovieListEntry(ref, serviceHandler))
92
93         def reload(self):
94                 self.load(self.root)
95                 self.l.setList(self.list)