1 from Tools.Directories import fileExists
2 from Components.config import config, ConfigSubsection, ConfigInteger, ConfigText, ConfigSelection, getConfigListEntry, ConfigSequence, ConfigSubList
4 class ConfigColor(ConfigSequence):
5 def __init__(self, default = [128,128,128]):
6 ConfigSequence.__init__(self, seperator = "#", limits = [(0,255),(0,255),(0,255)], default = default)
8 class ConfigFilename(ConfigText):
10 ConfigText.__init__(self, default = "", fixed_size = True, visible_width = False)
12 def getMulti(self, selected):
13 filename = (self.text.rstrip("/").rsplit("/",1))[1].encode("utf-8")[:40] + " "
15 mark = range(0, len(filename))
18 return ("mtext"[1-selected:], filename, mark)
26 self.settings = ConfigSubsection()
27 self.settings.name = ConfigText(fixed_size = False, visible_width = 40)
28 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)"))])
29 self.settings.titlesetmode = ConfigSelection(choices = [("single", _("Simple titleset (compatibility for legacy players)")), ("multi", _("Complex (allows mixing audio tracks and aspects)"))], default="multi")
30 self.settings.output = ConfigSelection(choices = [("iso", _("Create DVD-ISO")), ("dvd", _("Burn DVD"))])
31 self.settings.isopath = ConfigText(fixed_size = False, visible_width = 40)
32 self.settings.dataformat = ConfigSelection(choices = [("iso9660_1", ("ISO9660 Level 1")), ("iso9660_4", ("ISO9660 version 2")), ("udf", ("UDF"))])
33 self.settings.menutemplate = ConfigFilename()
34 self.settings.vmgm = ConfigFilename()
35 self.filekeys = ["vmgm", "isopath", "menutemplate"]
36 self.menutemplate = MenuTemplate()
38 def addService(self, service):
40 title = DVDTitle.DVDTitle()
41 title.addService(service)
42 self.titles.append(title)
45 def saveProject(self, path):
46 from Tools.XMLTools import stringToXML
48 list.append('<?xml version="1.0" encoding="utf-8" ?>\n')
49 list.append('<DreamDVDBurnerProject>\n')
50 list.append('\t<settings ')
51 for key, val in self.settings.dict().iteritems():
52 list.append( key + '="' + str(val.getValue()) + '" ' )
54 list.append('\t<titles>\n')
55 for title in self.titles:
56 list.append('\t\t<title>\n')
57 list.append('\t\t\t<path>')
58 list.append(stringToXML(title.source.getPath()))
59 list.append('</path>\n')
60 list.append('\t\t\t<properties ')
62 for key, val in title.properties.dict().iteritems():
63 if type(val) is ConfigSubList:
64 audiotracks.append('\t\t\t<audiotracks>\n')
65 for audiotrack in val:
66 audiotracks.append('\t\t\t\t<audiotrack ')
67 for subkey, subval in audiotrack.dict().iteritems():
68 audiotracks.append( subkey + '="' + str(subval.getValue()) + '" ' )
69 audiotracks.append(' />\n')
70 audiotracks.append('\t\t\t</audiotracks>\n')
72 list.append( key + '="' + str(val.getValue()) + '" ' )
74 for line in audiotracks:
76 list.append('\t\t</title>\n')
77 list.append('\t</titles>\n')
78 list.append('</DreamDVDBurnerProject>\n')
80 name = self.settings.name.getValue()
82 filename = path + name + ".ddvdp.xml"
83 while fileExists(filename):
85 filename = path + name + str(i).zfill(3) + ".ddvdp.xml"
87 file = open(filename, "w")
95 def load(self, filename):
96 ret = self.loadProject(filename)
98 ret = self.menutemplate.loadTemplate(self.settings.menutemplate.getValue())
99 self.error += self.menutemplate.error
102 def loadProject(self, filename):
103 import xml.dom.minidom
105 if not fileExists(filename):
106 self.error = "xml file not found!"
110 file = open(filename, "r")
111 data = file.read().decode("utf-8").replace('&',"&").encode("ascii",'xmlcharrefreplace')
113 projectfiledom = xml.dom.minidom.parseString(data)
114 for project in projectfiledom.childNodes[0].childNodes:
115 if project.nodeType == xml.dom.minidom.Element.nodeType:
116 if project.tagName == 'settings':
118 if project.attributes.length < len(self.settings.dict())-1:
119 self.error = "project attributes missing"
121 while i < project.attributes.length:
122 item = project.attributes.item(i)
123 key = item.name.encode("utf-8")
125 val = eval(item.nodeValue)
126 except (NameError, SyntaxError):
127 val = item.nodeValue.encode("utf-8")
129 self.settings.dict()[key].setValue(val)
131 self.error = "unknown attribute '%s'" % (key)
134 for key in self.filekeys:
135 val = self.settings.dict()[key].getValue()
136 if not fileExists(val):
137 self.error += "\n%s '%s' not found" % (key, val)
140 except AttributeError:
141 self.error += (" in project '%s'") % (filename)
147 for title in self.titles:
148 totalsize += title.estimatedDiskspace
151 size = property(getSize)
153 class MenuTemplate(DVDProject):
155 self.settings = ConfigSubsection()
156 self.settings.titleformat = ConfigText(fixed_size = False, visible_width = 40)
157 self.settings.subtitleformat = ConfigText(fixed_size = False, visible_width = 40)
158 self.settings.menubg = ConfigFilename()
159 self.settings.menuaudio = ConfigFilename()
160 self.settings.dimensions = ConfigSequence(seperator = ',', default = [576,720], limits = [(352,720),(480,576)])
161 self.settings.rows = ConfigInteger(default = 4, limits = (1, 10))
162 self.settings.cols = ConfigInteger(default = 1, limits = (1, 4))
163 self.settings.color_headline = ConfigColor()
164 self.settings.color_headline = ConfigColor()
165 self.settings.color_highlight = ConfigColor()
166 self.settings.color_button = ConfigColor()
167 self.settings.fontface_headline = ConfigFilename()
168 self.settings.fontface_title = ConfigFilename()
169 self.settings.fontface_subtitle = ConfigFilename()
170 self.settings.fontsize_headline = ConfigInteger(default = 46, limits = (0, 199))
171 self.settings.fontsize_title = ConfigInteger(default = 24, limits = (0, 199))
172 self.settings.fontsize_subtitle = ConfigInteger(default = 14, limits = (0, 199))
173 self.settings.margin_top = ConfigInteger(default = 120, limits = (0, 500))
174 self.settings.margin_bottom = ConfigInteger(default = 40, limits = (0, 500))
175 self.settings.margin_left = ConfigInteger(default = 56, limits = (0, 500))
176 self.settings.margin_right = ConfigInteger(default = 56, limits = (0, 500))
177 self.settings.space_rows = ConfigInteger(default = 32, limits = (0, 500))
178 self.settings.space_cols = ConfigInteger(default = 24, limits = (0, 500))
179 self.settings.prev_page_text = ConfigText(default = "<<<", fixed_size = False)
180 self.settings.next_page_text = ConfigText(default = ">>>", fixed_size = False)
181 self.settings.offset_headline = ConfigSequence(seperator = ',', default = [0,0], limits = [(-1,500),(-1,500)])
182 self.settings.offset_title = ConfigSequence(seperator = ',', default = [0,0], limits = [(-1,500),(-1,500)])
183 self.settings.offset_subtitle = ConfigSequence(seperator = ',', default = [20,0], limits = [(-1,500),(-1,500)])
184 self.settings.offset_thumb = ConfigSequence(seperator = ',', default = [40,0], limits = [(-1,500),(-1,500)])
185 self.settings.thumb_size = ConfigSequence(seperator = ',', default = [200,158], limits = [(0,576),(-1,720)])
186 self.settings.thumb_border = ConfigInteger(default = 2, limits = (0, 20))
187 self.filekeys = ["menubg", "menuaudio", "fontface_headline", "fontface_title", "fontface_subtitle"]
188 from TitleProperties import languageChoices
189 self.settings.menulang = ConfigSelection(choices = languageChoices.choices, default=languageChoices.choices[1][0])
191 def loadTemplate(self, filename):
192 ret = DVDProject.loadProject(self, filename)
193 DVDProject.error = self.error