ignore mplex buffer underruns since they apperently only occur at the very end of...
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / ProjectSettings.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 resolveFilename, SCOPE_PLUGINS, SCOPE_FONTS
13 from Components.config import config, getConfigListEntry
14 from Components.ConfigList import ConfigListScreen
15
16 class WaitBox(MessageBox):
17         def __init__(self, session, callback):
18                 MessageBox.__init__(self, session, text=_("please wait, loading picture..."), type = MessageBox.TYPE_INFO)
19                 self.skinName = "MessageBox"
20                 self.CB = callback
21                 self.onShown.append(self.runCB)
22
23         def ok(self):
24                 pass
25
26         def runCB(self):
27                 from enigma import eTimer
28                 self.delayTimer = eTimer()
29                 self.delayTimer.callback.append(self.CB)
30                 self.delayTimer.start(10,1)
31
32 class FileBrowser(Screen, HelpableScreen):
33         skin = """
34         <screen name="FileBrowser" position="100,100" size="520,376" title="DVD File Browser" >
35                 <widget name="filelist" position="0,0" size="520,376" scrollbarMode="showOnDemand" />
36         </screen>"""
37         def __init__(self, session, scope, settings):
38                 Screen.__init__(self, session)
39                 HelpableScreen.__init__(self)
40                 self.scope = scope
41                 pattern = ""
42                 currDir = "/"
43                 if self.scope == "project":
44                         currDir = self.getDir()
45                         pattern = "(?i)^.*\.(ddvdp\.xml)"               
46                 if self.scope == "menubg":
47                         currDir = self.getDir(settings.menubg)
48                         pattern = "(?i)^.*\.(jpeg|jpg|jpe|png|bmp)"
49                 elif self.scope == "menuaudio":
50                         currDir = self.getDir(settings.menuaudio)
51                         pattern = "(?i)^.*\.(mp2|m2a|ac3)"
52                 elif self.scope == "vmgm":
53                         currDir = self.getDir(settings.vmgm)
54                         pattern = "(?i)^.*\.(mpg|mpeg)"
55                 elif self.scope == "font_face":
56                         currDir = self.getDir(settings.font_face, resolveFilename(SCOPE_FONTS))
57                         pattern = "(?i)^.*\.(ttf)"
58
59                 self.filelist = FileList(currDir, matchingPattern=pattern)
60                 self["filelist"] = self.filelist
61
62                 self["FilelistActions"] = ActionMap(["OkCancelActions"],
63                         {
64                                 "ok": self.ok,
65                                 "cancel": self.exit
66                         })
67
68         def getDir(self, key=None, defaultDir=None):
69                 if key:
70                         settingDir = key.getValue()
71                         if len(settingDir) > 1:
72                                 return (settingDir.rstrip("/").rsplit("/",1))[0]
73                 return defaultDir or (resolveFilename(SCOPE_PLUGINS)+"Extensions/DVDBurn/")
74
75         def ok(self):
76                 if self.filelist.canDescent():
77                         self.filelist.descent()
78                 else:
79                         ret = self["filelist"].getCurrentDirectory() + '/' + self["filelist"].getFilename()
80                         self.close(ret,self.scope)
81
82         def exit(self):
83                 self.close(None,False)
84
85 class ProjectSettings(Screen,ConfigListScreen):
86         skin = """
87                 <screen position="90,83" size="560,445" title="Collection settings" >
88                     <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
89                     <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
90                     <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
91                     <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
92                     <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" />
93                     <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" />
94                     <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
95                     <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" />
96                     <widget name="config" position="10,50" size="540,276" scrollbarMode="showOnDemand" />
97                     <widget source="info" render="Label" position="20,350" size="520,90" font="Regular;16" />
98                 </screen>"""
99
100         def __init__(self, session, project = None):
101                 Screen.__init__(self, session)
102                 self.project = project
103                 
104                 self["key_red"] = StaticText(_("Cancel"))
105                 self["key_green"] = StaticText(_("OK"))
106                 self["key_yellow"] = StaticText(_("Load"))
107                 self["key_blue"] = StaticText(_("Save"))
108                 
109                 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")
110                 self["info"] = StaticText(infotext)
111
112                 self.settings = project.settings
113                 self.list = []
114                 self.list.append(getConfigListEntry(_("Collection name"), self.settings.name))
115                 self.list.append(getConfigListEntry(_("Authoring mode"), self.settings.authormode))
116                 self.list.append(getConfigListEntry(_("Menu")+' '+_("background image"), self.settings.menubg))
117                 self.list.append(getConfigListEntry(_("Menu")+' '+_("Title"), self.settings.titleformat))
118                 self.list.append(getConfigListEntry(_("Menu")+' '+_("Subtitles"), self.settings.subtitleformat))
119                 self.list.append(getConfigListEntry(_("Menu")+' '+_("headline")+' '+_("color"), self.settings.color_headline))
120                 self.list.append(getConfigListEntry(_("Menu")+' '+_("text")+' '+_("color"), self.settings.color_button))
121                 self.list.append(getConfigListEntry(_("Menu")+' '+_("highlighted button")+' '+_("color"), self.settings.color_highlight))
122                 self.list.append(getConfigListEntry(_("Menu")+' '+_("font face"), self.settings.font_face))
123                 self.list.append(getConfigListEntry(_("Font size")+' ('+_("headline")+', '+_("Title")+', '+_("Subtitles")+')', self.settings.font_size))
124                 self.list.append(getConfigListEntry(_("Menu")+' '+_("spaces (top, between rows, left)"), self.settings.space))
125                 self.list.append(getConfigListEntry(_("Menu")+' '+_("Audio"), self.settings.menuaudio))
126                 self.list.append(getConfigListEntry(_("VMGM (intro trailer)"), self.settings.vmgm))
127                 self.list.append(getConfigListEntry(_("Auto chapter split every ? minutes (0=never)"), self.settings.autochapter))
128                 ConfigListScreen.__init__(self, self.list)
129                 
130                 self.keydict = {}
131                 for key, val in self.settings.dict().iteritems():
132                         self.keydict[val] = key
133                 
134                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
135                 {
136                     "green": self.exit,
137                     "red": self.cancel,
138                     "blue": self.saveProject,
139                     "yellow": self.loadProject,
140                     "cancel": self.cancel,
141                     "ok": self.ok,
142                 }, -2)
143         
144         def exit(self):
145                 self.applySettings()
146                 self.close(True)
147
148         def applySettings(self):
149                 for x in self["config"].list:
150                         x[1].save()
151                 
152         def ok(self):
153                 key = self.keydict[self["config"].getCurrent()[1]]
154                 if key in self.project.filekeys:
155                         self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, key, self.settings)
156
157         def cancel(self):
158                 self.close(False)
159
160         def loadProject(self):
161                 self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, "project", self.settings)
162
163         def saveProject(self):
164                 self.applySettings()
165                 ret = self.project.saveProject(resolveFilename(SCOPE_PLAYLIST))
166                 if ret.startswith:
167                         text = _("Save")+' '+_('OK')+':\n'+ret
168                         self.session.open(MessageBox,text,type = MessageBox.TYPE_INFO)
169                 else:
170                         text = _("Save")+' '+_('Error')
171                         self.session.open(MessageBox,text,type = MessageBox.TYPE_ERROR)
172
173         def FileBrowserClosed(self, path, scope):
174                 if scope in self.project.filekeys:
175                         self.settings.dict()[scope].setValue(path)
176                 elif scope == "project":
177                         if not self.project.loadProject(path):
178                                 self.session.open(MessageBox,self.project.error,MessageBox.TYPE_ERROR)