1 from Tools.Directories import fileExists
2 from Components.config import config, ConfigSubsection, ConfigInteger, ConfigText, ConfigSelection, getConfigListEntry, ConfigSequence, ConfigSubList
6 class ConfigColor(ConfigSequence):
7 def __init__(self, default = [128,128,128]):
8 ConfigSequence.__init__(self, seperator = "#", limits = [(0,255),(0,255),(0,255)], default = default)
10 class ConfigFilename(ConfigText):
12 ConfigText.__init__(self, default = "", fixed_size = True, visible_width = False)
14 def getMulti(self, selected):
16 return ("mtext"[1-selected:], "", 0)
17 cut_len = min(len(self.text),40)
18 filename = (self.text.rstrip("/").rsplit("/",1))[1].encode("utf-8")[:cut_len] + " "
20 mark = range(0, len(filename))
23 return ("mtext"[1-selected:], filename, mark)
31 self.settings = ConfigSubsection()
32 self.settings.name = ConfigText(fixed_size = False, visible_width = 40)
33 self.settings.authormode = ConfigSelection(choices = [("menu_linked", _("Linked titles with a DVD menu")), ("just_linked", _("Direct playback of linked titles without menu")), ("menu_seperate", _("Seperate titles with a main menu")), ("data_ts", _("Dreambox format data DVD (HDTV compatible)"))])
34 self.settings.titlesetmode = ConfigSelection(choices = [("single", _("Simple titleset (compatibility for legacy players)")), ("multi", _("Complex (allows mixing audio tracks and aspects)"))], default="multi")
35 self.settings.output = ConfigSelection(choices = [("iso", _("Create DVD-ISO")), ("dvd", _("Burn DVD"))])
36 self.settings.isopath = ConfigText(fixed_size = False, visible_width = 40)
37 self.settings.dataformat = ConfigSelection(choices = [("iso9660_1", ("ISO9660 Level 1")), ("iso9660_4", ("ISO9660 version 2")), ("udf", ("UDF"))])
38 self.settings.menutemplate = ConfigFilename()
39 self.settings.vmgm = ConfigFilename()
40 self.filekeys = ["vmgm", "isopath", "menutemplate"]
41 self.menutemplate = MenuTemplate()
45 def addService(self, service):
46 title = DVDTitle.DVDTitle(self)
47 title.addService(service)
48 self.titles.append(title)
51 def saveProject(self, path):
52 from Tools.XMLTools import stringToXML
54 list.append('<?xml version="1.0" encoding="utf-8" ?>\n')
55 list.append('<DreamDVDBurnerProject>\n')
56 list.append('\t<settings ')
57 for key, val in self.settings.dict().iteritems():
58 list.append( key + '="' + str(val.getValue()) + '" ' )
60 list.append('\t<titles>\n')
61 for title in self.titles:
62 list.append('\t\t<title>\n')
63 list.append('\t\t\t<path>')
64 list.append(stringToXML(title.source.getPath()))
65 list.append('</path>\n')
66 list.append('\t\t\t<properties ')
68 for key, val in title.properties.dict().iteritems():
69 if type(val) is ConfigSubList:
70 audiotracks.append('\t\t\t<audiotracks>\n')
71 for audiotrack in val:
72 audiotracks.append('\t\t\t\t<audiotrack ')
73 for subkey, subval in audiotrack.dict().iteritems():
74 audiotracks.append( subkey + '="' + str(subval.getValue()) + '" ' )
75 audiotracks.append(' />\n')
76 audiotracks.append('\t\t\t</audiotracks>\n')
78 list.append( key + '="' + str(val.getValue()) + '" ' )
80 for line in audiotracks:
82 list.append('\t\t</title>\n')
83 list.append('\t</titles>\n')
84 list.append('</DreamDVDBurnerProject>\n')
86 name = self.settings.name.getValue()
88 filename = path + name + ".ddvdp.xml"
89 while fileExists(filename):
91 filename = path + name + str(i).zfill(3) + ".ddvdp.xml"
93 file = open(filename, "w")
101 def load(self, filename):
102 ret = self.loadProject(filename)
104 ret = self.menutemplate.loadTemplate(self.settings.menutemplate.getValue())
105 self.error += self.menutemplate.error
108 def loadProject(self, filename):
110 if not fileExists(filename):
111 self.error = "xml file not found!"
112 #raise AttributeError
113 file = open(filename, "r")
114 data = file.read().decode("utf-8").replace('&',"&").encode("ascii",'xmlcharrefreplace')
116 projectfiledom = xml.dom.minidom.parseString(data)
117 for node in projectfiledom.childNodes[0].childNodes:
119 if node.nodeType == xml.dom.minidom.Element.nodeType:
120 if node.tagName == 'settings':
121 self.xmlAttributesToConfig(node, self.settings)
122 elif node.tagName == 'titles':
123 self.xmlGetTitleNodeRecursive(node)
125 for key in self.filekeys:
126 val = self.settings.dict()[key].getValue()
127 if not fileExists(val):
128 self.error += "\n%s '%s' not found" % (key, val)
129 #except AttributeError:
130 #print "loadProject AttributeError", self.error
131 #self.error += (" in project '%s'") % (filename)
135 def xmlAttributesToConfig(self, node, config):
138 #if node.attributes.length < len(config.dict())-1:
139 #self.error = "project attributes missing"
140 #raise AttributeError
141 while i < node.attributes.length:
142 item = node.attributes.item(i)
143 key = item.name.encode("utf-8")
145 val = eval(item.nodeValue)
146 except (NameError, SyntaxError):
147 val = item.nodeValue.encode("utf-8")
149 print "config[%s].setValue(%s)" % (key, val)
150 config.dict()[key].setValue(val)
152 self.error = "unknown attribute '%s'" % (key)
153 print "KeyError", self.error
156 except AttributeError:
157 self.error += (" XML attribute error '%s'") % node.toxml()
160 def xmlGetTitleNodeRecursive(self, node, title_idx = -1):
161 print "[xmlGetTitleNodeRecursive]", title_idx, node
162 print node.childNodes
163 for subnode in node.childNodes:
164 print "xmlGetTitleNodeRecursive subnode:", subnode
165 if subnode.nodeType == xml.dom.minidom.Element.nodeType:
166 if subnode.tagName == 'title':
168 title = DVDTitle.DVDTitle(self)
169 self.titles.append(title)
170 self.xmlGetTitleNodeRecursive(subnode, title_idx)
171 if subnode.tagName == 'path':
172 print "path:", subnode.firstChild.data
173 filename = subnode.firstChild.data
174 self.titles[title_idx].addFile(filename.encode("utf-8"))
175 if subnode.tagName == 'properties':
176 self.xmlAttributesToConfig(node, self.titles[title_idx].properties)
177 if subnode.tagName == 'audiotracks':
178 self.xmlGetTitleNodeRecursive(subnode, title_idx)
179 if subnode.tagName == 'audiotrack':
180 print "audiotrack...", subnode.toxml()
184 for title in self.titles:
185 totalsize += title.estimatedDiskspace
188 size = property(getSize)
190 class MenuTemplate(DVDProject):
192 self.settings = ConfigSubsection()
193 self.settings.titleformat = ConfigText(fixed_size = False, visible_width = 40)
194 self.settings.subtitleformat = ConfigText(fixed_size = False, visible_width = 40)
195 self.settings.menubg = ConfigFilename()
196 self.settings.menuaudio = ConfigFilename()
197 self.settings.dimensions = ConfigSequence(seperator = ',', default = [576,720], limits = [(352,720),(480,576)])
198 self.settings.rows = ConfigInteger(default = 4, limits = (1, 10))
199 self.settings.cols = ConfigInteger(default = 1, limits = (1, 4))
200 self.settings.color_headline = ConfigColor()
201 self.settings.color_headline = ConfigColor()
202 self.settings.color_highlight = ConfigColor()
203 self.settings.color_button = ConfigColor()
204 self.settings.fontface_headline = ConfigFilename()
205 self.settings.fontface_title = ConfigFilename()
206 self.settings.fontface_subtitle = ConfigFilename()
207 self.settings.fontsize_headline = ConfigInteger(default = 46, limits = (0, 199))
208 self.settings.fontsize_title = ConfigInteger(default = 24, limits = (0, 199))
209 self.settings.fontsize_subtitle = ConfigInteger(default = 14, limits = (0, 199))
210 self.settings.margin_top = ConfigInteger(default = 120, limits = (0, 500))
211 self.settings.margin_bottom = ConfigInteger(default = 40, limits = (0, 500))
212 self.settings.margin_left = ConfigInteger(default = 56, limits = (0, 500))
213 self.settings.margin_right = ConfigInteger(default = 56, limits = (0, 500))
214 self.settings.space_rows = ConfigInteger(default = 32, limits = (0, 500))
215 self.settings.space_cols = ConfigInteger(default = 24, limits = (0, 500))
216 self.settings.prev_page_text = ConfigText(default = "<<<", fixed_size = False)
217 self.settings.next_page_text = ConfigText(default = ">>>", fixed_size = False)
218 self.settings.offset_headline = ConfigSequence(seperator = ',', default = [0,0], limits = [(-1,500),(-1,500)])
219 self.settings.offset_title = ConfigSequence(seperator = ',', default = [0,0], limits = [(-1,500),(-1,500)])
220 self.settings.offset_subtitle = ConfigSequence(seperator = ',', default = [20,0], limits = [(-1,500),(-1,500)])
221 self.settings.offset_thumb = ConfigSequence(seperator = ',', default = [40,0], limits = [(-1,500),(-1,500)])
222 self.settings.thumb_size = ConfigSequence(seperator = ',', default = [200,158], limits = [(0,576),(-1,720)])
223 self.settings.thumb_border = ConfigInteger(default = 2, limits = (0, 20))
224 self.filekeys = ["menubg", "menuaudio", "fontface_headline", "fontface_title", "fontface_subtitle"]
225 from TitleProperties import languageChoices
226 self.settings.menulang = ConfigSelection(choices = languageChoices.choices, default=languageChoices.choices[1][0])
229 def loadTemplate(self, filename):
230 ret = DVDProject.loadProject(self, filename)
231 DVDProject.error = self.error