annotate python/project.py @ 228:7f18ed9b6b7e

Removal of emptystatement class
author Windel Bouwman
date Sat, 13 Jul 2013 11:12:24 +0200
parents 5a965e9664f2
children
rev   line source
7
2db4d2b362e6 Added xml project
windel
parents:
diff changeset
1 """
67
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
2 source project
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
3 contains:
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
4 - modules
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
5 - primitives like functions, types and variables
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
6 - other modules
7
2db4d2b362e6 Added xml project
windel
parents:
diff changeset
7 """
2db4d2b362e6 Added xml project
windel
parents:
diff changeset
8
67
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
9 import json
15
de004f808e56 Fixup in multidocument area stuff
windel
parents: 8
diff changeset
10
7
2db4d2b362e6 Added xml project
windel
parents:
diff changeset
11 class Project:
67
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
12 def __init__(self, filename=None):
7
2db4d2b362e6 Added xml project
windel
parents:
diff changeset
13 self.name = ""
67
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
14 self.modules = []
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
15 self.elements = []
7
2db4d2b362e6 Added xml project
windel
parents:
diff changeset
16 self.settings = {}
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
17 if filename:
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
18 self.load(filename)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
19
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
20 def load(self, filename):
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
21 """ Load the project from file """
15
de004f808e56 Fixup in multidocument area stuff
windel
parents: 8
diff changeset
22 self.filename = filename
de004f808e56 Fixup in multidocument area stuff
windel
parents: 8
diff changeset
23
68
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
24 with open(self.filename, 'r') as f:
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
25 d = json.load(f)
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
26 self.elements = d['elements']
654c5ac4f2c5 Refactor of menus
windel
parents: 67
diff changeset
27
67
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
28 def save(self):
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
29 if self.filename:
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
30 d = {'elements': self.elements}
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
31 print(d)
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
32 with open(self.filename, 'w') as f:
99bf4f7d47f4 Changed project storage
windel
parents: 63
diff changeset
33 json.dump(d, f)
7
2db4d2b362e6 Added xml project
windel
parents:
diff changeset
34