enhance usability of ZappingAlternatives plugin
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Sat, 4 Mar 2006 18:18:46 +0000 (18:18 +0000)
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Sat, 4 Mar 2006 18:18:46 +0000 (18:18 +0000)
lib/python/Components/MenuList.py
lib/python/Plugins/Extensions/ZappingAlternatives/plugin.py

index 4089809..4e032d4 100644 (file)
@@ -26,3 +26,7 @@ class MenuList(HTMLComponent, GUIComponent):
        def selectionChanged(self):
                for f in self.onSelectionChanged:
                        f()
        def selectionChanged(self):
                for f in self.onSelectionChanged:
                        f()
+
+       def setList(self, list):
+               self.list = list
+               self.l.setList(self.list)
\ No newline at end of file
index e0d626a..fe21728 100644 (file)
@@ -36,6 +36,9 @@ def removeAlternative(service1, service2):
                del alternatives[service1]
        if len(alternatives[service2]) == 0:
                del alternatives[service2]
                del alternatives[service1]
        if len(alternatives[service2]) == 0:
                del alternatives[service2]
+
+def sortKey(x):
+       return str.lower(ServiceReference(x).getServiceName().strip())
                        
 class AlternativeZapping(Screen):
        skin = """
                        
 class AlternativeZapping(Screen):
        skin = """
@@ -167,17 +170,27 @@ class AlternativeZapping(Screen):
        
        def updateServices(self):
                self.serviceslist = []
        
        def updateServices(self):
                self.serviceslist = []
-               
-               for x in self.alternatives.keys():
+               keys = self.alternatives.keys()
+               keys.sort(key = sortKey)
+               for x in keys:
                        self.serviceslist.append((ServiceReference(x).getServiceName(), x))
                        
                        self.serviceslist.append((ServiceReference(x).getServiceName(), x))
                        
-               self["serviceslist"].l.setList(self.serviceslist)
+               self["serviceslist"].setList(self.serviceslist)
                if len(self.serviceslist) > 0:
                        self.yellow.setText(_("Add alternative"))
                        self.red.setText(_("Remove service"))
                else:
                        self.yellow.setText("")
                        self.red.setText("")
                if len(self.serviceslist) > 0:
                        self.yellow.setText(_("Add alternative"))
                        self.red.setText(_("Remove service"))
                else:
                        self.yellow.setText("")
                        self.red.setText("")
+       
+       def selectService(self, ref):
+               count = 0
+               for x in self["serviceslist"].list:
+                       if x[1] == ref:
+                               self["serviceslist"].instance.moveSelectionTo(count)
+                               return
+                       count += 1
+                       
                        
        def updateAlternatives(self):
                self.alternativeslist = []
                        
        def updateAlternatives(self):
                self.alternativeslist = []
@@ -188,17 +201,18 @@ class AlternativeZapping(Screen):
                        for x in alternativelist:
                                self.alternativeslist.append((ServiceReference(x).getServiceName(), x))
                        
                        for x in alternativelist:
                                self.alternativeslist.append((ServiceReference(x).getServiceName(), x))
                        
-               self["alternativeslist"].l.setList(self.alternativeslist)
+               self["alternativeslist"].setList(self.alternativeslist)
                        
        def greenKey(self):
                self.session.openWithCallback(self.finishedChannelSelection, SimpleChannelSelection, _("Select reference service"))
 
        def finishedChannelSelection(self, args):
                        
        def greenKey(self):
                self.session.openWithCallback(self.finishedChannelSelection, SimpleChannelSelection, _("Select reference service"))
 
        def finishedChannelSelection(self, args):
-               if not self.alternatives.has_key(str(ServiceReference(args))):
-                       self.alternatives[str(ServiceReference(args))] = []
-               print "alternatives:", self.alternatives
+               serviceString = str(ServiceReference(args))
+               if not self.alternatives.has_key(serviceString):
+                       self.alternatives[serviceString] = []
                self.updateServices()
                self.updateAlternatives()
                self.updateServices()
                self.updateAlternatives()
+               self.selectService(serviceString)
 
        def yellowKey(self):
                if len(self.serviceslist) > 0:
 
        def yellowKey(self):
                if len(self.serviceslist) > 0: