comparison ide/project.py @ 15:de004f808e56

Fixup in multidocument area stuff
author windel
date Tue, 15 Nov 2011 07:35:00 +0100
parents edd70006d3e4
children
comparison
equal deleted inserted replaced
11:607898120eb1 15:de004f808e56
19 self.project.files.append(attrs['Filename']) 19 self.project.files.append(attrs['Filename'])
20 def endElement(self, name): 20 def endElement(self, name):
21 if name == 'Files': 21 if name == 'Files':
22 self.inFiles = False 22 self.inFiles = False
23 23
24 class ProjectFile:
25 def __init__(self, filename):
26 self.filename = filename
27
24 class Project: 28 class Project:
25 def __init__(self): 29 def __init__(self, filename, isnew=False):
26 self.name = "" 30 self.name = ""
27 self.files = [] 31 self.files = []
28 self.settings = {} 32 self.settings = {}
29 self.filename = "" 33 self.filename = filename
34
35 if not isnew:
36 """ Load the project from the XML file """
37 parser = make_parser()
38 handler = ProjectContentHandler(self)
39 parser.setContentHandler(handler)
40 parser.parse(filename)
30 41
31 def save(self, filename): 42 def save(self, filename):
32 """ Save the project in XML format """ 43 """ Save the project in XML format """
33 # Create document: 44 # Create document:
34 doc = md.Document() 45 doc = md.Document()
48 # Write the XML file: 59 # Write the XML file:
49 xml = doc.toprettyxml() 60 xml = doc.toprettyxml()
50 with open(filename, 'w') as f: 61 with open(filename, 'w') as f:
51 f.write(xml) 62 f.write(xml)
52 63
53 def load(self, filename): 64 def loadProjectFile(self, filename):
54 """ Load the project from the XML file """ 65 basedir = os.path.dirname(self.filename)
55 if not os.path.exists(filename): 66 filename = os.path.join(basedir, filename)
56 return 67 with open(filename, 'r') as f:
57 self.filename = filename 68 src = f.read()
58 print(self.filename) 69 return src
59 parser = make_parser()
60 handler = ProjectContentHandler(self)
61 parser.setContentHandler(handler)
62 parser.parse(filename)
63 70