asterisk next to modified preset is more accurate

hopefully
This commit is contained in:
tassaron 2017-06-13 22:47:18 -04:00
parent 307d499f9a
commit 2ad14b7d6c
9 changed files with 80 additions and 113 deletions

View File

@ -1,5 +1,6 @@
from PyQt4 import QtGui, QtCore
class Component(QtCore.QObject):
'''A base class for components to inherit from'''
@ -26,8 +27,8 @@ class Component(QtCore.QObject):
self.canceled = False
def update(self):
self.modified.emit(self.compPos, True)
# use super().update() then read your widget values here
self.modified.emit(self.compPos, self.savePreset())
# read your widget values, then call super().update()
def loadPreset(self, presetDict, presetName):
'''Children should take (presetDict, presetName=None) as args'''
@ -36,10 +37,10 @@ class Component(QtCore.QObject):
# Then update your widgets using the preset dict
self.currentPreset = presetName \
if presetName != None else presetDict['preset']
'''
def savePreset(self):
return {}
'''
def preFrameRender(self, **kwargs):
for var, value in kwargs.items():
exec('self.%s = value' % var)

View File

@ -8,7 +8,7 @@ from . import __base__
class Component(__base__.Component):
'''Color'''
modified = QtCore.pyqtSignal(int, bool)
modified = QtCore.pyqtSignal(int, dict)
def widget(self, parent):
self.parent = parent
@ -48,12 +48,12 @@ class Component(__base__.Component):
return page
def update(self):
super().update()
self.color1 = self.RGBFromString(self.page.lineEdit_color1.text())
self.color2 = self.RGBFromString(self.page.lineEdit_color2.text())
self.x = self.page.spinBox_x.value()
self.y = self.page.spinBox_y.value()
self.parent.drawPreview()
super().update()
def previewRender(self, previewWorker):
width = int(previewWorker.core.settings.value('outputWidth'))

View File

@ -7,7 +7,7 @@ from . import __base__
class Component(__base__.Component):
'''Image'''
modified = QtCore.pyqtSignal(int, bool)
modified = QtCore.pyqtSignal(int, dict)
def widget(self, parent):
self.parent = parent
@ -25,9 +25,9 @@ class Component(__base__.Component):
return page
def update(self):
super().update()
self.imagePath = self.page.lineEdit_image.text()
self.parent.drawPreview()
super().update()
def previewRender(self, previewWorker):
width = int(previewWorker.core.settings.value('outputWidth'))

View File

@ -11,7 +11,7 @@ from copy import copy
class Component(__base__.Component):
'''Original Audio Visualization'''
modified = QtCore.pyqtSignal(int, bool)
modified = QtCore.pyqtSignal(int, dict)
def widget(self, parent):
self.parent = parent
@ -35,10 +35,10 @@ class Component(__base__.Component):
return page
def update(self):
super().update()
self.layout = self.page.comboBox_visLayout.currentIndex()
self.visColor = self.RGBFromString(self.page.lineEdit_visColor.text())
self.parent.drawPreview()
super().update()
def loadPreset(self, pr, presetName=None):
super().loadPreset(pr, presetName)

View File

@ -10,7 +10,7 @@ from . import __base__
class Component(__base__.Component):
'''Title Text'''
modified = QtCore.pyqtSignal(int, bool)
modified = QtCore.pyqtSignal(int, dict)
def __init__(self, *args):
super().__init__(*args)
@ -56,7 +56,6 @@ class Component(__base__.Component):
return page
def update(self):
super().update()
self.title = self.page.lineEdit_title.text()
self.alignment = self.page.comboBox_textAlign.currentIndex()
self.titleFont = self.page.fontComboBox_titleFont.currentFont()
@ -66,6 +65,7 @@ class Component(__base__.Component):
self.textColor = self.RGBFromString(
self.page.lineEdit_textColor.text())
self.parent.drawPreview()
super().update()
def getXY(self):
'''Returns true x, y after considering alignment settings'''

View File

@ -87,7 +87,7 @@ class Video:
class Component(__base__.Component):
'''Video'''
modified = QtCore.pyqtSignal(int, bool)
modified = QtCore.pyqtSignal(int, dict)
def widget(self, parent):
self.parent = parent
@ -109,10 +109,10 @@ class Component(__base__.Component):
return page
def update(self):
super().update()
self.videoPath = self.page.lineEdit_video.text()
self.loopVideo = self.page.checkBox_loop.isChecked()
self.parent.drawPreview()
super().update()
def previewRender(self, previewWorker):
width = int(previewWorker.core.settings.value('outputWidth'))

