correct polarity
[enigma2.git] / lib / python / Components / ConfigList.py
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
6
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)
12                 self.list = list
13                 self.onSelectionChanged = [ ]
14                 self.current = None
15                 self.help_window = None
16                 self.setHelpWindowSession(session)
17                 
18                 self.timer = eTimer()
19                 self.timer.timeout.get().append(self.timeout)
20         
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
24
25         def toggle(self):
26                 selection = self.getCurrent()
27                 selection[1].toggle()
28                 self.invalidateCurrent()
29
30         def handleKey(self, key):
31                 selection = self.getCurrent()
32                 if selection[1].enabled:
33                         selection[1].handleKey(key)
34                         self.invalidateCurrent()
35                         if self.help_window:
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)
39
40         def getCurrent(self):
41                 return self.l.getCurrentSelection()
42         
43         def invalidateCurrent(self):
44                 self.l.invalidateEntry(self.l.getCurrentSelectionIndex())
45                 
46         def invalidate(self, entry):
47                 self.l.invalidateEntry(self.__list.index(entry))
48
49         GUI_WIDGET = eListbox
50         
51         def selectionChanged(self):
52                 n = self.getCurrent()
53                 
54                 if self.help_window:
55                         self.session.deleteDialog(self.help_window)
56                 
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()
61
62                 self.current = n
63                 for x in self.onSelectionChanged:
64                         x()
65
66         def postWidgetCreate(self, instance):
67                 instance.setContent(self.l)
68                 instance.selectionChanged.get().append(self.selectionChanged)
69         
70         def preWidgetRemove(self, instance):
71                 instance.selectionChanged.get().remove(self.selectionChanged)
72         
73         def setList(self, list):
74                 self.__list = list
75                 self.l.setList(self.__list)
76
77         def getList(self):
78                 return self.__list
79
80         list = property(getList, setList)
81
82         def timeout(self):
83                 self.handleKey(KEY_TIMEOUT)
84
85 class ConfigListScreen:
86         def __init__(self, list, session = None):
87                 self["config_actions"] = NumberActionMap(["SetupActions", "TextInputActions"],
88                 {
89                         "ok": self.keyOK,
90                         "left": self.keyLeft,
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
103                 }, 5)
104
105                 self["config"] = ConfigList(list, session = session)
106
107         def keyOK(self):
108                 self["config"].handleKey(KEY_OK)
109
110         def keyLeft(self):
111                 self["config"].handleKey(KEY_LEFT)
112
113         def keyRight(self):
114                 self["config"].handleKey(KEY_RIGHT)
115
116         def keyDelete(self):
117                 self["config"].handleKey(KEY_DELETE)
118
119         def keyNumberGlobal(self, number):
120                 self["config"].handleKey(KEY_0 + number)