41857375d9512233b4f7cf1f8fcd17e3e9ee3cb1
[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                 
18                 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions"], 
19                 {
20                         "ok": self.save,
21                         "cancel": self.close,
22                         "up": self.up,
23                         "down": self.down,
24                         "left": self.left,
25                         "right": self.right
26                 }, -1)
27                 
28         def save(self):
29                 self.run()
30                 self.close()
31         
32         def run(self):
33                 language.activateLanguage(self["list"].l.getCurrentSelectionIndex())
34                 config.osd.language.value = self["list"].l.getCurrentSelectionIndex()
35                 config.osd.language.save()
36                 self.session.currentDialog.instance.setTitle(_("Language selection"))
37
38         def updateList(self):
39                 self.list = []
40                 if len(language.lang) == 0: # no language available => display only english
41                         self.list.append(LanguageEntryComponent("en", _("English")))
42                 else:
43                         for x in language.lang:
44                                 self.list.append(LanguageEntryComponent(x[3].lower(), _(x[0])))
45                 
46                 self["list"].l.setList(self.list)
47
48         def up(self):
49                 self["list"].instance.moveSelection(self["list"].instance.moveUp)
50                 self.run()
51                 self.updateList()
52                 
53         def down(self):
54                 self["list"].instance.moveSelection(self["list"].instance.moveDown)
55                 self.run()
56                 self.updateList()
57
58         def left(self):
59                 self["list"].instance.moveSelection(self["list"].instance.pageUp)
60                 self.run()
61                 self.updateList()
62                 
63         def right(self):
64                 self["list"].instance.moveSelection(self["list"].instance.pageDown)
65                 self.run()
66                 self.updateList()