use already translated string
[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 fileExists, resolveFilename, SCOPE_PLUGINS, SCOPE_FONTS, SCOPE_HDD
13 from Components.config import config, getConfigListEntry
14 from Components.ConfigList import ConfigListScreen
15
16 class FileBrowser(Screen, HelpableScreen):
17         skin = """
18         <screen name="FileBrowser" position="100,100" size="520,376" title="DVD File Browser" >
19                 <widget name="filelist" position="0,0" size="520,376" scrollbarMode="showOnDemand" />
20         </screen>"""
21         def __init__(self, session, scope, settings):
22                 Screen.__init__(self, session)
23                 HelpableScreen.__init__(self)
24                 self.scope = scope
25                 pattern = ""
26                 currDir = "/"
27                 if self.scope == "project":
28                         currDir = self.getDir()
29                         pattern = "(?i)^.*\.(ddvdp\.xml)"               
30                 if self.scope == "menubg":
31                         currDir = self.getDir(settings.menubg)
32                         pattern = "(?i)^.*\.(jpeg|jpg|jpe|png|bmp)"
33                 elif self.scope == "menuaudio":
34                         currDir = self.getDir(settings.menuaudio)
35                         pattern = "(?i)^.*\.(mp2|m2a|ac3)"
36                 elif self.scope == "vmgm":
37                         currDir = self.getDir(settings.vmgm)
38                         pattern = "(?i)^.*\.(mpg|mpeg)"
39                 elif self.scope == "font_face":
40                         currDir = self.getDir(settings.font_face, resolveFilename(SCOPE_FONTS))
41                         pattern = "(?i)^.*\.(ttf)"
42                 elif self.scope == "isopath":
43                         currDir = settings.isopath.getValue()
44                 elif self.scope == "image":
45                         currDir = resolveFilename(SCOPE_HDD)
46                         pattern = "(?i)^.*\.(iso)"
47
48                 self.filelist = FileList(currDir, matchingPattern=pattern)
49                 self["filelist"] = self.filelist
50
51                 self["FilelistActions"] = ActionMap(["OkCancelActions"],
52                         {
53                                 "ok": self.ok,
54                                 "cancel": self.exit
55                         })
56
57         def getDir(self, key=None, defaultDir=None):
58                 if key:
59                         settingDir = key.getValue()
60                         if len(settingDir) > 1:
61                                 return (settingDir.rstrip("/").rsplit("/",1))[0]
62                 return defaultDir or (resolveFilename(SCOPE_PLUGINS)+"Extensions/DVDBurn/")
63
64         def ok(self):
65                 if self.filelist.canDescent():
66                         self.filelist.descent()
67                         if self.scope == "image":
68                                 path = self["filelist"].getCurrentDirectory() or ""
69                                 if fileExists(path+"VIDEO_TS"):
70                                         self.close(path,self.scope)
71                 else:
72                         ret = self["filelist"].getCurrentDirectory() + '/' + self["filelist"].getFilename()
73                         self.close(ret,self.scope)
74
75         def exit(self):
76                 if self.scope == "isopath":
77                         self.close(self["filelist"].getCurrentDirectory(),self.scope)
78                 self.close(None,False)
79
80 class ProjectSettings(Screen,ConfigListScreen):
81         skin = """
82                 <screen position="90,83" size="560,445" title="Collection settings" >
83                     <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
84                     <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
85                     <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
86                     <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
87                     <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" />
88                     <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" />
89                     <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" />
90                     <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" />
91                     <widget name="config" position="10,50" size="540,276" scrollbarMode="showOnDemand" />
92                     <widget source="info" render="Label" position="20,350" size="520,90" font="Regular;16" />
93                 </screen>"""
94
95         def __init__(self, session, project = None):
96                 Screen.__init__(self, session)
97                 self.project = project
98                 
99                 self["key_red"] = StaticText(_("Cancel"))
100                 self["key_green"] = StaticText(_("OK"))
101                 self["key_yellow"] = StaticText(_("Load"))
102                 self["key_blue"] = StaticText(_("Save"))
103                 
104                 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")
105                 self["info"] = StaticText(infotext)
106
107                 self.settings = project.settings
108                 ConfigListScreen.__init__(self, [])
109                 self.initConfigList()
110                         
111                 self.keydict = {}
112                 for key, val in self.settings.dict().iteritems():
113                         self.keydict[val] = key
114                 
115                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
116                 {
117                     "green": self.exit,
118                     "red": self.cancel,
119                     "blue": self.saveProject,
120                     "yellow": self.loadProject,
121                     "cancel": self.cancel,
122                     "ok": self.ok,
123                 }, -2)
124
125         def changedConfigList(self):
126                 key = self.keydict[self["config"].getCurrent()[1]]
127                 if key == "authormode" or key == "output":
128                         self.initConfigList()
129
130         def initConfigList(self):
131                 authormode = self.settings.authormode.getValue()
132                 output = self.settings.output.getValue()
133                 self.list = []
134                 self.list.append(getConfigListEntry(_("Collection name"), self.settings.name))
135                 self.list.append(getConfigListEntry(_("Authoring mode"), self.settings.authormode))
136                 self.list.append(getConfigListEntry(("Output"), self.settings.output))
137                 if output == "iso":
138                         self.list.append(getConfigListEntry(_("ISO path"), self.settings.isopath))
139                 if authormode.startswith("menu"):
140                         self.list.append(getConfigListEntry(_("Menu")+' '+_("background image"), self.settings.menubg))
141                         self.list.append(getConfigListEntry(_("Menu")+' '+_("Title"), self.settings.titleformat))
142                         self.list.append(getConfigListEntry(_("Menu")+' '+_("Subtitles"), self.settings.subtitleformat))
143                         self.list.append(getConfigListEntry(_("Menu")+' '+_("headline")+' '+_("color"), self.settings.color_headline))
144                         self.list.append(getConfigListEntry(_("Menu")+' '+_("text")+' '+_("color"), self.settings.color_button))
145                         self.list.append(getConfigListEntry(_("Menu")+' '+_("highlighted button")+' '+_("color"), self.settings.color_highlight))
146                         self.list.append(getConfigListEntry(_("Menu")+' '+_("font face"), self.settings.font_face))
147                         self.list.append(getConfigListEntry(_("Font size")+' ('+_("headline")+', '+_("Title")+', '+_("Subtitles")+')', self.settings.font_size))
148                         self.list.append(getConfigListEntry(_("Menu")+' '+_("spaces (top, between rows, left)"), self.settings.space))
149                         self.list.append(getConfigListEntry(_("Menu")+' '+_("Audio"), self.settings.menuaudio))
150                 if authormode != "data_ts":
151                         self.list.append(getConfigListEntry(_("Titleset mode"), self.settings.titlesetmode))
152                         if self.settings.titlesetmode.getValue() == "single" or authormode == "just_linked":
153                                 self.list.append(getConfigListEntry(_("VMGM (intro trailer)"), self.settings.vmgm))
154                 else:
155                         self.list.append(getConfigListEntry(("DVD data format"), self.settings.dataformat))
156                 
157                 self["config"].setList(self.list)
158
159         def keyLeft(self):
160                 ConfigListScreen.keyLeft(self)
161                 key = self.keydict[self["config"].getCurrent()[1]]
162                 if key == "authormode" or key == "output" or key=="titlesetmode":
163                         self.initConfigList()
164
165         def keyRight(self):
166                 ConfigListScreen.keyRight(self)
167                 key = self.keydict[self["config"].getCurrent()[1]]
168                 if key == "authormode" or key == "output" or key=="titlesetmode":
169                         self.initConfigList()
170
171         def exit(self):
172                 self.applySettings()
173                 self.close(True)
174
175         def applySettings(self):
176                 for x in self["config"].list:
177                         x[1].save()
178                 
179         def ok(self):
180                 key = self.keydict[self["config"].getCurrent()[1]]
181                 if key in self.project.filekeys:
182                         self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, key, self.settings)
183
184         def cancel(self):
185                 self.close(False)
186
187         def loadProject(self):
188                 self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, "project", self.settings)
189
190         def saveProject(self):
191                 self.applySettings()
192                 ret = self.project.saveProject(resolveFilename(SCOPE_PLUGINS)+"Extensions/DVDBurn/")
193                 if ret.startswith:
194                         text = _("Save")+' '+_('OK')+':\n'+ret
195                         self.session.open(MessageBox,text,type = MessageBox.TYPE_INFO)
196                 else:
197                         text = _("Save")+' '+_('Error')
198                         self.session.open(MessageBox,text,type = MessageBox.TYPE_ERROR)
199
200         def FileBrowserClosed(self, path, scope):
201                 if scope in self.project.filekeys:
202                         self.settings.dict()[scope].setValue(path)
203                 elif scope == "project":
204                         if not self.project.loadProject(path):
205                                 self.session.open(MessageBox,self.project.error,MessageBox.TYPE_ERROR)