saved project dirs
This commit is contained in:
parent
fccdee45b2
commit
0bef283f8d
|
@ -8,6 +8,10 @@ from . import __base__
|
||||||
|
|
||||||
class Component(__base__.Component):
|
class Component(__base__.Component):
|
||||||
'''Title Text'''
|
'''Title Text'''
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.titleFont = QFont()
|
||||||
|
|
||||||
def widget(self, parent):
|
def widget(self, parent):
|
||||||
height = int(parent.settings.value('outputHeight'))
|
height = int(parent.settings.value('outputHeight'))
|
||||||
width = int(parent.settings.value('outputWidth'))
|
width = int(parent.settings.value('outputWidth'))
|
||||||
|
@ -36,8 +40,8 @@ class Component(__base__.Component):
|
||||||
page.pushButton_textColor.setStyleSheet(btnStyle)
|
page.pushButton_textColor.setStyleSheet(btnStyle)
|
||||||
|
|
||||||
page.lineEdit_title.setText(self.title)
|
page.lineEdit_title.setText(self.title)
|
||||||
if not self.titleFont == None:
|
#if self.titleFont:
|
||||||
page.fontComboBox_titleFont.setCurrentFont(QFont(self.titleFont))
|
# page.fontComboBox_titleFont.setCurrentFont(QFont(self.titleFont))
|
||||||
page.comboBox_textAlign.setCurrentIndex(int(self.alignment))
|
page.comboBox_textAlign.setCurrentIndex(int(self.alignment))
|
||||||
page.spinBox_fontSize.setValue(int(self.fontSize))
|
page.spinBox_fontSize.setValue(int(self.fontSize))
|
||||||
page.spinBox_xTextAlign.setValue(int(self.xPosition))
|
page.spinBox_xTextAlign.setValue(int(self.xPosition))
|
||||||
|
|
69
main.py
69
main.py
|
@ -146,16 +146,18 @@ class Main(QtCore.QObject):
|
||||||
self.pages = []
|
self.pages = []
|
||||||
self.selectedComponents = []
|
self.selectedComponents = []
|
||||||
|
|
||||||
# create data directory structure if needed
|
# create data directory, load/create settings
|
||||||
self.dataDir = QDesktopServices.storageLocation(QDesktopServices.DataLocation)
|
self.dataDir = QDesktopServices.storageLocation(QDesktopServices.DataLocation)
|
||||||
if not os.path.exists(self.dataDir):
|
|
||||||
os.makedirs(self.dataDir)
|
|
||||||
for neededDirectory in ('projects', 'project-settings', 'presets'):
|
|
||||||
if not os.path.exists(os.path.join(self.dataDir, neededDirectory)):
|
|
||||||
os.mkdir(os.path.join(self.dataDir, neededDirectory))
|
|
||||||
self.settings = QSettings(os.path.join(self.dataDir, 'settings.ini'), QSettings.IniFormat)
|
self.settings = QSettings(os.path.join(self.dataDir, 'settings.ini'), QSettings.IniFormat)
|
||||||
LoadDefaultSettings(self)
|
LoadDefaultSettings(self)
|
||||||
|
if not os.path.exists(self.dataDir):
|
||||||
|
os.makedirs(self.dataDir)
|
||||||
|
presetDir = os.path.join(self.dataDir, 'presets')
|
||||||
|
for neededDirectory in (presetDir, self.settings.value("projectDir")):
|
||||||
|
if not os.path.exists(neededDirectory):
|
||||||
|
os.mkdir(neededDirectory)
|
||||||
|
|
||||||
|
#
|
||||||
self.previewQueue = Queue()
|
self.previewQueue = Queue()
|
||||||
self.previewThread = QtCore.QThread(self)
|
self.previewThread = QtCore.QThread(self)
|
||||||
self.previewWorker = preview_thread.Worker(self, self.previewQueue)
|
self.previewWorker = preview_thread.Worker(self, self.previewQueue)
|
||||||
|
@ -176,7 +178,7 @@ class Main(QtCore.QObject):
|
||||||
window.pushButton_Cancel.clicked.connect(self.stopVideo)
|
window.pushButton_Cancel.clicked.connect(self.stopVideo)
|
||||||
window.setWindowTitle("Audio Visualizer")
|
window.setWindowTitle("Audio Visualizer")
|
||||||
|
|
||||||
self.previewWindow = PreviewWindow(self, r"background.jpg")
|
self.previewWindow = PreviewWindow(self, os.path.join(os.path.dirname(os.path.realpath(__file__)), "background.jpg"))
|
||||||
window.verticalLayout_previewWrapper.addWidget(self.previewWindow)
|
window.verticalLayout_previewWrapper.addWidget(self.previewWindow)
|
||||||
|
|
||||||
self.modules = self.findComponents()
|
self.modules = self.findComponents()
|
||||||
|
@ -206,19 +208,14 @@ class Main(QtCore.QObject):
|
||||||
self.window.pushButton_saveProject.clicked.connect(self.saveCurrentProject)
|
self.window.pushButton_saveProject.clicked.connect(self.saveCurrentProject)
|
||||||
self.window.pushButton_openProject.clicked.connect(self.openOpenProjectDialog)
|
self.window.pushButton_openProject.clicked.connect(self.openOpenProjectDialog)
|
||||||
|
|
||||||
|
self.openProject(self.settings.value("lastProject"))
|
||||||
self.drawPreview()
|
self.drawPreview()
|
||||||
|
|
||||||
window.show()
|
window.show()
|
||||||
|
|
||||||
def cleanUp(self):
|
def cleanUp(self):
|
||||||
self.timer.stop()
|
self.timer.stop()
|
||||||
self.previewThread.quit()
|
self.previewThread.quit()
|
||||||
self.previewThread.wait()
|
self.previewThread.wait()
|
||||||
backupPath = os.path.join(self.dataDir, 'settings.ini~')
|
|
||||||
settingsPath = self.settings.fileName()
|
|
||||||
if self.currentProject:
|
|
||||||
os.remove(settingsPath)
|
|
||||||
os.rename(backupPath, settingsPath)
|
|
||||||
|
|
||||||
def openInputFileDialog(self):
|
def openInputFileDialog(self):
|
||||||
inputDir = self.settings.value("inputDir", expanduser("~"))
|
inputDir = self.settings.value("inputDir", expanduser("~"))
|
||||||
|
@ -343,10 +340,12 @@ class Main(QtCore.QObject):
|
||||||
self.window.listWidget_componentList.takeItem(index)
|
self.window.listWidget_componentList.takeItem(index)
|
||||||
self.selectedComponents.pop(index)
|
self.selectedComponents.pop(index)
|
||||||
self.pages.pop(index)
|
self.pages.pop(index)
|
||||||
|
self.changeComponentWidget()
|
||||||
self.drawPreview()
|
self.drawPreview()
|
||||||
|
|
||||||
def changeComponentWidget(self):
|
def changeComponentWidget(self):
|
||||||
selected = self.window.listWidget_componentList.selectedItems()
|
selected = self.window.listWidget_componentList.selectedItems()
|
||||||
|
if selected:
|
||||||
index = self.window.listWidget_componentList.row(selected[0])
|
index = self.window.listWidget_componentList.row(selected[0])
|
||||||
self.window.stackedWidget.setCurrentIndex(index)
|
self.window.stackedWidget.setCurrentIndex(index)
|
||||||
self.updateOpenPresetComboBox(self.selectedComponents[index])
|
self.updateOpenPresetComboBox(self.selectedComponents[index])
|
||||||
|
@ -463,35 +462,39 @@ class Main(QtCore.QObject):
|
||||||
self.openSaveProjectDialog()
|
self.openSaveProjectDialog()
|
||||||
|
|
||||||
def openSaveProjectDialog(self):
|
def openSaveProjectDialog(self):
|
||||||
outputDir = os.path.join(self.dataDir, 'projects')
|
filename = QtGui.QFileDialog.getSaveFileName(self.window,
|
||||||
filename = QtGui.QFileDialog.getSaveFileName(self.window, "Create Project File", outputDir)
|
"Create Project File", self.settings.value("projectDir"),
|
||||||
|
"Project Files (*.avp)")
|
||||||
if not filename:
|
if not filename:
|
||||||
return
|
return
|
||||||
filepath = os.path.join(outputDir, filename)
|
self.createProjectFile(filename)
|
||||||
self.currentProject = filepath
|
|
||||||
self.createProjectFile(filepath)
|
|
||||||
|
|
||||||
def createProjectFile(self, filepath):
|
def createProjectFile(self, filepath):
|
||||||
|
if not filepath.endswith(".avp"):
|
||||||
|
filepath += '.avp'
|
||||||
with open(filepath, 'w') as f:
|
with open(filepath, 'w') as f:
|
||||||
for comp in self.selectedComponents:
|
for comp in self.selectedComponents:
|
||||||
saveValueStore = comp.savePreset()
|
saveValueStore = comp.savePreset()
|
||||||
f.write('%s\n' % str(comp))
|
f.write('%s\n' % str(comp))
|
||||||
f.write('%s\n' % str(comp.version()))
|
f.write('%s\n' % str(comp.version()))
|
||||||
f.write('%s\n' % repr(saveValueStore))
|
f.write('%s\n' % repr(saveValueStore))
|
||||||
projSettingsPath = os.path.join(self.dataDir, 'project-settings', os.path.basename('%s.ini' % filepath))
|
self.settings.setValue("projectDir", os.path.dirname(filepath))
|
||||||
shutil.copyfile(self.settings.fileName(), projSettingsPath)
|
self.settings.setValue("lastProject", filepath)
|
||||||
|
self.currentProject = filepath
|
||||||
|
|
||||||
def openOpenProjectDialog(self):
|
def openOpenProjectDialog(self):
|
||||||
inputDir = os.path.join(self.dataDir, 'projects')
|
filename = QtGui.QFileDialog.getOpenFileName(self.window,
|
||||||
filename = QtGui.QFileDialog.getOpenFileName(self.window, "Open Project File", inputDir)
|
"Open Project File", self.settings.value("projectDir"),
|
||||||
if not filename:
|
"Project Files (*.avp)")
|
||||||
return
|
self.openProject(filename)
|
||||||
filepath = os.path.join(inputDir, filename)
|
|
||||||
self.openProject(filepath)
|
|
||||||
|
|
||||||
def openProject(self, filepath):
|
def openProject(self, filepath):
|
||||||
|
if not filepath or not os.path.exists(filepath) or not filepath.endswith('.avp'):
|
||||||
|
return
|
||||||
self.clear()
|
self.clear()
|
||||||
self.currentProject = filepath
|
self.currentProject = filepath
|
||||||
|
self.settings.setValue("lastProject", filepath)
|
||||||
|
self.settings.setValue("projectDir", os.path.dirname(filepath))
|
||||||
compNames = [mod.Component.__doc__ for mod in self.modules]
|
compNames = [mod.Component.__doc__ for mod in self.modules]
|
||||||
with open(filepath, 'r') as f:
|
with open(filepath, 'r') as f:
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -507,19 +510,6 @@ class Main(QtCore.QObject):
|
||||||
saveValueStore = eval(line.strip())
|
saveValueStore = eval(line.strip())
|
||||||
self.selectedComponents[-1].loadPreset(saveValueStore)
|
self.selectedComponents[-1].loadPreset(saveValueStore)
|
||||||
i = 0
|
i = 0
|
||||||
projSettingsPath = os.path.join(self.dataDir, 'project-settings', '%s.ini' % os.path.basename(filepath))
|
|
||||||
backupPath = os.path.join(self.dataDir, 'settings.ini~')
|
|
||||||
settingsPath = self.settings.fileName()
|
|
||||||
if os.path.exists(backupPath):
|
|
||||||
os.remove(backupPath)
|
|
||||||
os.rename(settingsPath, backupPath)
|
|
||||||
shutil.copyfile(projSettingsPath, settingsPath)
|
|
||||||
self.settings.sync()
|
|
||||||
currentRes = str(self.settings.value('outputWidth'))+'x'+str(self.settings.value('outputHeight'))
|
|
||||||
for i in range(self.window.comboBox_resolution.count()-1):
|
|
||||||
if self.window.comboBox_resolution.itemText(i) == currentRes:
|
|
||||||
self.window.comboBox_resolution.setCurrentIndex(i)
|
|
||||||
break
|
|
||||||
|
|
||||||
def showMessage(self, string, icon=QtGui.QMessageBox.Information, showCancel=False):
|
def showMessage(self, string, icon=QtGui.QMessageBox.Information, showCancel=False):
|
||||||
msg = QtGui.QMessageBox()
|
msg = QtGui.QMessageBox()
|
||||||
|
@ -559,6 +549,7 @@ def LoadDefaultSettings(self):
|
||||||
"outputVideoFormat": "yuv420p",
|
"outputVideoFormat": "yuv420p",
|
||||||
"outputPreset": "medium",
|
"outputPreset": "medium",
|
||||||
"outputFormat": "mp4",
|
"outputFormat": "mp4",
|
||||||
|
"projectDir" : os.path.join(self.dataDir, 'projects'),
|
||||||
}
|
}
|
||||||
|
|
||||||
for parm, value in default.items():
|
for parm, value in default.items():
|
||||||
|
|
Reference in New Issue