[EventList Converter and Renderer]: initial checkin of eventlist converter and render...
[enigma2-plugins.git] / eventlist / src / EventListDisplay.py
1 # -*- coding: utf-8 -*-
2 #
3 # EventListDisplay - Renderer
4 #
5 # Coded by Dr.Best (c) 2013
6 # Support: www.dreambox-tools.info
7 # E-Mail: dr.best@dreambox-tools.info
8 #
9 # This plugin is open source but it is NOT free software.
10 #
11 # This plugin may only be distributed to and executed on hardware which
12 # is licensed by Dream Multimedia GmbH.
13 # In other words:
14 # It's NOT allowed to distribute any parts of this plugin or its source code in ANY way
15 # to hardware which is NOT licensed by Dream Multimedia GmbH.
16 # It's NOT allowed to execute this plugin and its source code or even parts of it in ANY way
17 # on hardware which is NOT licensed by Dream Multimedia GmbH.
18 #
19 # If you want to use or modify the code or parts of it,
20 # you have to keep MY license and inform me about the modifications by mail.
21 #
22
23 from Renderer import Renderer
24 from enigma import eCanvas, eRect, gFont
25 from skin import parseColor, parseFont
26
27 class EventListDisplay(Renderer):
28         GUI_WIDGET = eCanvas
29
30         def __init__(self):
31                 Renderer.__init__(self)
32                 self.backgroundColor = parseColor("#ff000000")
33                 self.rowHeight = 20
34                 self.columns = {}
35                 self.primetimeoffset = 10
36
37         def pull_updates(self):
38                 if self.instance is None:
39                         return
40                 self.instance.clear(self.backgroundColor)
41                 content = self.source.getContent()
42                 content_count = len(content)
43                 primetime = self.source.primetime
44                 if primetime == 1 and content_count == 1:
45                         primetime = 0
46                 y = 0
47                 a = 1
48                 for item in content:
49                         i = 0
50                         while i < 3:
51                                 if self.columns.has_key(str(i)):
52                                         value = self.columns[str(i)]
53                                         self.instance.writeText(eRect(value[0], y+int((self.rowHeight-value[4])/2), value[1], self.rowHeight), value[2], self.backgroundColor, value[3], item[value[5]], value[6])
54                                 i += 1
55                         a += 1
56                         y += self.rowHeight
57                         if a == content_count and primetime == 1:
58                                 y += self.primetimeoffset
59
60         def changed(self, what):
61                 self.pull_updates()
62
63         def applySkin(self, desktop, parent):
64
65                 attribs = [ ]
66                 from enigma import eSize
67
68                 def parseSize(str):
69                         x, y = str.split(',')
70                         return eSize(int(x), int(y))
71         
72                 def parseColumnValue(value):
73                         x, length, color, fontname, fontheight, align, itemindex = value.split(',')
74                         return (int(x), int(length), parseColor(color), gFont(fontname,int(fontheight)), int(fontheight), int(itemindex), int(align))
75
76                 for (attrib, value) in self.skinAttributes:
77                         if attrib == "size":
78                                 self.instance.setSize(parseSize(value))
79                                 attribs.append((attrib,value))
80                         elif attrib == "column0":
81                                 self.columns["0"] = parseColumnValue(value)
82                         elif attrib == "column1":
83                                 self.columns["1"] = parseColumnValue(value)
84                         elif attrib == "column2":
85                                 self.columns["2"] = parseColumnValue(value)
86                         elif attrib == "rowHeight":
87                                 self.rowHeight = int(value)
88                         elif attrib == "primetimeoffset":
89                                 self.primetimeoffset = int(value)
90                         elif attrib == "backgroundColor":
91                                 self.backgroundColor = parseColor(value)
92                                 self.instance.clear(self.backgroundColor)
93                                 attribs.append((attrib,value))
94                         else:
95                                 attribs.append((attrib,value))
96                 self.skinAttributes = attribs
97                 return Renderer.applySkin(self, desktop, parent)
98