From b2cb2cf5a88d2df60af474ced13e3c90891cf841 Mon Sep 17 00:00:00 2001 From: Stefan Pluecken Date: Sat, 4 Mar 2006 18:18:46 +0000 Subject: [PATCH] enhance usability of ZappingAlternatives plugin --- lib/python/Components/MenuList.py | 4 +++ .../Extensions/ZappingAlternatives/plugin.py | 28 ++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/python/Components/MenuList.py b/lib/python/Components/MenuList.py index 40898095..4e032d43 100644 --- a/lib/python/Components/MenuList.py +++ b/lib/python/Components/MenuList.py @@ -26,3 +26,7 @@ class MenuList(HTMLComponent, GUIComponent): 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 diff --git a/lib/python/Plugins/Extensions/ZappingAlternatives/plugin.py b/lib/python/Plugins/Extensions/ZappingAlternatives/plugin.py index e0d626ac..fe217289 100644 --- a/lib/python/Plugins/Extensions/ZappingAlternatives/plugin.py +++ b/lib/python/Plugins/Extensions/ZappingAlternatives/plugin.py @@ -36,6 +36,9 @@ def removeAlternative(service1, 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 = """ @@ -167,17 +170,27 @@ class AlternativeZapping(Screen): 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"].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("") + + 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 = [] @@ -188,17 +201,18 @@ class AlternativeZapping(Screen): 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): - 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.selectService(serviceString) def yellowKey(self): if len(self.serviceslist) > 0: -- 2.30.2