section structure in avp files

This commit is contained in:
tassaron 2017-06-03 11:08:52 -04:00
parent 0bef283f8d
commit f0ab2f53d6
1 changed files with 27 additions and 11 deletions

16
main.py
View File

@ -473,6 +473,7 @@ class Main(QtCore.QObject):
if not filepath.endswith(".avp"):
filepath += '.avp'
with open(filepath, 'w') as f:
f.write('[Components]\n')
for comp in self.selectedComponents:
saveValueStore = comp.savePreset()
f.write('%s\n' % str(comp))
@ -496,9 +497,24 @@ class Main(QtCore.QObject):
self.settings.setValue("lastProject", filepath)
self.settings.setValue("projectDir", os.path.dirname(filepath))
compNames = [mod.Component.__doc__ for mod in self.modules]
with open(filepath, 'r') as f:
validSections = ('Components')
section = ''
def parseLine(line):
line = line.strip()
newSection = ''
if line.startswith('[') and line.endswith(']') and line[1:-1] in validSections:
newSection = line[1:-1]
return line, newSection
i = 0
for line in f:
line, newSection = parseLine(line)
if newSection:
section = str(newSection)
continue
if line and section == 'Components':
if i == 0:
compIndex = compNames.index(line.strip())
self.addComponent(compIndex)