d5ba6c16ad6dd53460157ec736c66f9d9d782a68
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / TitleProperties.py
1 from Screens.Screen import Screen
2 from Screens.ChoiceBox import ChoiceBox
3 from Screens.InputBox import InputBox
4 from Screens.MessageBox import MessageBox
5 from Screens.HelpMenu import HelpableScreen
6 from Components.ActionMap import HelpableActionMap, ActionMap
7 from Components.Sources.List import List
8 from Components.Sources.StaticText import StaticText
9 from Components.Sources.Progress import Progress
10 from Components.FileList import FileList
11 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT
12 from Tools.Directories import fileExists, resolveFilename, SCOPE_PLUGINS, SCOPE_FONTS, SCOPE_HDD
13 from Components.config import config, getConfigListEntry, ConfigInteger, ConfigSubsection, ConfigSelection
14 from Components.ConfigList import ConfigListScreen
15 import DVDTitle
16
17 class TitleProperties(Screen,ConfigListScreen):
18         skin = """
19                 <screen position="90,83" size="560,445" title="Properties of current title" >
20                     <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
21                     <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
22                     <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
23                     <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
24                     <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
25                     <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
26                     <widget name="config" position="10,50" size="540,300" scrollbarMode="showOnDemand" />
27                     <widget source="serviceinfo_headline" render="Label" position="20,360" size="520,20" font="Regular;20" />
28                     <widget source="serviceinfo" render="Label" position="20,382" size="520,66" font="Regular;16" />
29                 </screen>"""
30
31         def __init__(self, session, parent, project, title_idx):
32                 Screen.__init__(self, session)
33                 self.parent = parent
34                 self.project = project
35                 self.title_idx = title_idx
36
37                 self["key_red"] = StaticText(_("Cancel"))
38                 self["key_green"] = StaticText(_("OK"))
39                 self["key_blue"] = StaticText(_("Edit Title"))
40                 self["serviceinfo_headline"] = StaticText("DVB info:")
41                 self["serviceinfo"] = StaticText()
42
43                 self.properties = project.titles[title_idx].properties
44                 ConfigListScreen.__init__(self, [])
45                 self.properties.crop = DVDTitle.ConfigFixedText("crop")
46                 self.properties.autochapter.addNotifier(self.initConfigList)
47                 self.properties.aspect.addNotifier(self.initConfigList)
48                 for audiotrack in self.properties.audiotracks:
49                         audiotrack.active.addNotifier(self.initConfigList)
50                 
51                 self.initConfigList()
52
53                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
54                 {
55                     "green": self.exit,
56                     "red": self.cancel,
57                     "blue": self.editTitle,
58                     "cancel": self.cancel,
59                     "ok": self.ok,
60                 }, -2)
61
62         def initConfigList(self, element=None):
63                 try:
64                         self.properties.position = ConfigInteger(default = self.title_idx+1, limits = (1, len(self.project.titles)))
65                         title = self.project.titles[self.title_idx]
66                         self.list = []
67                         self.list.append(getConfigListEntry("DVD " + _("Track"), self.properties.position))
68                         self.list.append(getConfigListEntry("DVD " + _("Title"), self.properties.menutitle))
69                         self.list.append(getConfigListEntry("DVD " + _("Description"), self.properties.menusubtitle))
70                         for audiotrack in self.properties.audiotracks:
71                                 DVB_aud = audiotrack.DVB_lang.getValue() or audiotrack.pid.getValue()
72                                 self.list.append(getConfigListEntry(_("burn audio track (%s)") % DVB_aud, audiotrack.active))
73                                 if audiotrack.active.getValue():
74                                         self.list.append(getConfigListEntry(_("audio track (%s) format") % DVB_aud, audiotrack.format))
75                                         self.list.append(getConfigListEntry(_("audio track (%s) language") % DVB_aud, audiotrack.language))
76                                         
77                         self.list.append(getConfigListEntry("DVD " + _("Aspect Ratio"), self.properties.aspect))
78                         if self.properties.aspect.getValue() == "16:9":
79                                 self.list.append(getConfigListEntry("DVD " + "widescreen", self.properties.widescreen))
80                         else:
81                                 self.list.append(getConfigListEntry("DVD " + "widescreen", self.properties.crop))
82                         
83                         infotext = _("Available format variables") + ":\n$i=" + _("Track") + ", $t=" + _("Title") + ", $d=" + _("Description") + ", $l=" + _("length") + ", $c=" + _("chapters") + ",\n" + _("Record") + " $T=" + _("Begin time") + ", $Y=" + _("year") + ", $M=" + _("month") + ", $D=" + _("day") + ",\n$A=" + _("audio tracks") + ", $C=" + _("Channel") + ", $f=" + _("filename")
84                         self["info"] = StaticText(infotext)
85                         
86                         if len(title.chaptermarks) == 0:
87                                 self.list.append(getConfigListEntry(_("Auto chapter split every ? minutes (0=never)"), self.properties.autochapter))
88                         infotext = _("Title") + ': ' + title.DVBname + "\n" + _("Description") + ': ' + title.DVBdescr + "\n" + _("Channel") + ': ' + title.DVBchannel
89                         chaptermarks = title.getChapterMarks(template="$h:$m:$s")
90                         chapters_count = len(chaptermarks)
91                         if chapters_count >= 1:
92                                 infotext += ', ' + str(chapters_count+1) + ' ' + _("chapters") + ' ('
93                                 infotext += ' / '.join(chaptermarks) + ')'
94                         self["serviceinfo"].setText(infotext)
95                         self["config"].setList(self.list)
96                 except AttributeError:
97                         pass
98
99         def editTitle(self):
100                 self.parent.editTitle()
101                 self.initConfigList()
102
103         def changedConfigList(self):
104                 self.initConfigList()
105
106         def exit(self):
107                 self.applySettings()
108                 self.close()
109
110         def applySettings(self):
111                 for x in self["config"].list:
112                         x[1].save()
113                 current_pos = self.title_idx+1
114                 new_pos = self.properties.position.getValue()
115                 if new_pos != current_pos:
116                         print "title got repositioned from ", current_pos, "to", new_pos
117                         swaptitle = self.project.titles.pop(current_pos-1)
118                         self.project.titles.insert(new_pos-1, swaptitle)
119
120         def ok(self):
121                 #key = self.keydict[self["config"].getCurrent()[1]]
122                 #if key in self.project.filekeys:
123                         #self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, key, self.settings)
124                 pass
125
126         def cancel(self):
127                 self.close()
128
129 from Tools.ISO639 import LanguageCodes
130 class LanguageChoices():
131         def __init__(self):
132                 from Components.Language import language as syslanguage
133                 syslang = syslanguage.getLanguage()[:2]
134                 self.langdict = { }
135                 self.choices = []
136                 for key, val in LanguageCodes.iteritems():
137                         if len(key) == 2:
138                                 self.langdict[key] = val[0]
139                 for key, val in self.langdict.iteritems():
140                         if key not in [syslang, 'en']:
141                                 self.langdict[key] = val
142                                 self.choices.append((key, val))
143                 self.choices.sort()
144                 self.choices.insert(0,("nolang", ("unspecified")))
145                 self.choices.insert(1,(syslang, self.langdict[syslang]))
146                 self.choices.insert(2,("en", self.langdict["en"]))
147
148         def getLanguage(self, DVB_lang):
149                 DVB_lang = DVB_lang.lower()
150                 stripwords = ["stereo", "audio", "description", "2ch", "dolby digital"]
151                 for word in stripwords:
152                         DVB_lang = DVB_lang.replace(word,"").strip()
153                 for key, val in LanguageCodes.iteritems():
154                         if DVB_lang.find(key.lower()) == 0:
155                                 if len(key) == 2:
156                                         return key
157                                 else:
158                                         DVB_lang = (LanguageCodes[key])[0]
159                         elif DVB_lang.find(val[0].lower()) > -1:
160                                 if len(key) == 2:
161                                         return key
162                                 else:
163                                         DVB_lang = (LanguageCodes[key])[0]
164                 for key, val in self.langdict.iteritems():
165                         if val == DVB_lang:
166                                 return key
167                 return "nolang"
168
169 languageChoices = LanguageChoices()