CreateMenu is now a task of its own
[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 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
43                 self.filelist = FileList(currDir, matchingPattern=pattern)
44                 self["filelist"] = self.filelist
45
46                 self["FilelistActions"] = ActionMap(["OkCancelActions"],
47                         {
48                                 "ok": self.ok,
49                                 "cancel": self.exit
50                         })
51
52         def getDir(self, key=None, defaultDir=None):
53                 if key:
54                         settingDir = key.getValue()
55                         if len(settingDir) > 1:
56                                 return (settingDir.rstrip("/").rsplit("/",1))[0]
57                 return defaultDir or (resolveFilename(SCOPE_PLUGINS)+"Extensions/DVDBurn/")
58
59         def ok(self):
60                 if self.filelist.canDescent():
61                         self.filelist.descent()
62                 else:
63                         ret = self["filelist"].getCurrentDirectory() + '/' + self["filelist"].getFilename()
64                         self.close(ret,self.scope)
65
66         def exit(self):
67                 self.close(None,False)
68
69 class ProjectSettings(Screen,ConfigListScreen):
70         skin = """
71                 <screen position="90,83" size="560,445" title="Collection settings" >
72                     <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
73                     <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
74                     <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
75                     <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
76                     <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" />
77                     <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" />
78                     <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" />
79                     <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" />
80                     <widget name="config" position="10,50" size="540,276" scrollbarMode="showOnDemand" />
81                     <widget source="info" render="Label" position="20,350" size="520,90" font="Regular;16" />
82                 </screen>"""
83
84         def __init__(self, session, project = None):
85                 Screen.__init__(self, session)
86                 self.project = project
87                 
88                 self["key_red"] = StaticText(_("Cancel"))
89                 self["key_green"] = StaticText(_("OK"))
90                 self["key_yellow"] = StaticText(_("Load"))
91                 self["key_blue"] = StaticText(_("Save"))
92                 
93                 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")
94                 self["info"] = StaticText(infotext)
95
96                 self.settings = project.settings
97                 ConfigListScreen.__init__(self, [])
98                 self.initConfigList(self.settings.authormode.getValue())
99                         
100                 self.keydict = {}
101                 for key, val in self.settings.dict().iteritems():
102                         self.keydict[val] = key
103                 
104                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
105                 {
106                     "green": self.exit,
107                     "red": self.cancel,
108                     "blue": self.saveProject,
109                     "yellow": self.loadProject,
110                     "cancel": self.cancel,
111                     "ok": self.ok,
112                 }, -2)
113
114         def changedConfigList(self):
115                 if self.keydict[self["config"].getCurrent()[1]] == "authormode":
116                         self.initConfigList(self.settings.authormode.getValue())
117                 
118         def initConfigList(self, authormode=""):
119                 print "initConfigList(%s)" % authormode
120                 self.list = []
121                 self.list.append(getConfigListEntry(_("Collection name"), self.settings.name))
122                 self.list.append(getConfigListEntry(_("Authoring mode"), self.settings.authormode))
123                 if authormode.startswith("menu"):
124                         self.list.append(getConfigListEntry(_("Menu")+' '+_("background image"), self.settings.menubg))
125                         self.list.append(getConfigListEntry(_("Menu")+' '+_("Title"), self.settings.titleformat))
126                         self.list.append(getConfigListEntry(_("Menu")+' '+_("Subtitles"), self.settings.subtitleformat))
127                         self.list.append(getConfigListEntry(_("Menu")+' '+_("headline")+' '+_("color"), self.settings.color_headline))
128                         self.list.append(getConfigListEntry(_("Menu")+' '+_("text")+' '+_("color"), self.settings.color_button))
129                         self.list.append(getConfigListEntry(_("Menu")+' '+_("highlighted button")+' '+_("color"), self.settings.color_highlight))
130                         self.list.append(getConfigListEntry(_("Menu")+' '+_("font face"), self.settings.font_face))
131                         self.list.append(getConfigListEntry(_("Font size")+' ('+_("headline")+', '+_("Title")+', '+_("Subtitles")+')', self.settings.font_size))
132                         self.list.append(getConfigListEntry(_("Menu")+' '+_("spaces (top, between rows, left)"), self.settings.space))
133                         self.list.append(getConfigListEntry(_("Menu")+' '+_("Audio"), self.settings.menuaudio))
134                 if authormode != "data_ts":
135                         self.list.append(getConfigListEntry(_("VMGM (intro trailer)"), self.settings.vmgm))
136                         self.list.append(getConfigListEntry(_("Auto chapter split every ? minutes (0=never)"), self.settings.autochapter))
137                 self["config"].setList(self.list)
138
139         def keyLeft(self):
140                 ConfigListScreen.keyLeft(self)
141                 if self.keydict[self["config"].getCurrent()[1]] == "authormode":
142                         self.initConfigList(self.settings.authormode.getValue())
143
144         def keyRight(self):
145                 ConfigListScreen.keyRight(self)
146                 if self.keydict[self["config"].getCurrent()[1]] == "authormode":
147                         self.initConfigList(self.settings.authormode.getValue())
148
149         def exit(self):
150                 self.applySettings()
151                 self.close(True)
152
153         def applySettings(self):
154                 for x in self["config"].list:
155                         x[1].save()
156                 
157         def ok(self):
158                 key = self.keydict[self["config"].getCurrent()[1]]
159                 if key in self.project.filekeys:
160                         self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, key, self.settings)
161
162         def cancel(self):
163                 self.close(False)
164
165         def loadProject(self):
166                 self.session.openWithCallback(self.FileBrowserClosed, FileBrowser, "project", self.settings)
167
168         def saveProject(self):
169                 self.applySettings()
170                 ret = self.project.saveProject(resolveFilename(SCOPE_PLUGINS)+"Extensions/DVDBurn/")
171                 if ret.startswith:
172                         text = _("Save")+' '+_('OK')+':\n'+ret
173                         self.session.open(MessageBox,text,type = MessageBox.TYPE_INFO)
174                 else:
175                         text = _("Save")+' '+_('Error')
176                         self.session.open(MessageBox,text,type = MessageBox.TYPE_ERROR)
177
178         def FileBrowserClosed(self, path, scope):
179                 if scope in self.project.filekeys:
180                         self.settings.dict()[scope].setValue(path)
181                 elif scope == "project":
182                         if not self.project.loadProject(path):
183                                 self.session.open(MessageBox,self.project.error,MessageBox.TYPE_ERROR)