- switchtimer added to RecordingTimer
[enigma2.git] / lib / python / Screens / LanguageSelection.py
1 from Screen import Screen
2
3 from Components.MenuList import MenuList
4 from Components.ActionMap import ActionMap
5 from Components.Language import language
6 from Components.LanguageList import *
7 from Components.config import config
8
9
10 class LanguageSelection(Screen):
11         def __init__(self, session):
12                 Screen.__init__(self, session)
13                 
14                 self.list = []
15                 self["list"] = LanguageList(self.list)
16                 self.updateList()
17                 self.onLayoutFinish.append(self.selectActiveLanguage)
18                                 
19                 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions"], 
20                 {
21                         "ok": self.save,
22                         "cancel": self.close,
23                         "up": self.up,
24                         "down": self.down,
25                         "left": self.left,
26                         "right": self.right
27                 }, -1)
28                 
29         def selectActiveLanguage(self):
30                 activeLanguage = language.getActiveLanguage()
31                 pos = 0
32                 for x in self.list:
33                         if x[0] == activeLanguage:
34                                 self["list"].instance.moveSelectionTo(pos)
35                                 break
36                         pos += 1
37                 
38         def save(self):
39                 self.run()
40                 self.close()
41         
42         def run(self):
43                 language.activateLanguage(self["list"].l.getCurrentSelection()[0])
44                 config.osd.language.value = self["list"].l.getCurrentSelection()[0]
45                 config.osd.language.save()
46                 config.misc.languageselected.value = 0
47                 config.misc.languageselected.save()
48                 self.setTitle(_("Language selection"))
49
50         def updateList(self):
51                 self.list = []
52                 if len(language.getLanguageList()) == 0: # no language available => display only english
53                         self.list.append(LanguageEntryComponent("en", _("English"), "en_EN"))
54                 else:
55                         for x in language.getLanguageList():
56                                 self.list.append(LanguageEntryComponent(file = x[1][3].lower(), name = _(x[1][0]), index = x[0]))
57                 self.list.sort(key=lambda x: x[1][7])
58                 self["list"].l.setList(self.list)
59
60         def up(self):
61                 self["list"].instance.moveSelection(self["list"].instance.moveUp)
62                 self.run()
63                 self.updateList()
64                 
65         def down(self):
66                 self["list"].instance.moveSelection(self["list"].instance.moveDown)
67                 self.run()
68                 self.updateList()
69
70         def left(self):
71                 self["list"].instance.moveSelection(self["list"].instance.pageUp)
72                 self.run()
73                 self.updateList()
74                 
75         def right(self):
76                 self["list"].instance.moveSelection(self["list"].instance.pageDown)
77                 self.run()
78                 self.updateList()