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