drop autotimerpreviewlist in favour of a list->templatedmulticontent->listbox chain
authorMoritz Venn <ritzmo@users.schwerkraft.elitedvb.net>
Sun, 1 Mar 2009 20:34:05 +0000 (20:34 +0000)
committerMoritz Venn <ritzmo@users.schwerkraft.elitedvb.net>
Sun, 1 Mar 2009 20:34:05 +0000 (20:34 +0000)
autotimer/src/AutoTimerList.py
autotimer/src/AutoTimerPreview.py

index 0403096..3e08dc4 100644 (file)
@@ -9,9 +9,6 @@ from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, \
 
 from skin import parseColor, parseFont
 
-from ServiceReference import ServiceReference
-from Tools.FuzzyDate import FuzzyTime
-
 class AutoTimerList(MenuList):
        """Defines a simple Component to show Timer name"""
 
@@ -68,70 +65,3 @@ class AutoTimerList(MenuList):
                                break
                        idx += 1
 
-class AutoTimerPreviewList(MenuList):
-       """Preview Timers, emulates TimerList"""
-
-       def __init__(self, entries):
-               MenuList.__init__(self, entries, False, content = eListboxPythonMultiContent)
-
-               self.serviceNameFont = gFont("Regular", 20)
-               self.l.setFont(0, self.serviceNameFont)
-               self.font = gFont("Regular", 18)
-               self.l.setFont(1, self.font)
-               self.l.setBuildFunc(self.buildListboxEntry)
-               self.l.setItemHeight(70)
-
-       def applySkin(self, desktop, parent):
-               attribs = [ ] 
-               if self.skinAttributes is not None:
-                       for (attrib, value) in self.skinAttributes:
-                               if attrib == "font":
-                                       self.font = parseFont(value, ((1,1),(1,1)))
-                                       self.l.setFont(1, self.font)
-                               elif attrib == "serviceNameFont":
-                                       self.serviceNameFont = parseFont(value, ((1,1),(1,1)))
-                                       self.l.setFont(0, self.serviceNameFont)
-                               elif attrib == "colorDisabled":
-                                       self.colorDisabled = int(parseColor(value))
-                               elif attrib == "itemHeight":
-                                       self.l.setItemHeight(int(value))
-                               else:
-                                       attribs.append((attrib, value))
-               self.skinAttributes = attribs
-               return MenuList.applySkin(self, desktop, parent)
-
-       #
-       #  | <Service>     <Name of the Event>  |
-       #  | <start, end>  <Name of AutoTimer>  |
-       #
-       def buildListboxEntry(self, name, begin, end, serviceref, timername):
-               size = self.l.getItemSize()
-               width = size.width()
-               snameHeight = self.serviceNameFont.pointSize + 10
-               fontSize = self.font.pointSize + 2
-               lastRow = snameHeight + fontSize
-
-               return [
-                       None,
-                       (eListboxPythonMultiContent.TYPE_TEXT, 0, 0, width, snameHeight, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, \
-                                       ServiceReference(serviceref).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')),
-                       (eListboxPythonMultiContent.TYPE_TEXT, 0, snameHeight, width, fontSize, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, name),
-                       (eListboxPythonMultiContent.TYPE_TEXT, 0, lastRow, 400, fontSize, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, \
-                                       (("%s, %s ... %s (%d " + _("mins") + ")") % (FuzzyTime(begin) + FuzzyTime(end)[1:] + ((end - begin) / 60,)))),
-                       (eListboxPythonMultiContent.TYPE_TEXT, width - 245, lastRow, 240, fontSize, 1, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, timername)
-               ]
-
-       def invalidate(self):
-               self.l.invalidate()
-
-       def moveToEntry(self, entry):
-               if entry is None:
-                       return
-
-               idx = 0
-               for x in self.list:
-                       if x == entry:
-                               self.instance.moveSelectionTo(idx)
-                               break
-                       idx += 1
-
index 14358f2..5ffa76f 100644 (file)
@@ -7,13 +7,28 @@ from Screens.Screen import Screen
 # GUI (Components)
 from Components.ActionMap import ActionMap
 from Components.Button import Button
-from AutoTimerList import AutoTimerPreviewList
+from Components.Sources.List import List
+
+from ServiceReference import ServiceReference
+from Tools.FuzzyDate import FuzzyTime
 
 class AutoTimerPreview(Screen):
        """Preview Timers which would be set"""
 
        skin = """<screen name="AutoTimerPreview" title="Preview AutoTimer" position="75,155" size="565,265">
-               <widget name="timerlist" position="5,5" size="555,210" scrollbarMode="showOnDemand" />
+               <widget source="timerlist" render="Listbox" position="5,5" size="555,210" scrollbarMode="showOnDemand">
+                       <convert type="TemplatedMultiContent">
+                               {"template": [
+                                               MultiContentEntryText(pos=(2,2), size=(550,24), text = 3, font = 0, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER),
+                                               MultiContentEntryText(pos=(2,26), size=(555,30), text = 0, font = 1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER),
+                                               MultiContentEntryText(pos=(2,50), size=(400,20), text = 4, font = 1, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER),
+                                               MultiContentEntryText(pos=(320,50), size=(233,20), text = 2, font = 1, flags = RT_HALIGN_RIGHT|RT_VALIGN_CENTER),
+                                       ],
+                                "fonts": [gFont("Regular", 20),gFont("Regular", 18)],
+                                "itemHeight": 72
+                               }
+                       </convert>
+               </widget>
                <ePixmap position="0,220" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
                <ePixmap position="280,220" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
                <widget name="key_red" position="0,220" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
@@ -27,9 +42,15 @@ class AutoTimerPreview(Screen):
                timers.sort(key = lambda x: x[1])
                self.sort_type = 0
 
-               self.timers = timers
+               # name, begin, end, serviceref, timername -> name, begin, timername, sname, timestr
+               self.timers = [
+                       (x[0], x[1], x[4],
+                       ServiceReference(x[3]).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '').encode('utf-8', 'ignore'),
+                       (("%s, %s ... %s (%d " + _("mins") + ")") % (FuzzyTime(x[1]) + FuzzyTime(x[2])[1:] + ((x[2] - x[1]) / 60,))))
+                       for x in timers
+               ]
 
-               self["timerlist"] = AutoTimerPreviewList(timers)
+               self["timerlist"] = List(self.timers)
 
                # Initialize Buttons
                self["key_red"] = Button(_("Cancel"))
@@ -59,16 +80,21 @@ class AutoTimerPreview(Screen):
 
        def sort(self):
                timers = self.timers
-               if len(timers):
-                       timer = self["timerlist"].getCurrent()
+               if timers:
+                       current = self["timerlist"].current
+                       idx = 0
+                       for timer in timers:
+                               if timer == current:
+                                       break
+                               idx += 1
                        if self.sort_type == 1:
                                timers.sort(key=lambda x: x[1])
                                self.sort_type = 0
                        else:
                                timers.sort(key = lambda x: x[4].lower())
                                self.sort_type = 1
-                       self["timerlist"].setList(timers)
-                       self["timerlist"].moveToEntry(timer)
+                       self["timerlist"].updateList(timers)
+                       self["timerlist"].index = idx
                        self.setSortDescription()
 
        def cancel(self):