whitespace cleanup
[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.oldActiveLanguage = language.getActiveLanguage()
15
16                 self.list = []
17                 self["list"] = LanguageList(self.list)
18                 self.updateList()
19                 self.onLayoutFinish.append(self.selectActiveLanguage)
20
21                 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions"], 
22                 {
23                         "ok": self.save,
24                         "cancel": self.cancel,
25                         "up": self.up,
26                         "down": self.down,
27                         "left": self.left,
28                         "right": self.right
29                 }, -1)
30
31         def selectActiveLanguage(self):
32                 activeLanguage = language.getActiveLanguage()
33                 pos = 0
34                 for x in self.list:
35                         if x[0] == activeLanguage:
36                                 self["list"].instance.moveSelectionTo(pos)
37                                 break
38                         pos += 1
39
40         def save(self):
41                 self.run()
42                 self.close()
43
44         def cancel(self):
45                 language.activateLanguage(self.oldActiveLanguage)
46                 self.close()
47
48         def run(self):
49                 language.activateLanguage(self["list"].l.getCurrentSelection()[0])
50                 config.osd.language.value = self["list"].l.getCurrentSelection()[0]
51                 config.osd.language.save()
52                 config.misc.languageselected.value = 0
53                 config.misc.languageselected.save()
54                 self.setTitle(_("Language selection"))
55
56         def updateList(self):
57                 self.list = []
58                 if len(language.getLanguageList()) == 0: # no language available => display only english
59                         self.list.append(LanguageEntryComponent("en", _("English"), "en_EN"))
60                 else:
61                         for x in language.getLanguageList():
62                                 self.list.append(LanguageEntryComponent(file = x[1][3].lower(), name = _(x[1][0]), index = x[0]))
63                 #self.list.sort(key=lambda x: x[1][7])
64                 self["list"].l.setList(self.list)
65
66         def up(self):
67                 self["list"].instance.moveSelection(self["list"].instance.moveUp)
68                 self.run()
69                 self.updateList()
70
71         def down(self):
72                 self["list"].instance.moveSelection(self["list"].instance.moveDown)
73                 self.run()
74                 self.updateList()
75
76         def left(self):
77                 self["list"].instance.moveSelection(self["list"].instance.pageUp)
78                 self.run()
79                 self.updateList()
80
81         def right(self):
82                 self["list"].instance.moveSelection(self["list"].instance.pageDown)
83                 self.run()
84                 self.updateList()