1 from HTMLComponent import *
2 from GUIComponent import *
3 from config import KEY_LEFT, KEY_RIGHT, KEY_0, KEY_DELETE, KEY_OK, KEY_TIMEOUT
4 from Components.ActionMap import NumberActionMap
5 from enigma import eListbox, eListboxPythonConfigContent, eTimer
7 class ConfigList(HTMLComponent, GUIComponent, object):
8 def __init__(self, list, session = None):
9 GUIComponent.__init__(self)
10 self.l = eListboxPythonConfigContent()
11 self.l.setSeperation(100)
13 self.onSelectionChanged = [ ]
15 self.help_window = None
16 self.setHelpWindowSession(session)
19 self.timer.timeout.get().append(self.timeout)
21 def setHelpWindowSession(self, session):
22 assert self.help_window is None, "you can't move a help window to another session"
23 self.session = session
26 selection = self.getCurrent()
28 self.invalidateCurrent()
30 def handleKey(self, key):
31 selection = self.getCurrent()
32 if selection[1].enabled:
33 selection[1].handleKey(key)
34 self.invalidateCurrent()
36 self.help_window.update(selection[1])
37 if key not in [KEY_TIMEOUT, KEY_LEFT, KEY_RIGHT, KEY_DELETE, KEY_OK]:
38 self.timer.start(1000, 1)
41 return self.l.getCurrentSelection()
43 def invalidateCurrent(self):
44 self.l.invalidateEntry(self.l.getCurrentSelectionIndex())
46 def invalidate(self, entry):
47 self.l.invalidateEntry(self.__list.index(entry))
51 def selectionChanged(self):
55 self.session.deleteDialog(self.help_window)
57 nh = n and n[1].helpWindow()
58 if nh is not None and self.session is not None:
59 self.help_window = self.session.instantiateDialog(*nh)
60 self.help_window.show()
63 for x in self.onSelectionChanged:
66 def postWidgetCreate(self, instance):
67 instance.setContent(self.l)
68 instance.selectionChanged.get().append(self.selectionChanged)
70 def preWidgetRemove(self, instance):
71 instance.selectionChanged.get().remove(self.selectionChanged)
73 def setList(self, list):
75 self.l.setList(self.__list)
80 list = property(getList, setList)
83 self.handleKey(KEY_TIMEOUT)
85 class ConfigListScreen:
86 def __init__(self, list, session = None):
87 self["config_actions"] = NumberActionMap(["SetupActions", "TextInputActions"],
91 "right": self.keyRight,
92 "delete": self.keyDelete,
93 "1": self.keyNumberGlobal,
94 "2": self.keyNumberGlobal,
95 "3": self.keyNumberGlobal,
96 "4": self.keyNumberGlobal,
97 "5": self.keyNumberGlobal,
98 "6": self.keyNumberGlobal,
99 "7": self.keyNumberGlobal,
100 "8": self.keyNumberGlobal,
101 "9": self.keyNumberGlobal,
102 "0": self.keyNumberGlobal
105 self["config"] = ConfigList(list, session = session)
108 self["config"].handleKey(KEY_OK)
111 self["config"].handleKey(KEY_LEFT)
114 self["config"].handleKey(KEY_RIGHT)
117 self["config"].handleKey(KEY_DELETE)
119 def keyNumberGlobal(self, number):
120 self["config"].handleKey(KEY_0 + number)