ignore applySkin when skinAttributes is None
[enigma2.git] / lib / python / Plugins / Extensions / GraphMultiEPG / GraphMultiEpg.py
index d8c654bc3972426f0d9fb3943d6f2b4ba2692254..9040539a61749953b4869d6940bf250010ddcce2 100644 (file)
@@ -1,16 +1,18 @@
+from skin import parseColor
 from Components.config import config, ConfigClock, ConfigInteger
-from Components.Button import Button
 from Components.Pixmap import Pixmap
+from Components.Button import Button
 from Components.ActionMap import ActionMap
 from Components.HTMLComponent import HTMLComponent
 from Components.GUIComponent import GUIComponent
 from Components.EpgList import Rect
 from Components.Sources.Event import Event
-from Components.Sources.Clock import Clock
+from Components.Sources.Source import ObsoleteSource
 from Screens.Screen import Screen
 from Screens.EventView import EventViewSimple
 from Screens.TimeDateInput import TimeDateInput
 from Screens.TimerEntry import TimerEntry
+from Screens.EpgSelection import EPGSelection
 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE
 from RecordTimer import RecordTimerEntry, parseEvent
 from ServiceReference import ServiceReference
@@ -39,7 +41,29 @@ class EPGList(HTMLComponent, GUIComponent):
                self.time_base = None
                self.time_epoch = time_epoch
                self.list = None
-               self.entry_rect = None
+               self.event_rect = None
+
+               self.foreColor = None
+               self.borderColor = None
+               self.backColor = 0x586d88
+               self.backColorSelected = 0x808080
+
+       def applySkin(self, desktop):
+               if self.skinAttributes is not None:
+                       attribs = [ ]
+                       for (attrib, value) in self.skinAttributes:
+                               if attrib == "EntryForegroundColor":
+                                       self.foreColor = parseColor(value).argb()
+                               elif attrib == "EntryBorderColor":
+                                       self.borderColor = parseColor(value).argb()
+                               elif attrib == "EntryBackgroundColor":
+                                       self.backColor = parseColor(value).argb()
+                               elif attrib == "EntryBackgroundColorSelected":
+                                       self.backColorSelected = parseColor(value).argb()
+                               else:
+                                       attribs.append((attrib,value))
+                       self.skinAttributes = attribs
+               return GUIComponent.applySkin(self, desktop)
 
        def isSelectable(self, service, sname, event_list):
                return (event_list and len(event_list) and True) or False
@@ -138,7 +162,7 @@ class EPGList(HTMLComponent, GUIComponent):
                xpos += w;
                w = width/10*8;
                self.event_rect = Rect(xpos, 0, w, height)
-               self.l.setSelectionClip(eRect(xpos, 0, w, height), False)
+               self.l.setSelectionClip(eRect(0,0,0,0), False)
 
        def calcEntryPosAndWidthHelper(self, stime, duration, start, end, width):
                xpos = (stime - start) * width / (end - start)
@@ -160,52 +184,61 @@ class EPGList(HTMLComponent, GUIComponent):
                r2=self.event_rect
                res = [ None ] # no private data needed
                res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, service_name))
-               start = self.time_base+self.offs*self.time_epoch*60
-               end = start + self.time_epoch * 60
-               left = r2.left()
-               top = r2.top()
-               width = r2.width()
-               height = r2.height()
+
                if events:
+                       start = self.time_base+self.offs*self.time_epoch*60
+                       end = start + self.time_epoch * 60
+                       left = r2.left()
+                       top = r2.top()
+                       width = r2.width()
+                       height = r2.height()
+                       foreColor = self.foreColor
+                       backColor = self.backColor
+                       backColorSelected = self.backColorSelected
+                       borderColor = self.borderColor
+
                        for ev in events:  #(event_id, event_title, begin_time, duration)
                                rec=self.timer.isInTimer(ev[0], ev[2], ev[3], service) > ((ev[3]/10)*8)
                                xpos, ewidth = self.calcEntryPosAndWidthHelper(ev[2], ev[3], start, end, width)
-                               res.append((eListboxPythonMultiContent.TYPE_TEXT, left+xpos, top, ewidth, height, 1, RT_HALIGN_CENTER|RT_VALIGN_CENTER|RT_WRAP, ev[1], None, 0x586d88, 0x808080, 1))
+                               if self.borderColor is None:
+                                       res.append((eListboxPythonMultiContent.TYPE_TEXT, left+xpos, top, ewidth, height, 1, RT_HALIGN_CENTER|RT_VALIGN_CENTER|RT_WRAP, ev[1], foreColor, backColor, backColorSelected, 1))
+                               else:
+                                       res.append((eListboxPythonMultiContent.TYPE_TEXT, left+xpos, top, ewidth, height, 1, RT_HALIGN_CENTER|RT_VALIGN_CENTER|RT_WRAP, ev[1], foreColor, backColor, backColorSelected, 1, borderColor))
                                if rec and ewidth > 23:
-                                       res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, left+xpos+ewidth-22, top+height-22, 21, 21, self.clock_pixmap, 0x586d88, 0x808080))
+                                       res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, left+xpos+ewidth-22, top+height-22, 21, 21, self.clock_pixmap, backColor, backColorSelected))
                return res
 
-       def selEntry(self, dir):
+       def selEntry(self, dir, visible=True):
                cur_service = self.cur_service #(service, service_name, events)
