From acf22900256d75c469c78efbd98139e3bfab0e93 Mon Sep 17 00:00:00 2001
From: DH4
Date: Wed, 7 Jun 2017 14:32:05 -0500
Subject: Created projects and presets button. FIXME: Hookup New Project menu
item. Hookup preset manager.
---
mainwindow.ui | 147 +++++++++++++++++++++-------------------------------------
1 file changed, 54 insertions(+), 93 deletions(-)
(limited to 'mainwindow.ui')
diff --git a/mainwindow.ui b/mainwindow.ui
index c010caf..62e0632 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -108,23 +108,32 @@
QLayout::SetMinimumSize
-
-
-
- Open Project
+
+
+ Qt::Horizontal
-
+
+ QSizePolicy::Fixed
+
+
+
+ 140
+ 20
+
+
+
-
-
+
- Save Project
+ Projects
-
-
+
- Save As
+ Presets
@@ -141,53 +150,11 @@
20
- 15
+ 2
- -
-
-
-
-
-
- Add
-
-
-
- -
-
-
- Remove
-
-
-
- -
-
-
- Up
-
-
-
- -
-
-
- Down
-
-
-
-
-
-
-
- -
-
-
- 4
-
-
- 2
-
-
@@ -231,54 +198,48 @@
+ -
+
+
-
+
+
+ Add
+
+
+
+ -
+
+
+ Remove
+
+
+
+ -
+
+
+ Up
+
+
+
+ -
+
+
+ Down
+
+
+
+
+
-
-
+
+ 4
+
+
2
-
-
-
-
-
- 0
- 0
-
-
-
-
- 180
- 0
-
-
-
-
-
- Component Presets
-
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
- Save
-
-
-
- -
-
-
- Remove
-
-
-
--
cgit v1.2.3
From 6079c4fd24aecf2ecfed0528c1427a74d596993f Mon Sep 17 00:00:00 2001
From: tassaron
Date: Thu, 8 Jun 2017 09:56:57 -0400
Subject: drag'n'drop componentList, move component code to core.py
FIXME: finish implementing drag'n'drop, Down button
---
core.py | 32 ++++++++++++++++
mainwindow.py | 114 ++++++++++++++++++++++++-------------------------------
mainwindow.ui | 11 ++++--
presetmanager.py | 56 ++++++++++++++++-----------
4 files changed, 122 insertions(+), 91 deletions(-)
(limited to 'mainwindow.ui')
diff --git a/core.py b/core.py
index 7b3c69a..0fa5ec5 100644
--- a/core.py
+++ b/core.py
@@ -12,6 +12,7 @@ import atexit
import time
from collections import OrderedDict
import json
+from importlib import import_module
class Core():
@@ -26,6 +27,37 @@ class Core():
self.wd = os.path.dirname(os.path.realpath(__file__))
self.loadEncoderOptions()
+ self.modules = self.findComponents()
+ self.selectedComponents = []
+
+ def findComponents(self):
+ def findComponents():
+ srcPath = os.path.join(self.wd, 'components')
+ if os.path.exists(srcPath):
+ for f in sorted(os.listdir(srcPath)):
+ name, ext = os.path.splitext(f)
+ if name.startswith("__"):
+ continue
+ elif ext == '.py':
+ yield name
+ return [
+ import_module('components.%s' % name)
+ for name in findComponents()]
+
+ def insertComponent(self, compPos, moduleIndex):
+ self.selectedComponents.insert(
+ compPos,
+ self.modules[moduleIndex].Component())
+ return compPos #if compPos > -1 else len(self.selectedComponents)-1
+
+ def moveComponent(self, startI, endI):
+ comp = self.selectedComponents.pop(startI)
+ i = self.selectedComponents.insert(endI, comp)
+ return i
+
+ def updateComponent(self, i):
+ self.selectedComponents[i].update()
+
def loadEncoderOptions(self):
file_path = os.path.join(self.wd, 'encoder-options.json')
with open(file_path) as json_file:
diff --git a/mainwindow.py b/mainwindow.py
index 883d475..f24fc66 100644
--- a/mainwindow.py
+++ b/mainwindow.py
@@ -1,6 +1,5 @@
from os.path import expanduser
from queue import Queue
-from importlib import import_module
from collections import OrderedDict
from PyQt4 import QtCore, QtGui, uic
from PyQt4.QtCore import QSettings, Qt
@@ -54,8 +53,9 @@ class MainWindow(QtCore.QObject):
# print('main thread id: {}'.format(QtCore.QThread.currentThreadId()))
self.window = window
self.core = core.Core()
- self.pages = []
- self.selectedComponents = []
+
+ self.pages = [] # widgets of component settings
+ self.componentRows = {} # QListWidgetItems
self.lastAutosave = time.time()
# Create data directory, load/create settings
@@ -149,16 +149,16 @@ class MainWindow(QtCore.QObject):
window.verticalLayout_previewWrapper.addWidget(self.previewWindow)
# Make component buttons
- self.modules = self.findComponents()
self.compMenu = QMenu()
- for i, comp in enumerate(self.modules):
+ for i, comp in enumerate(self.core.modules):
action = self.compMenu.addAction(comp.Component.__doc__)
action.triggered[()].connect(
lambda item=i: self.insertComponent(item))
self.window.pushButton_addComponent.setMenu(self.compMenu)
- window.listWidget_componentList.clicked.connect(
+ self.window.listWidget_componentList.dropEvent = self.componentMoved
+ self.window.listWidget_componentList.clicked.connect(
lambda _: self.changeComponentWidget())
self.window.pushButton_removeComponent.clicked.connect(
@@ -183,8 +183,8 @@ class MainWindow(QtCore.QObject):
self.window.pushButton_listMoveUp.clicked.connect(
self.moveComponentUp)
- self.window.pushButton_listMoveDown.clicked.connect(
- self.moveComponentDown)
+ #self.window.pushButton_listMoveDown.clicked.connect(
+ # self.moveComponentDown)
# Configure the Projects Menu
self.projectMenu = QMenu()
@@ -323,7 +323,7 @@ class MainWindow(QtCore.QObject):
self.videoTask.emit(
self.window.lineEdit_audioFile.text(),
self.window.lineEdit_outputFile.text(),
- self.selectedComponents)
+ self.core.selectedComponents)
else:
self.showMessage(
msg="You must select an audio file and output filename.")
@@ -384,56 +384,35 @@ class MainWindow(QtCore.QObject):
self.drawPreview()
def drawPreview(self):
- self.newTask.emit(self.selectedComponents)
+ self.newTask.emit(self.core.selectedComponents)
# self.processTask.emit()
self.autosave()
def showPreviewImage(self, image):
self.previewWindow.changePixmap(image)
- def findComponents(self):
- def findComponents():
- srcPath = os.path.join(
- os.path.dirname(os.path.realpath(__file__)), 'components')
- if os.path.exists(srcPath):
- for f in sorted(os.listdir(srcPath)):
- name, ext = os.path.splitext(f)
- if name.startswith("__"):
- continue
- elif ext == '.py':
- yield name
- return [
- import_module('components.%s' % name)
- for name in findComponents()]
-
- def addComponent(self, moduleIndex):
- index = len(self.pages)
- self.selectedComponents.append(self.modules[moduleIndex].Component())
- self.window.listWidget_componentList.addItem(
- self.selectedComponents[-1].__doc__)
- self.pages.append(self.selectedComponents[-1].widget(self))
- self.window.listWidget_componentList.setCurrentRow(index)
- self.window.stackedWidget.addWidget(self.pages[-1])
+ def insertComponent(self, moduleIndex, compPos=0):
+ componentList = self.window.listWidget_componentList
+
+ index = self.core.insertComponent(
+ compPos, moduleIndex)
+ row = componentList.insertItem(
+ index,
+ self.core.selectedComponents[index].__doc__)
+ self.componentRows[index] = componentList.row(row)
+ componentList.setCurrentRow(index)
+
+ self.pages.insert(index, self.core.selectedComponents[index].widget(self))
+ self.window.stackedWidget.insertWidget(index, self.pages[index])
self.window.stackedWidget.setCurrentIndex(index)
- self.selectedComponents[-1].update()
-
- def insertComponent(self, moduleIndex):
- self.selectedComponents.insert(
- 0, self.modules[moduleIndex].Component())
- self.window.listWidget_componentList.insertItem(
- 0, self.selectedComponents[0].__doc__)
- self.pages.insert(0, self.selectedComponents[0].widget(self))
- self.window.listWidget_componentList.setCurrentRow(0)
- self.window.stackedWidget.insertWidget(0, self.pages[0])
- self.window.stackedWidget.setCurrentIndex(0)
- self.selectedComponents[0].update()
+ self.core.updateComponent(index)
def removeComponent(self):
for selected in self.window.listWidget_componentList.selectedItems():
index = self.window.listWidget_componentList.row(selected)
self.window.stackedWidget.removeWidget(self.pages[index])
self.window.listWidget_componentList.takeItem(index)
- self.selectedComponents.pop(index)
+ self.core.selectedComponents.pop(index)
self.pages.pop(index)
self.changeComponentWidget()
self.drawPreview()
@@ -447,20 +426,21 @@ class MainWindow(QtCore.QObject):
def moveComponentUp(self):
row = self.window.listWidget_componentList.currentRow()
if row > 0:
- module = self.selectedComponents[row]
- self.selectedComponents.pop(row)
- self.selectedComponents.insert(row - 1, module)
- page = self.pages[row]
- self.pages.pop(row)
+ self.core.moveComponent(row, row - 1)
+ page = self.pages.pop(row)
self.pages.insert(row - 1, page)
- item = self.window.listWidget_componentList.takeItem(row)
- self.window.listWidget_componentList.insertItem(row - 1, item)
- widget = self.window.stackedWidget.removeWidget(page)
- self.window.stackedWidget.insertWidget(row - 1, page)
- self.window.listWidget_componentList.setCurrentRow(row - 1)
- self.window.stackedWidget.setCurrentIndex(row - 1)
- self.drawPreview()
+ # update widgets
+ componentList = self.window.listWidget_componentList
+ stackedWidget = self.window.stackedWidget
+ item = componentList.takeItem(row)
+ componentList.insertItem(row - 1, item)
+ widget = stackedWidget.removeWidget(page)
+ stackedWidget.insertWidget(row - 1, page)
+ componentList.setCurrentRow(row - 1)
+ stackedWidget.setCurrentIndex(row - 1)
+ self.drawPreview()
+ '''
def moveComponentDown(self):
row = self.window.listWidget_componentList.currentRow()
if row != -1 and row < len(self.pages)+1:
@@ -477,6 +457,12 @@ class MainWindow(QtCore.QObject):
self.window.listWidget_componentList.setCurrentRow(row + 1)
self.window.stackedWidget.setCurrentIndex(row + 1)
self.drawPreview()
+ '''
+ def componentMoved(self, event):
+ widget = self.window.listWidget_componentList
+ for i in range(widget.count()):
+ pass
+ #print(widget.item(i) == self.componentRows[i])
def openPresetManager(self):
'''Preset manager for importing, exporting, renaming, deleting'''
@@ -484,7 +470,7 @@ class MainWindow(QtCore.QObject):
def createNewProject(self):
self.currentProject = None
- self.selectedComponents = []
+ self.core.selectedComponents = []
self.window.listWidget_componentList.clear()
for widget in self.pages:
self.window.stackedWidget.removeWidget(widget)
@@ -513,7 +499,7 @@ class MainWindow(QtCore.QObject):
with open(filepath, 'w') as f:
print('creating %s' % filepath)
f.write('[Components]\n')
- for comp in self.selectedComponents:
+ for comp in self.core.selectedComponents:
saveValueStore = comp.savePreset()
f.write('%s\n' % str(comp))
f.write('%s\n' % str(comp.version()))
@@ -538,7 +524,7 @@ class MainWindow(QtCore.QObject):
self.currentProject = filepath
self.settings.setValue("currentProject", 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.core.modules]
try:
with open(filepath, 'r') as f:
validSections = ('Components')
@@ -563,14 +549,14 @@ class MainWindow(QtCore.QObject):
if line and section == 'Components':
if i == 0:
compIndex = compNames.index(line)
- self.addComponent(compIndex)
+ self.insertComponent(compIndex, -1)
i += 1
elif i == 1:
# version, not used yet
i += 1
elif i == 2:
saveValueStore = dict(eval(line))
- self.selectedComponents[-1].loadPreset(
+ self.core.selectedComponents[-1].loadPreset(
saveValueStore)
i = 0
except (IndexError, ValueError, NameError, SyntaxError,
@@ -620,7 +606,7 @@ class MainWindow(QtCore.QObject):
# submenu for opening presets
index = self.window.listWidget_componentList.currentRow()
try:
- presets = self.presetManager.presets[str(self.selectedComponents[index])]
+ presets = self.presetManager.presets[str(self.core.selectedComponents[index])]
self.submenu = QtGui.QMenu("Open Preset")
self.menu.addMenu(self.submenu)
diff --git a/mainwindow.ui b/mainwindow.ui
index 62e0632..e809ee8 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -184,17 +184,20 @@
1
-
- false
+
+ true
- false
+ true
false
- QAbstractItemView::NoDragDrop
+ QAbstractItemView::InternalMove
+
+
+ Qt::MoveAction
diff --git a/presetmanager.py b/presetmanager.py
index f67dbb9..50efd8d 100644
--- a/presetmanager.py
+++ b/presetmanager.py
@@ -86,28 +86,35 @@ class PresetManager(QtGui.QDialog):
if window.listWidget_componentList.currentRow() == -1:
return
while True:
- dialog = QtGui.QInputDialog(
- QtGui.QWidget(), 'Audio Visualizer', 'New Preset Name:')
- dialog.setTextValue()
- newName, OK = dialog.getText()
- badName = False
- for letter in newName:
- if letter in string.punctuation:
- badName = True
- if badName:
- # some filesystems don't like bizarre characters
- self.parent.showMessage(msg=\
-'''Preset names must contain only letters, numbers, and spaces.''')
- continue
- if OK and newName:
- index = window.listWidget_componentList.currentRow()
- if index != -1:
- saveValueStore = \
- self.parent.selectedComponents[index].savePreset()
- componentName = str(self.parent.selectedComponents[index]).strip()
- vers = self.parent.selectedComponents[index].version()
- self.createPresetFile(
- componentName, vers, saveValueStore, newName)
+ index = window.listWidget_componentList.currentRow()
+ currentPreset = self.parent.selectedComponents[index].currentPreset
+ newName, OK = QtGui.QInputDialog.getText(
+ self.parent.window,
+ 'Audio Visualizer',
+ 'New Preset Name:',
+ QtGui.QLineEdit.Normal,
+ currentPreset
+ )
+ if OK:
+ badName = False
+ for letter in newName:
+ if letter in string.punctuation:
+ badName = True
+ if badName:
+ # some filesystems don't like bizarre characters
+ self.parent.showMessage(
+ msg='Preset names must contain only letters,'
+ 'numbers, and spaces.')
+ continue
+ if newName:
+ if index != -1:
+ saveValueStore = \
+ self.parent.selectedComponents[index].savePreset()
+ componentName = str(self.parent.selectedComponents[index]).strip()
+ vers = self.parent.selectedComponents[index].version()
+ self.createPresetFile(
+ componentName, vers, saveValueStore, newName)
+ self.parent.selectedComponents[index].currentPreset = newName
break
def createPresetFile(self, compName, vers, saveValueStore, filename):
@@ -139,6 +146,9 @@ class PresetManager(QtGui.QDialog):
for line in f:
saveValueStore = dict(eval(line.strip()))
break
- self.parent.selectedComponents[index].loadPreset(saveValueStore)
+ self.parent.selectedComponents[index].loadPreset(
+ saveValueStore,
+ presetName
+ )
self.parent.drawPreview()
--
cgit v1.2.3
From bb1e54b31eb6157ef041764cfccd60484a0e02d8 Mon Sep 17 00:00:00 2001
From: tassaron
Date: Thu, 8 Jun 2017 16:50:48 -0400
Subject: saved preset titles, code clean-ups
componentList drag'n'drop disabled for now; will work on it in another branch
---
components/color.py | 3 +-
components/image.py | 3 +-
components/original.py | 3 +-
components/text.py | 3 +-
components/video.py | 3 +-
core.py | 58 +++++++++++++-----
mainwindow.py | 159 +++++++++++++++++++++++++++++--------------------
mainwindow.ui | 2 +-
presetmanager.py | 42 +++++++------
9 files changed, 169 insertions(+), 107 deletions(-)
(limited to 'mainwindow.ui')
diff --git a/components/color.py b/components/color.py
index b13f54e..a86927b 100644
--- a/components/color.py
+++ b/components/color.py
@@ -70,7 +70,7 @@ class Component(__base__.Component):
return Image.new("RGBA", (width, height), (r, g, b, 255))
def loadPreset(self, pr, presetName=None):
- self.currentPreset = presetName
+ self.currentPreset = presetName if presetName else pr['preset']
self.page.lineEdit_color1.setText('%s,%s,%s' % pr['color1'])
self.page.lineEdit_color2.setText('%s,%s,%s' % pr['color2'])
@@ -85,6 +85,7 @@ class Component(__base__.Component):
def savePreset(self):
return {
+ 'preset': self.currentPreset,
'color1': self.color1,
'color2': self.color2,
}
diff --git a/components/image.py b/components/image.py
index 6ccddb6..441e0e1 100644
--- a/components/image.py
+++ b/components/image.py
@@ -49,11 +49,12 @@ class Component(__base__.Component):
return frame
def loadPreset(self, pr, presetName=None):
- self.currentPreset = presetName
+ self.currentPreset = presetName if presetName else pr['preset']
self.page.lineEdit_image.setText(pr['image'])
def savePreset(self):
return {
+ 'preset': self.currentPreset,
'image': self.imagePath,
}
diff --git a/components/original.py b/components/original.py
index a2059d1..7873f43 100644
--- a/components/original.py
+++ b/components/original.py
@@ -38,7 +38,7 @@ class Component(__base__.Component):
self.parent.drawPreview()
def loadPreset(self, pr, presetName=None):
- self.currentPreset = presetName
+ self.currentPreset = presetName if presetName else pr['preset']
self.page.lineEdit_visColor.setText('%s,%s,%s' % pr['visColor'])
btnStyle = "QPushButton { background-color : %s; outline: none; }" \
% QColor(*pr['visColor']).name()
@@ -47,6 +47,7 @@ class Component(__base__.Component):
def savePreset(self):
return {
+ 'preset': self.currentPreset,
'layout': self.layout,
'visColor': self.visColor,
}
diff --git a/components/text.py b/components/text.py
index 1725a41..68cffca 100644
--- a/components/text.py
+++ b/components/text.py
@@ -79,7 +79,7 @@ class Component(__base__.Component):
return x, self.yPosition
def loadPreset(self, pr, presetName=None):
- self.currentPreset = presetName
+ self.currentPreset = presetName if presetName else pr['preset']
self.page.lineEdit_title.setText(pr['title'])
font = QFont()
font.fromString(pr['titleFont'])
@@ -95,6 +95,7 @@ class Component(__base__.Component):
def savePreset(self):
return {
+ 'preset': self.currentPreset,
'title': self.title,
'titleFont': self.titleFont.toString(),
'alignment': self.alignment,
diff --git a/components/video.py b/components/video.py
index e636224..c529658 100644
--- a/components/video.py
+++ b/components/video.py
@@ -129,12 +129,13 @@ class Component(__base__.Component):
return self.video.frame(frameNo)
def loadPreset(self, pr, presetName=None):
- self.currentPreset = presetName
+ self.currentPreset = presetName if presetName else pr['preset']
self.page.lineEdit_video.setText(pr['video'])
self.page.checkBox_loop.setChecked(pr['loop'])
def savePreset(self):
return {
+ 'preset': self.currentPreset,
'video': self.videoPath,
'loop': self.loopVideo,
}
diff --git a/core.py b/core.py
index 0fa5ec5..797749d 100644
--- a/core.py
+++ b/core.py
@@ -6,29 +6,34 @@ from os.path import expanduser
import subprocess as sp
import numpy
from PIL import Image
-import tempfile
+#import tempfile
from shutil import rmtree
-import atexit
+#import atexit
import time
from collections import OrderedDict
import json
from importlib import import_module
+from PyQt4.QtGui import QDesktopServices
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.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')
self.wd = os.path.dirname(os.path.realpath(__file__))
self.loadEncoderOptions()
self.modules = self.findComponents()
self.selectedComponents = []
+ self.selectedModules = []
def findComponents(self):
def findComponents():
@@ -45,19 +50,40 @@ class Core():
for name in findComponents()]
def insertComponent(self, compPos, moduleIndex):
+ if compPos < 0:
+ compPos = len(self.selectedComponents) -1
self.selectedComponents.insert(
compPos,
- self.modules[moduleIndex].Component())
- return compPos #if compPos > -1 else len(self.selectedComponents)-1
+ self.modules[moduleIndex].Component()
+ )
+ self.selectedModules.insert(
+ compPos,
+ moduleIndex
+ )
+ return compPos
def moveComponent(self, startI, endI):
comp = self.selectedComponents.pop(startI)
- i = self.selectedComponents.insert(endI, comp)
- return i
+ self.selectedComponents.insert(endI, comp)
+ i = self.selectedModules.pop(startI)
+ self.selectedModules.insert(endI, i)
+ return endI
def updateComponent(self, i):
+ print('updating %s' % self.selectedComponents[i])
self.selectedComponents[i].update()
+ def moduleIndexFor(self, compIndex):
+ return self.selectedModules[compIndex]
+
+ def createPresetFile(self, compName, vers, saveValueStore, filename):
+ dirname = os.path.join(self.presetDir, compName, str(vers))
+ if not os.path.exists(dirname):
+ os.makedirs(dirname)
+ filepath = os.path.join(dirname, filename)
+ with open(filepath, 'w') as f:
+ f.write(Core.stringOrderedDict(saveValueStore))
+
def loadEncoderOptions(self):
file_path = os.path.join(self.wd, 'encoder-options.json')
with open(file_path) as json_file:
@@ -139,11 +165,11 @@ class Core():
return completeAudioArray
- def deleteTempDir(self):
- try:
- rmtree(self.tempDir)
- except FileNotFoundError:
- pass
+ #def deleteTempDir(self):
+ # try:
+ # rmtree(self.tempDir)
+ # except FileNotFoundError:
+ # pass
def cancel(self):
self.canceled = True
diff --git a/mainwindow.py b/mainwindow.py
index f24fc66..8812e7f 100644
--- a/mainwindow.py
+++ b/mainwindow.py
@@ -3,7 +3,7 @@ from queue import Queue
from collections import OrderedDict
from PyQt4 import QtCore, QtGui, uic
from PyQt4.QtCore import QSettings, Qt
-from PyQt4.QtGui import QDesktopServices, QMenu
+from PyQt4.QtGui import QMenu
import sys
import os
import signal
@@ -55,12 +55,11 @@ class MainWindow(QtCore.QObject):
self.core = core.Core()
self.pages = [] # widgets of component settings
- self.componentRows = {} # QListWidgetItems
+ self.componentRows = [] # (moduleIndex, QListWidgetItem) tuples
self.lastAutosave = time.time()
# Create data directory, load/create settings
- self.dataDir = QDesktopServices.storageLocation(
- QDesktopServices.DataLocation)
+ self.dataDir = self.core.dataDir
self.presetManager = PresetManager(
uic.loadUi(
os.path.join(os.path.dirname(os.path.realpath(__file__)),
@@ -73,7 +72,7 @@ class MainWindow(QtCore.QObject):
if not os.path.exists(self.dataDir):
os.makedirs(self.dataDir)
for neededDirectory in (
- self.presetManager.presetDir, self.settings.value("projectDir")):
+ self.core.presetDir, self.settings.value("projectDir")):
if not os.path.exists(neededDirectory):
os.mkdir(neededDirectory)
@@ -90,6 +89,8 @@ class MainWindow(QtCore.QObject):
self.timer.start(500)
# Begin decorating the window and connecting events
+ componentList = self.window.listWidget_componentList
+
window.toolButton_selectAudioFile.clicked.connect(
self.openInputFileDialog)
@@ -120,7 +121,7 @@ class MainWindow(QtCore.QObject):
codec = window.comboBox_videoCodec.itemText(i)
if codec == self.settings.value('outputVideoCodec'):
window.comboBox_videoCodec.setCurrentIndex(i)
- print(codec)
+ #print(codec)
for i in range(window.comboBox_audioCodec.count()):
codec = window.comboBox_audioCodec.itemText(i)
@@ -157,17 +158,17 @@ class MainWindow(QtCore.QObject):
self.window.pushButton_addComponent.setMenu(self.compMenu)
- self.window.listWidget_componentList.dropEvent = self.componentMoved
- self.window.listWidget_componentList.clicked.connect(
+ componentList.dropEvent = self.componentListChanged
+ componentList.clicked.connect(
lambda _: self.changeComponentWidget())
self.window.pushButton_removeComponent.clicked.connect(
lambda _: self.removeComponent())
- self.window.listWidget_componentList.setContextMenuPolicy(
+ componentList.setContextMenuPolicy(
QtCore.Qt.CustomContextMenu)
- self.window.listWidget_componentList.connect(
- self.window.listWidget_componentList,
+ componentList.connect(
+ componentList,
QtCore.SIGNAL("customContextMenuRequested(QPoint)"),
self.componentContextMenu)
@@ -182,9 +183,11 @@ class MainWindow(QtCore.QObject):
self.updateResolution)
self.window.pushButton_listMoveUp.clicked.connect(
- self.moveComponentUp)
- #self.window.pushButton_listMoveDown.clicked.connect(
- # self.moveComponentDown)
+ lambda: self.moveComponent(-1)
+ )
+ self.window.pushButton_listMoveDown.clicked.connect(
+ lambda: self.moveComponent(1)
+ )
# Configure the Projects Menu
self.projectMenu = QMenu()
@@ -210,8 +213,7 @@ class MainWindow(QtCore.QObject):
# Show the window and load current project
window.show()
self.currentProject = self.settings.value("currentProject")
- if self.currentProject and os.path.exists(self.autosavePath) \
- and filecmp.cmp(self.autosavePath, self.currentProject):
+ if self.autosaveExists():
# delete autosave if it's identical to the project
os.remove(self.autosavePath)
@@ -235,6 +237,14 @@ class MainWindow(QtCore.QObject):
self.previewThread.wait()
self.autosave()
+ def updateComponentTitle(self, pos):
+ if pos < 0:
+ pos = len(self.core.selectedComponents)-1
+ title = str(self.core.selectedComponents[pos])
+ if self.core.selectedComponents[pos].currentPreset:
+ title += ' - %s' % self.core.selectedComponents[pos].currentPreset
+ self.window.listWidget_componentList.item(pos).setText(title)
+
def updateCodecs(self):
containerWidget = self.window.comboBox_videoContainer
vCodecWidget = self.window.comboBox_videoCodec
@@ -270,12 +280,20 @@ class MainWindow(QtCore.QObject):
self.settings.setValue('outputAudioBitrate', currentAudioBitrate)
def autosave(self):
- if time.time() - self.lastAutosave >= 2.0:
+ if not self.currentProject:
if os.path.exists(self.autosavePath):
os.remove(self.autosavePath)
+ elif time.time() - self.lastAutosave >= 2.0:
self.createProjectFile(self.autosavePath)
self.lastAutosave = time.time()
+ def autosaveExists(self):
+ if self.currentProject and os.path.exists(self.autosavePath) \
+ and filecmp.cmp(self.autosavePath, self.currentProject):
+ return True
+ else:
+ return False
+
def openInputFileDialog(self):
inputDir = self.settings.value("inputDir", expanduser("~"))
@@ -393,88 +411,94 @@ class MainWindow(QtCore.QObject):
def insertComponent(self, moduleIndex, compPos=0):
componentList = self.window.listWidget_componentList
+ stackedWidget = self.window.stackedWidget
+ if compPos < 0:
+ compPos = componentList.count()
index = self.core.insertComponent(
compPos, moduleIndex)
row = componentList.insertItem(
index,
self.core.selectedComponents[index].__doc__)
- self.componentRows[index] = componentList.row(row)
+ self.componentRows.insert(compPos, (moduleIndex, row))
componentList.setCurrentRow(index)
self.pages.insert(index, self.core.selectedComponents[index].widget(self))
- self.window.stackedWidget.insertWidget(index, self.pages[index])
- self.window.stackedWidget.setCurrentIndex(index)
+ stackedWidget.insertWidget(index, self.pages[index])
+ stackedWidget.setCurrentIndex(index)
+
self.core.updateComponent(index)
def removeComponent(self):
- for selected in self.window.listWidget_componentList.selectedItems():
- index = self.window.listWidget_componentList.row(selected)
+ componentList = self.window.listWidget_componentList
+
+ for selected in componentList.selectedItems():
+ index = componentList.row(selected)
self.window.stackedWidget.removeWidget(self.pages[index])
- self.window.listWidget_componentList.takeItem(index)
+ componentList.takeItem(index)
+ self.componentRows.pop(index)
self.core.selectedComponents.pop(index)
self.pages.pop(index)
self.changeComponentWidget()
self.drawPreview()
- def changeComponentWidget(self):
- selected = self.window.listWidget_componentList.selectedItems()
- if selected:
- index = self.window.listWidget_componentList.row(selected[0])
- self.window.stackedWidget.setCurrentIndex(index)
+ def moveComponent(self, change):
+ '''Moves a component relatively from its current position'''
+ componentList = self.window.listWidget_componentList
+ stackedWidget = self.window.stackedWidget
- def moveComponentUp(self):
- row = self.window.listWidget_componentList.currentRow()
- if row > 0:
- self.core.moveComponent(row, row - 1)
- page = self.pages.pop(row)
- self.pages.insert(row - 1, page)
+ row = componentList.currentRow()
+ newRow = row + change
+ if newRow > -1 and newRow < componentList.count():
+ self.core.moveComponent(row, newRow)
# update widgets
- componentList = self.window.listWidget_componentList
- stackedWidget = self.window.stackedWidget
+ page = self.pages.pop(row)
+ self.pages.insert(newRow, page)
item = componentList.takeItem(row)
- componentList.insertItem(row - 1, item)
+ newItem = componentList.insertItem(newRow, item)
widget = stackedWidget.removeWidget(page)
- stackedWidget.insertWidget(row - 1, page)
- componentList.setCurrentRow(row - 1)
- stackedWidget.setCurrentIndex(row - 1)
- self.drawPreview()
- '''
- def moveComponentDown(self):
- row = self.window.listWidget_componentList.currentRow()
- if row != -1 and row < len(self.pages)+1:
- module = self.selectedComponents[row]
- self.selectedComponents.pop(row)
- self.selectedComponents.insert(row + 1, module)
- page = self.pages[row]
- self.pages.pop(row)
- self.pages.insert(row + 1, page)
- item = self.window.listWidget_componentList.takeItem(row)
- self.window.listWidget_componentList.insertItem(row + 1, item)
- widget = self.window.stackedWidget.removeWidget(page)
- self.window.stackedWidget.insertWidget(row + 1, page)
- self.window.listWidget_componentList.setCurrentRow(row + 1)
- self.window.stackedWidget.setCurrentIndex(row + 1)
+ stackedWidget.insertWidget(newRow, page)
+ componentList.setCurrentRow(newRow)
+ stackedWidget.setCurrentIndex(newRow)
+ self.componentRows.pop(row)
+ self.componentRows.insert(newRow, (self.core.moduleIndexFor(row), newItem))
self.drawPreview()
- '''
- def componentMoved(self, event):
- widget = self.window.listWidget_componentList
- for i in range(widget.count()):
- pass
- #print(widget.item(i) == self.componentRows[i])
+
+ def componentListChanged(self, *args):
+ '''Update all our tracking variables to match the widget'''
+ pass
+
+ def changeComponentWidget(self):
+ selected = self.window.listWidget_componentList.selectedItems()
+ if selected:
+ index = self.window.listWidget_componentList.row(selected[0])
+ self.window.stackedWidget.setCurrentIndex(index)
def openPresetManager(self):
'''Preset manager for importing, exporting, renaming, deleting'''
self.presetManager.show()
- def createNewProject(self):
- self.currentProject = None
+ def clear(self):
+ '''Get a blank slate'''
self.core.selectedComponents = []
self.window.listWidget_componentList.clear()
for widget in self.pages:
self.window.stackedWidget.removeWidget(widget)
self.pages = []
+
+ def createNewProject(self):
+ if self.autosaveExists():
+ ch = self.showMessage(
+ msg="You have unsaved changes in project '%s'. "
+ "Save before starting a new project?"
+ % os.path.basename(self.currentProject)[:-4],
+ showCancel=True)
+ if ch:
+ self.saveCurrentProject()
+
+ self.clear()
+ self.currentProject = None
self.settings.setValue("currentProject", None)
self.drawPreview()
@@ -496,6 +520,8 @@ class MainWindow(QtCore.QObject):
def createProjectFile(self, filepath):
if not filepath.endswith(".avp"):
filepath += '.avp'
+ if os.path.exists(filepath):
+ os.remove(filepath)
with open(filepath, 'w') as f:
print('creating %s' % filepath)
f.write('[Components]\n')
@@ -520,7 +546,7 @@ class MainWindow(QtCore.QObject):
if not filepath or not os.path.exists(filepath) \
or not filepath.endswith('.avp'):
return
- self.createNewProject()
+ self.clear()
self.currentProject = filepath
self.settings.setValue("currentProject", filepath)
self.settings.setValue("projectDir", os.path.dirname(filepath))
@@ -558,6 +584,7 @@ class MainWindow(QtCore.QObject):
saveValueStore = dict(eval(line))
self.core.selectedComponents[-1].loadPreset(
saveValueStore)
+ self.updateComponentTitle(-1)
i = 0
except (IndexError, ValueError, NameError, SyntaxError,
AttributeError, TypeError) as e:
diff --git a/mainwindow.ui b/mainwindow.ui
index e809ee8..af47cee 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -188,7 +188,7 @@
true
- true
+ false
false
diff --git a/presetmanager.py b/presetmanager.py
index 50efd8d..268754e 100644
--- a/presetmanager.py
+++ b/presetmanager.py
@@ -10,7 +10,8 @@ class PresetManager(QtGui.QDialog):
def __init__(self, window, parent):
super().__init__()
self.parent = parent
- self.presetDir = os.path.join(self.parent.dataDir, 'presets')
+ self.core = self.parent.core
+ self.presetDir = self.core.presetDir
self.window = window
self.findPresets()
self.lastFilter = '*'
@@ -83,11 +84,14 @@ class PresetManager(QtGui.QDialog):
def openSavePresetDialog(self):
window = self.parent.window
- if window.listWidget_componentList.currentRow() == -1:
+ self.selectedComponents = self.parent.core.selectedComponents
+ componentList = window.listWidget_componentList
+
+ if componentList.currentRow() == -1:
return
while True:
- index = window.listWidget_componentList.currentRow()
- currentPreset = self.parent.selectedComponents[index].currentPreset
+ index = componentList.currentRow()
+ currentPreset = self.selectedComponents[index].currentPreset
newName, OK = QtGui.QInputDialog.getText(
self.parent.window,
'Audio Visualizer',
@@ -109,35 +113,34 @@ class PresetManager(QtGui.QDialog):
if newName:
if index != -1:
saveValueStore = \
- self.parent.selectedComponents[index].savePreset()
- componentName = str(self.parent.selectedComponents[index]).strip()
- vers = self.parent.selectedComponents[index].version()
+ self.selectedComponents[index].savePreset()
+ componentName = str(self.selectedComponents[index]).strip()
+ vers = self.selectedComponents[index].version()
self.createPresetFile(
componentName, vers, saveValueStore, newName)
- self.parent.selectedComponents[index].currentPreset = newName
+ self.selectedComponents[index].currentPreset = newName
break
def createPresetFile(self, compName, vers, saveValueStore, filename):
- dirname = os.path.join(self.presetDir, compName, str(vers))
- if not os.path.exists(dirname):
- os.makedirs(dirname)
- filepath = os.path.join(dirname, filename)
- if os.path.exists(filepath):
+ path = os.path.join(self.presetDir, compName, str(vers), filename)
+ if os.path.exists(path):
ch = self.parent.showMessage(
msg="%s already exists! Overwrite it?" % filename,
showCancel=True, icon=QtGui.QMessageBox.Warning)
if not ch:
return
- with open(filepath, 'w') as f:
- f.write(core.Core.stringOrderedDict(saveValueStore))
+ self.core.createPresetFile(compName, vers, saveValueStore, filename)
self.drawPresetList()
def openPreset(self, presetName):
- index = self.parent.window.listWidget_componentList.currentRow()
+ componentList = self.parent.window.listWidget_componentList
+ selectedComponents = self.parent.core.selectedComponents
+
+ index = componentList.currentRow()
if index == -1:
return
- componentName = str(self.parent.selectedComponents[index]).strip()
- version = self.parent.selectedComponents[index].version()
+ componentName = str(selectedComponents[index]).strip()
+ 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):
@@ -146,9 +149,10 @@ class PresetManager(QtGui.QDialog):
for line in f:
saveValueStore = dict(eval(line.strip()))
break
- self.parent.selectedComponents[index].loadPreset(
+ selectedComponents[index].loadPreset(
saveValueStore,
presetName
)
+ self.parent.updateComponentTitle(index)
self.parent.drawPreview()
--
cgit v1.2.3
From ee8031925fcd93d7bedceff6e98a06f3806426b3 Mon Sep 17 00:00:00 2001
From: tassaron
Date: Thu, 15 Jun 2017 23:13:36 -0400
Subject: drag events for component list now working!
---
core.py | 14 +++++++++-----
mainwindow.py | 34 ++++++++++++++++++++++++++--------
mainwindow.ui | 9 ++++++---
presetmanager.py | 3 +--
4 files changed, 42 insertions(+), 18 deletions(-)
(limited to 'mainwindow.ui')
diff --git a/core.py b/core.py
index 3fca7bf..dcea783 100644
--- a/core.py
+++ b/core.py
@@ -68,7 +68,8 @@ class Core():
yield name
self.modules = [
import_module('components.%s' % name)
- for name in findComponents()]
+ for name in findComponents()
+ ]
self.moduleIndexes = [i for i in range(len(self.modules))]
def componentListChanged(self):
@@ -119,11 +120,14 @@ class Core():
saveValueStore = self.getPreset(filepath)
if not saveValueStore:
return False
+ try:
+ self.selectedComponents[compIndex].loadPreset(
+ saveValueStore,
+ presetName
+ )
+ except KeyError as e:
+ print('preset missing value: %s' % e)
- self.selectedComponents[compIndex].loadPreset(
- saveValueStore,
- presetName
- )
self.savedPresets[presetName] = dict(saveValueStore)
return True
diff --git a/mainwindow.py b/mainwindow.py
index f1959cb..fb9ebfd 100644
--- a/mainwindow.py
+++ b/mainwindow.py
@@ -157,7 +157,7 @@ class MainWindow(QtCore.QObject):
self.window.pushButton_addComponent.setMenu(self.compMenu)
- componentList.dropEvent = self.componentListChanged
+ componentList.dropEvent = self.dragComponent
componentList.itemSelectionChanged.connect(
self.changeComponentWidget)
@@ -479,9 +479,26 @@ class MainWindow(QtCore.QObject):
stackedWidget.setCurrentIndex(newRow)
self.drawPreview()
- def componentListChanged(self, *args):
- '''Update all our tracking variables to match the widget'''
- pass
+ def dragComponent(self, event):
+ '''Drop event for the component listwidget'''
+ componentList = self.window.listWidget_componentList
+
+ modelIndexes = [ \
+ componentList.model().index(i) \
+ for i in range(componentList.count()) \
+ ]
+ rects = [ \
+ componentList.visualRect(modelIndex) \
+ for modelIndex in modelIndexes \
+ ]
+
+ rowPos = [rect.contains(event.pos()) for rect in rects]
+ if not any(rowPos):
+ return
+
+ i = rowPos.index(True)
+ change = (componentList.currentRow() - i) * -1
+ self.moveComponent(change)
def changeComponentWidget(self):
selected = self.window.listWidget_componentList.selectedItems()
@@ -608,10 +625,11 @@ class MainWindow(QtCore.QObject):
except KeyError:
pass
- menuItem = self.menu.addAction("Clear Preset")
- menuItem.triggered.connect(
- self.presetManager.clearPreset
- )
+ if self.core.selectedComponents[index].currentPreset:
+ menuItem = self.menu.addAction("Clear Preset")
+ menuItem.triggered.connect(
+ self.presetManager.clearPreset
+ )
self.menu.move(parentPosition + QPos)
self.menu.show()
diff --git a/mainwindow.ui b/mainwindow.ui
index af47cee..e892959 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -6,8 +6,8 @@
0
0
- 1008
- 575
+ 1028
+ 592
@@ -175,6 +175,9 @@
16777215
+
+ true
+
QFrame::StyledPanel
@@ -188,7 +191,7 @@
true
- false
+ true
false
diff --git a/presetmanager.py b/presetmanager.py
index 49a6336..3b02714 100644
--- a/presetmanager.py
+++ b/presetmanager.py
@@ -111,8 +111,7 @@ class PresetManager(QtGui.QDialog):
def clearPreset(self, compI=None):
'''Functions on mainwindow level from the context menu'''
compI = self.parent.window.listWidget_componentList.currentRow()
- self.core.clearPreset(compI, self)
-
+ self.core.clearPreset(compI, self.parent)
def openSavePresetDialog(self):
'''Functions on mainwindow level from the context menu'''
--
cgit v1.2.3