eric6/E5XML/TemplatesWriter.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2005 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the writer class for writing an XML templates file.
8 """
9
10 from __future__ import unicode_literals
11
12 import time
13
14 from .XMLStreamWriterBase import XMLStreamWriterBase
15 from .Config import templatesFileFormatVersion
16
17
18 class TemplatesWriter(XMLStreamWriterBase):
19 """
20 Class implementing the writer class for writing an XML templates file.
21 """
22 def __init__(self, device, templatesViewer):
23 """
24 Constructor
25
26 @param device reference to the I/O device to write to (QIODevice)
27 @param templatesViewer reference to the templates viewer object
28 (TemplateViewer)
29 """
30 XMLStreamWriterBase.__init__(self, device)
31
32 self.templatesViewer = templatesViewer
33
34 def writeXML(self):
35 """
36 Public method to write the XML to the file.
37 """
38 XMLStreamWriterBase.writeXML(self)
39
40 self.writeDTD('<!DOCTYPE Templates SYSTEM "Templates-{0}.dtd">'.format(
41 templatesFileFormatVersion))
42
43 # add some generation comments
44 self.writeComment(" eric6 templates file ")
45 self.writeComment(
46 " Saved: {0} ".format(time.strftime('%Y-%m-%d, %H:%M:%S')))
47
48 # add the main tag
49 self.writeStartElement("Templates")
50 self.writeAttribute("version", templatesFileFormatVersion)
51
52 # do the template groups
53 groups = self.templatesViewer.getAllGroups()
54 for group in groups:
55 self.writeStartElement("TemplateGroup")
56 self.writeAttribute("name", group.getName())
57 self.writeAttribute("language", group.getLanguage())
58 # do the templates
59 templates = group.getAllEntries()
60 for template in templates:
61 self.writeStartElement("Template")
62 self.writeAttribute("name", template.getName())
63 self.writeTextElement(
64 "TemplateDescription", template.getDescription())
65 self.writeTextElement(
66 "TemplateText", template.getTemplateText())
67 self.writeEndElement()
68 self.writeEndElement()
69
70 self.writeEndElement()
71 self.writeEndDocument()

eric ide

mercurial