125
core.py
View File

@ -6,9 +6,7 @@ from os.path import expanduser
import subprocess as sp
import numpy
from PIL import Image
#import tempfile
from shutil import rmtree
#import atexit
import time
from collections import OrderedDict
import json
@ -21,11 +19,6 @@ class Core():
def __init__(self):
self.FFMPEG_BIN = self.findFfmpeg()
#self.tempDir = os.path.join(
# tempfile.gettempdir(), 'audio-visualizer-python-data')
#if not os.path.exists(self.tempDir):
# os.makedirs(self.tempDir)
#atexit.register(self.deleteTempDir)
self.dataDir = QDesktopServices.storageLocation(
QDesktopServices.DataLocation)
self.presetDir = os.path.join(self.dataDir, 'presets')
@ -34,7 +27,8 @@ class Core():
self.findComponents()
self.selectedComponents = []
self.modifiedComponents = {}
# copies of named presets to detect modification
self.savedPresets = {}
def findComponents(self):
def findComponents():
@ -54,7 +48,6 @@ class Core():
def componentListChanged(self):
for i, component in enumerate(self.selectedComponents):
component.compPos = i
# print('Modified Components: ', self.modifiedComponents)
def insertComponent(self, compPos, moduleIndex):
if compPos < 0:
@ -66,76 +59,52 @@ class Core():
compPos,
component)
newDict = {}
for i, val in self.modifiedComponents.items():
if i >= compPos:
newDict[i+1] = bool(val)
else:
newDict[i] = bool(val)
self.modifiedComponents.clear()
self.modifiedComponents = newDict
self.componentListChanged()
return compPos
def moveComponent(self, startI, endI):
def insert(target, comp):
self.selectedComponents.insert(target, comp)
comp = self.selectedComponents.pop(startI)
insert(endI, comp)
try:
oldModified = self.modifiedComponents.pop(startI)
if endI in self.modifiedComponents:
self.modifiedComponents[startI] = \
self.modifiedComponents.pop(endI)
self.modifiedComponents[endI] = oldModified
except KeyError:
pass
self.selectedComponents.insert(endI, comp)
self.componentListChanged()
return endI
def removeComponent(self, i):
self.selectedComponents.pop(i)
try:
self.modifiedComponents.pop(i)
except KeyError:
pass
newDict = {}
for index, val in self.modifiedComponents.items():
if index >= i:
newDict[index-1] = bool(val)
else:
newDict[index] = bool(val)
self.modifiedComponents.clear()
self.modifiedComponents = newDict
self.componentListChanged()
def updateComponent(self, i):
# print('updating %s' % self.selectedComponents[i])
self.selectedComponents[i].update()
def componentModified(self, i):
'''Triggered by mainwindow.updateComponentTitle()
Tracks temporary state of whether components are modified or not
for retrieval upon loading a project file'''
self.modifiedComponents[i] = True
def componentUnmodified(self, i):
try:
self.modifiedComponents.pop(i)
except KeyError:
pass
def moduleIndexFor(self, compName):
compNames = [mod.Component.__doc__ for mod in self.modules]
index = compNames.index(compName)
return self.moduleIndexes[index]
def openPreset(self, filepath, compIndex, presetName):
'''Applies a preset to a specific component'''
saveValueStore = self.getPreset(filepath)
if not saveValueStore:
return False
self.selectedComponents[compIndex].loadPreset(
saveValueStore,
presetName
)
self.savedPresets[presetName] = dict(saveValueStore)
return True
def getPreset(self, filepath):
'''Returns the preset dict stored at this filepath'''
if not os.path.exists(filepath):
return False
with open(filepath, 'r') as f:
for line in f:
saveValueStore = Core.presetFromString(line.strip())
break
return saveValueStore
def openProject(self, loader, filepath):
'''loader is the object calling this method (mainwindow/command)
which implements an insertComponent method'''
@ -143,15 +112,29 @@ class Core():
if errcode == 0:
for i, tup in enumerate(data['Components']):
name, vers, preset = tup
# add loaded named presets to savedPresets dict
if 'preset' in preset and preset['preset'] != None:
nam = preset['preset']
filepath2 = os.path.join(
self.presetDir, name, str(vers), nam)
origSaveValueStore = self.getPreset(filepath2)
self.savedPresets[nam] = dict(origSaveValueStore)
# insert component into the loader
loader.insertComponent(
self.moduleIndexFor(name), -1)
self.selectedComponents[-1].loadPreset(
preset)
if data['Modified'][i] == True:
self.componentModified(i)
loader.updateComponentTitle(i, True)
if 'preset' in preset and preset['preset'] != None:
self.selectedComponents[-1].loadPreset(
preset
)
else:
loader.updateComponentTitle(i)
self.selectedComponents[-1].loadPreset(
preset,
preset['preset']
)
elif errcode == 1:
typ, value, _ = data
if typ.__name__ == KeyError:
@ -174,7 +157,7 @@ class Core():
with open(filepath, 'r') as f:
def parseLine(line):
'''Decides if a given avp or avl line is a section header'''
validSections = ('Components', 'Modified')
validSections = ('Components')
line = line.strip()
newSection = ''
@ -207,8 +190,6 @@ class Core():
lastCompPreset)
)
i = 0
if line and section == 'Modified':
data[section].append(eval(line))
return 0, data
except:
return 1, sys.exc_info()
@ -294,12 +275,6 @@ class Core():
f.write('%s\n' % str(comp))
f.write('%s\n' % str(comp.version()))
f.write('%s\n' % Core.presetToString(saveValueStore))
f.write('[Modified]\n')
for i in range(len(self.selectedComponents)):
if i in self.modifiedComponents:
f.write('%s\n' % repr(True))
else:
f.write('%s\n' % repr(False))
return True
except:
return False
@ -385,12 +360,6 @@ class Core():
return completeAudioArray
#def deleteTempDir(self):
# try:
# rmtree(self.tempDir)
# except FileNotFoundError:
# pass
def cancel(self):
self.canceled = True