-               if not self.entry_rect:
+               if not self.event_rect:
                        self.recalcEntrySize()
                if cur_service and self.cur_event is not None:
                        update = True
                        entries = cur_service[2]
                        if dir == 0: #current
                                update = False
-                               pass
                        elif dir == +1: #next
                                if self.cur_event+1 < len(entries):
                                        self.cur_event+=1
                                else:
                                        self.offs += 1
                                        self.fillMultiEPG(None) # refill
-                                       return
+                                       return True
                        elif dir == -1: #prev
                                if self.cur_event-1 >= 0:
                                        self.cur_event-=1
                                elif self.offs > 0:
                                        self.offs -= 1
                                        self.fillMultiEPG(None) # refill
-                                       return
+                                       return True
                        entry = entries[self.cur_event] #(event_id, event_title, begin_time, duration)
                        time_base = self.time_base+self.offs*self.time_epoch*60
                        xpos, width = self.calcEntryPosAndWidth(self.event_rect, time_base, self.time_epoch, entry[2], entry[3])
-                       self.l.setSelectionClip(eRect(xpos, 0, width, self.event_rect.height()), update)
+                       self.l.setSelectionClip(eRect(xpos, 0, width, self.event_rect.height()), visible and update)
                else:
                        self.l.setSelectionClip(eRect(self.event_rect.left(), self.event_rect.top(), self.event_rect.width(), self.event_rect.height()), False)
                self.selectionChanged()
+               return False
 
        def queryEPG(self, list, buildFunc=None):
                if self.epgcache is not None:
@@ -246,13 +279,17 @@ class EPGList(HTMLComponent, GUIComponent):
                self.findBestEvent()
 
        def getEventRect(self):
-               return self.event_rect
+               rc = self.event_rect
+               return Rect( rc.left() + (self.instance and self.instance.position().x() or 0), rc.top(), rc.width(), rc.height() )
 
        def getTimeEpoch(self):
                return self.time_epoch
 
        def getTimeBase(self):
-               return self.time_base
+               return self.time_base + (self.offs * self.time_epoch * 60)
+
+       def resetOffset(self):
+               self.offs = 0
 
 class TimelineText(HTMLComponent, GUIComponent):
        def __init__(self):
@@ -291,7 +328,7 @@ class GraphMultiEPG(Screen):
                self["key_green"] = Button(_("Add timer"))
                self["timeline_text"] = TimelineText()
                self["Event"] = Event()
-               self["Clock"] = Clock()
+               self["Clock"] = ObsoleteSource(new_source = "global.CurrentTime", removal_date = "2008-01")
                self.time_lines = [ ]
                for x in (0,1,2,3,4,5):
                        pm = Pixmap()
@@ -318,8 +355,8 @@ class GraphMultiEPG(Screen):
 
                self["input_actions"] = ActionMap(["InputActions"],
                        {
-                               "left": self.prevEvent,
-                               "right": self.nextEvent,
+                               "left": self.leftPressed,
+                               "right": self.rightPressed,
                                "1": self.key1,
                                "2": self.key2,
                                "3": self.key3,
@@ -332,11 +369,21 @@ class GraphMultiEPG(Screen):
                self.updateTimelineTimer.start(60*1000)
                self.onLayoutFinish.append(self.onCreate)
 
-       def nextEvent(self):
-               self["list"].selEntry(+1)
+       def leftPressed(self):
+               self.prevEvent()
+
+       def rightPressed(self):
+               self.nextEvent()
+
+       def nextEvent(self, visible=True):
+               ret = self["list"].selEntry(+1, visible)
+               if ret:
+                       self.moveTimeLines(True)
 
-       def prevEvent(self):
-               self["list"].selEntry(-1)
+       def prevEvent(self, visible=True):
+               ret = self["list"].selEntry(-1, visible)
+               if ret:
+                       self.moveTimeLines(True)
 
        def key1(self):
                self["list"].setEpoch(60)
@@ -378,8 +425,10 @@ class GraphMultiEPG(Screen):
                if len(ret) > 1:
                        if ret[0]:
                                self.ask_time=ret[1]
-                               self["list"].fillMultiEPG(self.services, ret[1])
-                               self.moveTimeLines()
+                               l = self["list"]
+                               l.resetOffset()
+                               l.fillMultiEPG(self.services, ret[1])
+                               self.moveTimeLines(True)
 
        def closeScreen(self):
                self.close(self.closeRecursive)
@@ -407,9 +456,9 @@ class GraphMultiEPG(Screen):
                l = self["list"]
                old = l.getCurrent()
                if val == -1:
-                       l.selEntry(-1)
+                       self.prevEvent(False)
                elif val == +1:
-                       self.selEntry(+1)
+                       self.nextEvent(False)
                cur = l.getCurrent()
                if cur[0] is None and cur[1].ref != old[1].ref:
                        self.eventViewCallback(setEvent, setService, val)
@@ -454,7 +503,7 @@ class GraphMultiEPG(Screen):
                        else:
                                self["key_red"].setText("")
 
-       def moveTimeLines(self):
+       def moveTimeLines(self, force=False):
                l = self["list"]
                event_rect = l.getEventRect()
                time_epoch = l.getTimeEpoch()
@@ -483,7 +532,7 @@ class GraphMultiEPG(Screen):
                        x += 1
                        pos += incWidth
 
-               if changecount:
+               if changecount or force:
                        self["timeline_text"].setEntries(timeline_entries)
 
                now=time()