2 from Tools.Directories import fileExists
3 from Components.config import config, ConfigSubsection, ConfigInteger, ConfigYesNo, ConfigText, ConfigSelection, getConfigListEntry, ConfigSequence
5 class ConfigColor(ConfigSequence):
7 ConfigSequence.__init__(self, seperator = "#", limits = [(0,255),(0,255),(0,255)])
9 class ConfigPixelvals(ConfigSequence):
11 ConfigSequence.__init__(self, seperator = ",", limits = [(0,200),(0,200),(0,200)])
13 class ConfigPixelvals(ConfigSequence):
15 ConfigSequence.__init__(self, seperator = ",", limits = [(0,200),(0,200),(0,200)])
17 class ConfigFilename(ConfigText):
19 ConfigText.__init__(self, default = "", fixed_size = True, visible_width = False)
21 def getMulti(self, selected):
22 filename = (self.text.rstrip("/").rsplit("/",1))[1].encode("utf-8")[:40] + " "
24 mark = range(0, len(filename))
27 return ("mtext"[1-selected:], filename, mark)
33 self.settings = ConfigSubsection()
34 self.settings.name = ConfigText(fixed_size = False, visible_width = 40)
35 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)"))])
36 self.settings.menubg = ConfigFilename()
37 self.settings.menuaudio = ConfigFilename()
38 self.settings.titleformat = ConfigText(fixed_size = False, visible_width = 40)
39 self.settings.subtitleformat = ConfigText(fixed_size = False, visible_width = 40)
40 self.settings.color_headline = ConfigColor()
41 self.settings.color_highlight = ConfigColor()
42 self.settings.color_button = ConfigColor()
43 self.settings.font_face = ConfigFilename()
44 self.settings.font_size = ConfigPixelvals()
45 self.settings.space = ConfigPixelvals()
46 self.settings.vmgm = ConfigFilename()
47 self.settings.autochapter = ConfigInteger(default = 0, limits = (0, 99))
48 self.filekeys = ["vmgm", "menubg", "menuaudio", "font_face"]
50 def addService(self, service):
52 title = DVDTitle.DVDTitle()
53 title.addService(service)
54 self.titles.append(title)
57 def saveProject(self, path):
58 import xml.dom.minidom
59 from Tools.XMLTools import elementsWithTag, mergeText, stringToXML
61 list.append('<?xml version="1.0" encoding="utf-8" ?>\n')
62 list.append('<DreamDVDBurnerProject>\n')
63 list.append('\t<settings ')
64 for key, val in self.settings.dict().iteritems():
65 list.append( key + '="' + str(val.getValue()) + '" ' )
67 list.append('\t<titles>\n')
68 for title in self.titles:
69 list.append('\t\t<path>')
70 list.append(stringToXML(title.source.getPath()))
71 list.append('</path>\n')
72 list.append('\t</titles>\n')
73 list.append('</DreamDVDBurnerProject>\n')
75 name = self.settings.name.getValue()
77 filename = path + name + ".ddvdp.xml"
78 while fileExists(filename):
80 filename = path + name + str(i).zfill(3) + ".ddvdp.xml"
82 file = open(filename, "w")
90 def loadProject(self, filename):
91 import xml.dom.minidom
93 if not fileExists(filename):
94 self.error = "xml file not found!"
98 file = open(filename, "r")
99 data = file.read().decode("utf-8").replace('&',"&").encode("ascii",'xmlcharrefreplace')
101 projectfiledom = xml.dom.minidom.parseString(data)
102 for project in projectfiledom.childNodes[0].childNodes:
103 if project.nodeType == xml.dom.minidom.Element.nodeType:
104 if project.tagName == 'settings':
106 if project.attributes.length < 11:
107 self.error = "project attributes missing"
109 while i < project.attributes.length:
110 item = project.attributes.item(i)
111 key = item.name.encode("utf-8")
113 val = eval(item.nodeValue)
114 except (NameError, SyntaxError):
115 val = item.nodeValue.encode("utf-8")
117 self.settings.dict()[key].setValue(val)
119 self.error = "unknown attribute '%s'" % (key)
122 for key in self.filekeys:
123 val = self.settings.dict()[key].getValue()
124 if not fileExists(val):
125 self.error += "\n%s '%s' not found" % (key, val)
128 except AttributeError:
129 self.error += (" in project '%s'") % (filename)