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 4089809569330faf089f47bc6eedb06ee9f35638..4e032d43b963b35c66650b70c5320a7fddaf9d8e 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 e0d626ac499a902398b61bdda7b472fb0dc44a66..fe2172899da7946b5c1ac71fc18cf4200c5741bf 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: