Merge branch 'bug_570_playback_skip_fixes_and_cleanup_ml_aholst'
[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 Components.Pixmap import Pixmap
12 from enigma import ePicLoad
13 from Tools.Directories import fileExists, resolveFilename, SCOPE_PLUGINS, SCOPE_FONTS, SCOPE_HDD
14 from Components.config import config, getConfigListEntry, ConfigInteger, ConfigSubsection, ConfigSelection
15 from Components.ConfigList import ConfigListScreen
16 from Components.AVSwitch import AVSwitch
17 import DVDTitle
18
19 class TitleProperties(Screen,ConfigListScreen):
20         skin = """
21                 <screen name="TitleProperties" position="center,center" size="560,445" title="Properties of current title" >
22                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
23                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
24                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
25                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
26                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
27                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
28                         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
29                         <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;19" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
30                         <widget source="serviceinfo" render="Label" position="10,46" size="350,144" font="Regular;18" />
31                         <widget name="thumbnail" position="370,46" size="180,144" alphatest="on" />
32                         <widget name="config" position="10,206" size="540,228" scrollbarMode="showOnDemand" />
33                 </screen>"""
34
35         def __init__(self, session, parent, project, title_idx):
36                 Screen.__init__(self, session)
37                 self.parent = parent
38                 self.project = project
39                 self.title_idx = title_idx
40
41                 self["key_red"] = StaticText(_("Cancel"))
42                 self["key_green"] = StaticText(_("OK"))
43                 self["key_yellow"] = StaticText(_("Edit Title"))
44                 self["key_blue"] = StaticText()
45                 self["serviceinfo"] = StaticText()
46
47                 self["thumbnail"] = Pixmap()
48                 self.picload = ePicLoad()
49                 self.picload.PictureData.get().append(self.paintThumbPixmapCB)
50
51                 self.properties = project.titles[title_idx].properties
52                 ConfigListScreen.__init__(self, [])
53                 self.properties.crop = DVDTitle.ConfigFixedText("crop")
54                 self.properties.autochapter.addNotifier(self.initConfigList)
55                 self.properties.aspect.addNotifier(self.initConfigList)
56                 for audiotrack in self.properties.audiotracks:
57                         audiotrack.active.addNotifier(self.initConfigList)
58
59                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
60                 {
61                     "green": self.exit,
62                     "red": self.cancel,
63                     "yellow": self.editTitle,
64                     "cancel": self.cancel,
65                     "ok": self.ok,
66                 }, -2)
67                 
68                 self.onShown.append(self.update)
69                 self.onLayoutFinish.append(self.layoutFinished)
70
71         def layoutFinished(self):
72                 self.setTitle(_("Properties of current title"))
73
74         def initConfigList(self, element=None):
75                 try:
76                         self.properties.position = ConfigInteger(default = self.title_idx+1, limits = (1, len(self.project.titles)))
77                         title = self.project.titles[self.title_idx]
78                         self.list = []
79                         self.list.append(getConfigListEntry("DVD " + _("Track"), self.properties.position))
80                         self.list.append(getConfigListEntry("DVD " + _("Title"), self.properties.menutitle))
81                         self.list.append(getConfigListEntry("DVD " + _("Description"), self.properties.menusubtitle))
82                         if config.usage.setup_level.index >= 2: # expert+
83                                 for audiotrack in self.properties.audiotracks:
84                                         DVB_aud = audiotrack.DVB_lang.getValue() or audiotrack.pid.getValue()
85                                         self.list.append(getConfigListEntry(_("burn audio track (%s)") % DVB_aud, audiotrack.active))
86                                         if audiotrack.active.getValue():
87                                                 self.list.append(getConfigListEntry(_("audio track (%s) format") % DVB_aud, audiotrack.format))
88                                                 self.list.append(getConfigListEntry(_("audio track (%s) language") % DVB_aud, audiotrack.language))
89                                                 
90                                 self.list.append(getConfigListEntry("DVD " + _("Aspect Ratio"), self.properties.aspect))
91                                 if self.properties.aspect.getValue() == "16:9":
92                                         self.list.append(getConfigListEntry("DVD " + "widescreen", self.properties.widescreen))
93                                 else:
94                                         self.list.append(getConfigListEntry("DVD " + "widescreen", self.properties.crop))
95                         if len(title.chaptermarks) == 0:
96                                 self.list.append(getConfigListEntry(_("Auto chapter split every ? minutes (0=never)"), self.properties.autochapter))
97                         infotext = "DVB " + _("Title") + ': ' + title.DVBname + "\n" + _("Description") + ': ' + title.DVBdescr + "\n" + _("Channel") + ': ' + title.DVBchannel + '\n' + _("Begin time") + title.formatDVDmenuText(": $D.$M.$Y, $T\n", self.title_idx+1)
98                         chaptermarks = title.getChapterMarks(template="$h:$m:$s")
99                         chapters_count = len(chaptermarks)
100                         if chapters_count >= 1:
101                                 infotext += str(chapters_count+1) + ' ' + _("chapters") + ': '
102                                 infotext += ' / '.join(chaptermarks)
103                         self["serviceinfo"].setText(infotext)
104                         self["config"].setList(self.list)
105                 except AttributeError:
106                         pass
107
108         def editTitle(self):
109                 self.parent.editTitle()
110
111         def update(self):
112                 print "[onShown]"
113                 self.initConfigList()
114                 self.loadThumb()
115
116         def loadThumb(self):
117                 thumbfile = self.project.titles[self.title_idx].inputfile.rsplit('.',1)[0] + ".png"
118                 sc = AVSwitch().getFramebufferScale()
119                 self.picload.setPara((self["thumbnail"].instance.size().width(), self["thumbnail"].instance.size().height(), sc[0], sc[1], False, 1, "#00000000"))
120                 self.picload.startDecode(thumbfile)
121
122         def paintThumbPixmapCB(self, picInfo=None):
123                 ptr = self.picload.getData()
124                 if ptr != None:
125                         self["thumbnail"].instance.setPixmap(ptr.__deref__())
126
127         def changedConfigList(self):
128                 self.initConfigList()
129
130         def exit(self):
131                 self.applySettings()
132                 self.close()
133
134         def applySettings(self):
135                 for x in self["config"].list:
136                         x[1].save()
137                 current_pos = self.title_idx+1
138                 new_pos = self.properties.position.getValue()
139                 if new_pos != current_pos:
140                         print "title got repositioned from ", current_pos, "to", new_pos
141                         swaptitle = self.project.titles.pop(current_pos-1)
142                         self.project.titles.insert(new_pos-1, swaptitle)
143
144         def ok(self):
145                 #key = self.keydict[self["config"].getCurrent()[1]]
146                 #if key in self.project.filekeys:
147                         #self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, key, self.settings)
148                 pass
149
150         def cancel(self):
151                 self.close()
152
153 from Tools.ISO639 import LanguageCodes
154 class LanguageChoices():
155         def __init__(self):
156                 from Components.Language import language as syslanguage
157                 syslang = syslanguage.getLanguage()[:2]
158                 self.langdict = { }
159                 self.choices = []
160                 for key, val in LanguageCodes.iteritems():
161                         if len(key) == 2:
162                                 self.langdict[key] = val[0]
163                 for key, val in self.langdict.iteritems():
164                         if key not in (syslang, 'en'):
165                                 self.langdict[key] = val
166                                 self.choices.append((key, val))
167                 self.choices.sort()
168                 self.choices.insert(0,("nolang", ("unspecified")))
169                 self.choices.insert(1,(syslang, self.langdict[syslang]))
170                 if syslang != "en":
171                         self.choices.insert(2,("en", self.langdict["en"]))
172
173         def getLanguage(self, DVB_lang):
174                 DVB_lang = DVB_lang.lower()
175                 for word in ("stereo", "audio", "description", "2ch", "dolby digital"):
176                         DVB_lang = DVB_lang.replace(word,"").strip()
177                 for key, val in LanguageCodes.iteritems():
178                         if DVB_lang.find(key.lower()) == 0:
179                                 if len(key) == 2:
180                                         return key
181                                 else:
182                                         DVB_lang = (LanguageCodes[key])[0]
183                         elif DVB_lang.find(val[0].lower()) > -1:
184                                 if len(key) == 2:
185                                         return key
186                                 else:
187                                         DVB_lang = (LanguageCodes[key])[0]
188                 for key, val in self.langdict.iteritems():
189                         if val == DVB_lang:
190                                 return key
191                 return "nolang"
192
193 languageChoices = LanguageChoices()