update sv, hy, lt, pl, fr language
[enigma2.git] / lib / python / Screens / LanguageSelection.py
1 from Screen import Screen
2
3 from Components.ActionMap import ActionMap
4 from Components.Language import language
5 from Components.config import config
6 from Components.Sources.List import List
7 from Components.Label import Label
8 from Components.Pixmap import Pixmap
9
10 from Screens.Rc import Rc
11
12 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE
13
14 from Tools.LoadPixmap import LoadPixmap
15
16 def LanguageEntryComponent(file, name, index):
17         png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "countries/" + file + ".png"))
18         if png == None:
19                 png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "countries/missing.png"))
20         res = (index, name, png)
21         return res
22
23 class LanguageSelection(Screen):
24         def __init__(self, session):
25                 Screen.__init__(self, session)
26
27                 self.oldActiveLanguage = language.getActiveLanguage()
28
29                 self.list = []
30                 self["languages"] = List(self.list)
31                 self["languages"].onSelectionChanged.append(self.changed)
32
33                 self.updateList()
34                 self.onLayoutFinish.append(self.selectActiveLanguage)
35
36                 self["actions"] = ActionMap(["OkCancelActions"], 
37                 {
38                         "ok": self.save,
39                         "cancel": self.cancel,
40                 }, -1)
41
42         def selectActiveLanguage(self):
43                 activeLanguage = language.getActiveLanguage()
44                 pos = 0
45                 for x in self.list:
46                         if x[0] == activeLanguage:
47                                 self["languages"].index = pos
48                                 break
49                         pos += 1
50
51         def save(self):
52                 self.run()
53                 self.close()
54
55         def cancel(self):
56                 language.activateLanguage(self.oldActiveLanguage)
57                 self.close()
58
59         def run(self):
60                 print "updating language..."
61                 lang = self["languages"].getCurrent()[0]
62                 language.activateLanguage(lang)
63                 config.osd.language.value = lang
64                 config.osd.language.save()
65                 config.misc.languageselected.value = 0
66                 config.misc.languageselected.save()
67                 self.setTitle(_("Language selection"))
68                 print "ok"
69
70         def updateList(self):
71                 print "update list"
72                 first_time = len(self.list) == 0
73
74                 self.list = []
75                 if len(language.getLanguageList()) == 0: # no language available => display only english
76                         self.list.append(LanguageEntryComponent("en", _("English"), "en_EN"))
77                 else:
78                         for x in language.getLanguageList():
79                                 self.list.append(LanguageEntryComponent(file = x[1][2].lower(), name = _(x[1][0]), index = x[0]))
80                 #self.list.sort(key=lambda x: x[1][7])
81
82                 print "updateList"
83                 if first_time:
84                         self["languages"].list = self.list
85                 else:
86                         self["languages"].updateList(self.list)
87                 print "done"
88
89         def changed(self):
90                 self.run()
91                 self.updateList()
92
93 class LanguageWizard(LanguageSelection, Rc):
94         def __init__(self, session):
95                 LanguageSelection.__init__(self, session)
96                 Rc.__init__(self)
97                 self.onLayoutFinish.append(self.selectKeys)
98                                 
99                 self["wizard"] = Pixmap()
100                 self["text"] = Label()
101                 self.setText()
102                 
103         def selectKeys(self):
104                 self.clearSelectedKeys()
105                 self.selectKey("UP")
106                 self.selectKey("DOWN")
107                 
108         def changed(self):
109                 self.run()
110                 self.updateList()
111                 self.setText()
112                 
113         def setText(self):
114                 self["text"].setText(_("Please use the UP and DOWN keys to select your language. Afterwards press the OK button."))
115