View File

@ -235,9 +235,17 @@ class MainWindow(QtCore.QObject):
self.previewThread.wait()
self.autosave()
@QtCore.pyqtSlot(int, bool)
def updateComponentTitle(self, pos, modified=False):
#print(pos, modified)
@QtCore.pyqtSlot(int, dict)
def updateComponentTitle(self, pos, presetStore=False):
if type(presetStore) == dict:
name = presetStore['preset']
if name == None:
modified = False
else:
modified = (presetStore != self.core.savedPresets[name])
else:
print(pos, presetStore)
modified = bool(presetStore)
if pos < 0:
pos = len(self.core.selectedComponents)-1
title = str(self.core.selectedComponents[pos])
@ -246,10 +254,6 @@ class MainWindow(QtCore.QObject):
if modified:
title += '*'
self.window.listWidget_componentList.item(pos).setText(title)
if modified:
self.core.componentModified(pos)
else:
self.core.componentUnmodified(pos)
def updateCodecs(self):
containerWidget = self.window.comboBox_videoContainer
@ -521,6 +525,8 @@ class MainWindow(QtCore.QObject):
"Project Files (*.avp)")
if not filename:
return
if not filename.endswith(".avp"):
filename += '.avp'
self.settings.setValue("projectDir", os.path.dirname(filename))
self.settings.setValue("currentProject", filename)
self.currentProject = filename

View File

@ -14,6 +14,7 @@ class PresetManager(QtGui.QDialog):
self.presetDir = self.core.presetDir
self.findPresets()
# window
self.lastFilter = '*'
self.presetRows = [] # list of (comp, vers, name) tuples
self.window = window
@ -126,6 +127,7 @@ class PresetManager(QtGui.QDialog):
continue
if newName:
if index != -1:
selectedComponents[index].currentPreset = newName
saveValueStore = \
selectedComponents[index].savePreset()
componentName = str(selectedComponents[index]).strip()
@ -133,10 +135,7 @@ class PresetManager(QtGui.QDialog):
self.createNewPreset(
componentName, vers, newName,
saveValueStore, window=self.parent.window)
selectedComponents[index].currentPreset = newName
#self.findPresets()
#self.drawPresetList()
self.parent.updateComponentTitle(index)
self.openPreset(newName)
break
def createNewPreset(
@ -173,16 +172,8 @@ class PresetManager(QtGui.QDialog):
version = selectedComponents[index].version()
dirname = os.path.join(self.presetDir, componentName, str(version))
filepath = os.path.join(dirname, presetName)
if not os.path.exists(filepath):
return
with open(filepath, 'r') as f:
for line in f:
saveValueStore = core.Core.presetFromString(line.strip())
break
selectedComponents[index].loadPreset(
saveValueStore,
presetName
)
self.core.openPreset(filepath, index, presetName)
self.parent.updateComponentTitle(index)
self.parent.drawPreview()