comparison python/libs/project.py @ 68:654c5ac4f2c5

Refactor of menus
author windel
date Sat, 13 Oct 2012 16:13:05 +0200
parents 99bf4f7d47f4
children
comparison
equal deleted inserted replaced
67:99bf4f7d47f4 68:654c5ac4f2c5
2 source project 2 source project
3 contains: 3 contains:
4 - modules 4 - modules
5 - primitives like functions, types and variables 5 - primitives like functions, types and variables
6 - other modules 6 - other modules
7
8 """ 7 """
9 8
10 import json 9 import json
11 10
12 class Project: 11 class Project:
13 def __init__(self, filename=None): 12 def __init__(self, filename=None):
14 self.name = "" 13 self.name = ""
15 self.modules = [] 14 self.modules = []
16 self.elements = [] 15 self.elements = []
17 self.settings = {} 16 self.settings = {}
17 if filename:
18 self.load(filename)
19
20 def load(self, filename):
21 """ Load the project from file """
18 self.filename = filename 22 self.filename = filename
19 23
20 if self.filename: 24 with open(self.filename, 'r') as f:
21 """ Load the project from the XML file """ 25 d = json.load(f)
22 with open(self.filename, 'r') as f: 26 self.elements = d['elements']
23 d = json.load(f) 27
24 self.elements = d['elements']
25
26 def save(self): 28 def save(self):
27 if self.filename: 29 if self.filename:
28 d = {'elements': self.elements} 30 d = {'elements': self.elements}
29 print(d) 31 print(d)
30 with open(self.filename, 'w') as f: 32 with open(self.filename, 'w') as f: