stop writing progress after profile_final
[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
8 from Tools.Directories import *
9
10 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT
11 from Tools.LoadPixmap import LoadPixmap
12
13 def LanguageEntryComponent(file, name, index):
14         res = [ index ]
15         res.append((eListboxPythonMultiContent.TYPE_TEXT, 80, 10, 200, 50, 0, RT_HALIGN_LEFT ,name))
16         png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "countries/" + file + ".png"))
17         if png == None:
18                 png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "countries/missing.png"))
19         res.append((eListboxPythonMultiContent.TYPE_PIXMAP, 10, 5, 60, 40, png))
20         
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, item_height=50, fonts = [gFont("Regular", 20)])
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][3].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()