aboutsummaryrefslogtreecommitdiff
path: root/src/core.py
diff options
context:
space:
mode:
authorBrianna2017-06-25 15:53:49 -0400
committerGitHub2017-06-25 15:53:49 -0400
commitf86c33d0e5aca7dcb74fd6d87e3395ee1595b088 (patch)
tree3215f071c503abb113c979847f5c66696f692ef0 /src/core.py
parent55423ca4aa206ec9a082942ca89da7dcb4f452bc (diff)
parent2c82a65d1b79b898b2bc27fc5b1e0362fc160c46 (diff)
Merge pull request #36 from djfun/newgui-project-settings
Project files save more settings
Diffstat (limited to 'src/core.py')
-rw-r--r--src/core.py76
1 files changed, 65 insertions, 11 deletions
diff --git a/src/core.py b/src/core.py
index fdba1c4..2994a24 100644
--- a/src/core.py
+++ b/src/core.py
@@ -30,6 +30,10 @@ class Core():
# unfrozen
self.wd = os.path.dirname(os.path.realpath(__file__))
self.componentsPath = os.path.join(self.wd, 'components')
+ self.settings = QtCore.QSettings(
+ os.path.join(self.dataDir, 'settings.ini'),
+ QtCore.QSettings.IniFormat
+ )
self.loadEncoderOptions()
self.videoFormats = Core.appendUppercase([
@@ -169,13 +173,23 @@ class Core():
its own showMessage(**kwargs) method for displaying errors.
'''
if not os.path.exists(filepath):
- loader.showMessage(msg='Project file not found')
+ loader.showMessage(msg='Project file not found.')
return
errcode, data = self.parseAvFile(filepath)
if errcode == 0:
try:
- for i, tup in enumerate(data['Components']):
+ if hasattr(loader, 'window'):
+ for widget, value in data['WindowFields']:
+ widget = eval('loader.window.%s' % widget)
+ widget.blockSignals(True)
+ widget.setText(value)
+ widget.blockSignals(False)
+
+ for key, value in data['Settings']:
+ self.settings.setValue(key, value)
+
+ for tup in data['Components']:
name, vers, preset = tup
clearThis = False
modified = False
@@ -213,7 +227,7 @@ class Core():
preset['preset']
)
except KeyError as e:
- print('%s missing value %s' % (
+ print('%s missing value: %s' % (
self.selectedComponents[i], e)
)
@@ -221,23 +235,26 @@ class Core():
self.clearPreset(i)
if hasattr(loader, 'updateComponentTitle'):
loader.updateComponentTitle(i, modified)
+
except:
errcode = 1
data = sys.exc_info()
if errcode == 1:
- typ, value, _ = data
- if typ.__name__ == KeyError:
+ typ, value, tb = data
+ if typ.__name__ == 'KeyError':
# probably just an old version, still loadable
print('file missing value: %s' % value)
return
if hasattr(loader, 'createNewProject'):
loader.createNewProject()
- msg = '%s: %s' % (typ.__name__, value)
+ import traceback
+ msg = '%s: %s\n\nTraceback:\n' % (typ.__name__, value)
+ msg += "\n".join(traceback.format_tb(tb))
loader.showMessage(
msg="Project file '%s' is corrupted." % filepath,
showCancel=False,
- icon=QtGui.QMessageBox.Warning,
+ icon='Warning',
detail=msg)
def parseAvFile(self, filepath):
@@ -245,12 +262,16 @@ class Core():
Returns dictionary with section names as the keys, each one
contains a list of tuples: (compName, version, compPresetDict)
'''
- data = {}
+ validSections = (
+ 'Components',
+ 'Settings',
+ 'WindowFields'
+ )
+ data = {sect: [] for sect in validSections}
try:
with open(filepath, 'r') as f:
def parseLine(line):
'''Decides if a file line is a section header'''
- validSections = ('Components')
line = line.strip()
newSection = ''
@@ -266,7 +287,6 @@ class Core():
line, newSection = parseLine(line)
if newSection:
section = str(newSection)
- data[section] = []
continue
if line and section == 'Components':
if i == 0:
@@ -283,6 +303,10 @@ class Core():
lastCompPreset
))
i = 0
+ elif line and section:
+ key, value = line.split('=', 1)
+ data[section].append((key, value.strip()))
+
return 0, data
except:
return 1, sys.exc_info()
@@ -354,8 +378,22 @@ class Core():
f.write('%s\n' % str(vers))
f.write(Core.presetToString(saveValueStore))
- def createProjectFile(self, filepath):
+ def createProjectFile(self, filepath, window=None):
'''Create a project file (.avp) using the current program state'''
+ forbiddenSettingsKeys = [
+ 'currentProject',
+ 'outputAudioBitrate',
+ 'outputAudioCodec',
+ 'outputContainer',
+ 'outputFormat',
+ 'outputFrameRate',
+ 'outputHeight',
+ 'outputPreset',
+ 'outputVideoBitrate',
+ 'outputVideoCodec',
+ 'outputVideoFormat',
+ 'outputWidth',
+ ]
try:
if not filepath.endswith(".avp"):
filepath += '.avp'
@@ -363,12 +401,28 @@ class Core():
os.remove(filepath)
with open(filepath, 'w') as f:
print('creating %s' % filepath)
+
f.write('[Components]\n')
for comp in self.selectedComponents:
saveValueStore = comp.savePreset()
f.write('%s\n' % str(comp))
f.write('%s\n' % str(comp.version()))
f.write('%s\n' % Core.presetToString(saveValueStore))
+
+ f.write('\n[Settings]\n')
+ for key in self.settings.allKeys():
+ if key not in forbiddenSettingsKeys:
+ f.write('%s=%s\n' % (key, self.settings.value(key)))
+
+ if window:
+ f.write('\n[WindowFields]\n')
+ f.write(
+ 'lineEdit_audioFile=%s\n'
+ 'lineEdit_outputFile=%s\n' % (
+ window.lineEdit_audioFile.text(),
+ window.lineEdit_outputFile.text()
+ )
+ )
return True
except:
return False