1 from Tools.Directories import fileExists
2 from Components.config import config, ConfigSubsection, ConfigInteger, ConfigYesNo, ConfigText, ConfigSelection, getConfigListEntry, ConfigSequence
4 class ConfigColor(ConfigSequence):
6 ConfigSequence.__init__(self, seperator = "#", limits = [(0,255),(0,255),(0,255)])
8 class ConfigPixelvals(ConfigSequence):
10 ConfigSequence.__init__(self, seperator = ",", limits = [(0,200),(0,200),(0,200)])
16 self.settings = ConfigSubsection()
17 self.settings.name = ConfigText(visible_width = 40)
18 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")), ])
19 self.settings.menubg = ConfigText(visible_width = 40)
20 self.settings.menuaudio = ConfigText(visible_width = 40)
21 self.settings.titleformat = ConfigText(visible_width = 40)
22 self.settings.subtitleformat = ConfigText(visible_width = 40)
23 self.settings.color_headline = ConfigColor()
24 self.settings.color_highlight = ConfigColor()
25 self.settings.color_button = ConfigColor()
26 self.settings.font_face = ConfigText(visible_width = 40)
27 self.settings.font_size = ConfigPixelvals()
28 self.settings.space = ConfigPixelvals()
29 self.settings.vmgm = ConfigText(visible_width = 40)
30 self.settings.autochapter = ConfigInteger(default = 0, limits = (0, 99))
31 self.filekeys = ["vmgm", "menubg", "menuaudio", "font_face"]
33 def addService(self, service):
35 title = DVDTitle.DVDTitle()
36 title.addService(service)
37 self.titles.append(title)
40 def saveProject(self, path):
41 import xml.dom.minidom
42 from Tools.XMLTools import elementsWithTag, mergeText, stringToXML
44 list.append('<?xml version="1.0" encoding="utf-8" ?>\n')
45 list.append('<DreamDVDBurnerProject>\n')
46 list.append('\t<settings ')
47 for key, val in self.settings.dict().iteritems():
48 list.append( key + '="' + str(val.getValue()) + '" ' )
50 list.append('\t<titles>\n')
51 for title in self.titles:
52 list.append('\t\t<path>')
53 list.append(stringToXML(title.source.getPath()))
54 list.append('</path>\n')
55 list.append('\t</titles>\n')
56 list.append('</DreamDVDBurnerProject>\n')
58 name = self.settings.name.getValue()
60 filename = path + name + ".ddvdp.xml"
61 while fileExists(filename):
63 filename = path + name + str(i).zfill(3) + ".ddvdp.xml"
65 file = open(filename, "w")
73 def loadProject(self, filename):
74 import xml.dom.minidom
76 if not fileExists(filename):
77 self.error = "xml file not found!"
81 file = open(filename, "r")
82 data = file.read().decode("utf-8").replace('&',"&").encode("ascii",'xmlcharrefreplace')
84 projectfiledom = xml.dom.minidom.parseString(data)
85 for project in projectfiledom.childNodes[0].childNodes:
86 if project.nodeType == xml.dom.minidom.Element.nodeType:
87 if project.tagName == 'settings':
89 if project.attributes.length < 11:
90 self.error = "project attributes missing"
92 while i < project.attributes.length:
93 item = project.attributes.item(i)
94 key = item.name.encode("utf-8")
96 val = eval(item.nodeValue)
97 except (NameError, SyntaxError):
98 val = item.nodeValue.encode("utf-8")
100 self.settings.dict()[key].setValue(val)
102 self.error = "unknown attribute '%s'" % (key)
105 for key in self.filekeys:
106 val = self.settings.dict()[key].getValue()
107 if not fileExists(val):
108 self.error += "\n%s '%s' not found" % (key, val)
111 except AttributeError:
112 self.error += (" in project '%s'") % (filename)