Menu eventinfo/extension: manual re-order list
authordima73 <dima73@dev.null>
Thu, 12 Mar 2015 07:03:53 +0000 (08:03 +0100)
committerlittlesat <littlesat99@yahoo.com>
Thu, 12 Mar 2015 07:03:53 +0000 (08:03 +0100)
-In the menu eventinfo/extension you are now able to re-order list via the < > buttons instantly
-button menu sort list to default and exit

Note: Slightly modified by me

Signed-off-by: littlesat <littlesat99@yahoo.com>

lib/python/Screens/ChoiceBox.py
lib/python/Screens/InfoBarGenerics.py

index 373a39c..6189bcc 100644 (file)
@@ -1,18 +1,25 @@
 from Screens.Screen import Screen
+from Screens.MessageBox import MessageBox
 from Components.ActionMap import NumberActionMap
+from Components.config import config, ConfigSubsection, ConfigText
 from Components.Label import Label
 from Components.ChoiceList import ChoiceEntryComponent, ChoiceList
 from Components.Sources.StaticText import StaticText
 import enigma
 
+config.misc.pluginlist = ConfigSubsection()
+config.misc.pluginlist.eventinfo_order = ConfigText(default="")
+config.misc.pluginlist.extension_order = ConfigText(default="")
+
 class ChoiceBox(Screen):
-       def __init__(self, session, title = "", list = [], keys = None, selection = 0, skin_name = []):
+       def __init__(self, session, title="", list=[], keys=None, selection=0, skin_name=[], reorderConfig=""):
                Screen.__init__(self, session)
 
                if isinstance(skin_name, str):
                        skin_name = [skin_name]
                self.skinName = skin_name + ["ChoiceBox"]
 
+               self.reorderConfig = reorderConfig
                self["text"] = Label(title)
                self.list = []
                self.summarylist = []
@@ -23,6 +30,16 @@ class ChoiceBox(Screen):
 
                self.keymap = {}
                pos = 0
+               if self.reorderConfig:
+                       prev_list = list
+                       new_list = []
+                       self.config_type = eval("config.misc.pluginlist." + self.reorderConfig)
+                       for x in self.config_type.value.split(","):
+                               for entry in prev_list:
+                                       if entry[0] == x:
+                                               new_list.append(entry)
+                                               prev_list.remove(entry)
+                       list = new_list + prev_list
                for x in list:
                        strpos = str(self.__keys[pos])
                        self.list.append(ChoiceEntryComponent(key = strpos, text = x))
@@ -35,7 +52,7 @@ class ChoiceBox(Screen):
                self["summary_selection"] = StaticText()
                self.updateSummary(selection)
 
-               self["actions"] = NumberActionMap(["WizardActions", "InputActions", "ColorActions", "DirectionActions"],
+               self["actions"] = NumberActionMap(["WizardActions", "InputActions", "ColorActions", "DirectionActions", "MenuActions"],
                {
                        "ok": self.go,
                        "back": self.cancel,
@@ -54,7 +71,10 @@ class ChoiceBox(Screen):
                        "yellow": self.keyYellow,
                        "blue": self.keyBlue,
                        "up": self.up,
-                       "down": self.down
+                       "down": self.down,
+                       "moveUp": self.additionalMoveUp,
+                       "moveDown": self.additionalMoveDown,
+                       "menu": self.setDefaultChoiceList
                }, -1)
 
        def autoResize(self):
@@ -160,3 +180,42 @@ class ChoiceBox(Screen):
 
        def cancel(self):
                self.close(None)
+
+       def setDefaultChoiceList(self):
+               if self.reorderConfig:
+                       if len(self.list) > 0 and self.config_type.value != "":
+                               self.session.openWithCallback(self.setDefaultChoiceListCallback, MessageBox, _("Sort list to default and exit?"), MessageBox.TYPE_YESNO)
+               else:
+                       self.cancel()
+
+       def setDefaultChoiceListCallback(self, answer):
+               if answer:
+                       self.config_type.value = ""
+                       self.config_type.save()
+                       self.cancel()
+
+       def additionalMoveUp(self):
+               if self.reorderConfig:
+                       self.additionalMove(-1)
+
+       def additionalMoveDown(self):
+               if self.reorderConfig:
+                       self.additionalMove(1)
+
+       def additionalMove(self, direction):
+               if len(self.list) > 1:
+                       currentIndex = self["list"].getSelectionIndex()
+                       swapIndex = (currentIndex + direction) % len(self.list)
+                       if currentIndex == 0 and swapIndex != 1:
+                               self.list = self.list[1:] + [self.list[0]]
+                       elif swapIndex == 0 and currentIndex != 1:
+                               self.list = [self.list[-1]] + self.list[:-1]
+                       else:
+                               self.list[currentIndex], self.list[swapIndex] = self.list[swapIndex], self.list[currentIndex]
+                       self["list"].l.setList(self.list)
+                       if direction == 1:
+                               self["list"].down()
+                       else:
+                               self["list"].up()
+                       self.config_type.value = ",".join(x[0][0] for x in self.list)
+                       self.config_type.save()
index 23737df..a00285c 100644 (file)
@@ -1043,7 +1043,7 @@ class InfoBarEPG:
        def showEventInfoPlugins(self):
                pluginlist = self.getEPGPluginList()
                if pluginlist:
-                       self.session.openWithCallback(self.EventInfoPluginChosen, ChoiceBox, title=_("Please choose an extension..."), list = pluginlist, skin_name = "EPGExtensionsList")
+                       self.session.openWithCallback(self.EventInfoPluginChosen, ChoiceBox, title=_("Please choose an extension..."), list=pluginlist, skin_name="EPGExtensionsList", reorderConfig="eventinfo_order")
                else:
                        self.openSingleServiceEPG()
 
@@ -2011,7 +2011,7 @@ class InfoBarExtensions:
                list.extend([(x[0](), x) for x in extensionsList])
 
                keys += [""] * len(extensionsList)
-               self.session.openWithCallback(self.extensionCallback, ChoiceBox, title=_("Please choose an extension..."), list = list, keys = keys, skin_name = "ExtensionsList")
+               self.session.openWithCallback(self.extensionCallback, ChoiceBox, title=_("Please choose an extension..."), list=list, keys=keys, skin_name="ExtensionsList", reorderConfig="extension_order")
 
        def extensionCallback(self, answer):
                if answer is not None: