diff options
| author | Brianna | 2017-05-28 23:00:48 -0400 |
|---|---|---|
| committer | GitHub | 2017-05-28 23:00:48 -0400 |
| commit | 025bc2c2e6041f402b132560585b14aeed041757 (patch) | |
| tree | 14c61c69dad54b9aeffc4f6a78ade0d3191c4b2e | |
| parent | 6433f6d5804fa5021a4187f59905089b2c20bbb6 (diff) | |
| parent | db7acbf3ea353d6c5b21de44b4f532b43339ac5c (diff) | |
Merge pull request #2 from IamDH4/feature-newgui-presets
basic start to implementing presets
| -rw-r--r-- | components/original.py | 6 | ||||
| -rw-r--r-- | components/text.py | 6 | ||||
| -rw-r--r-- | main.py | 63 | ||||
| -rw-r--r-- | mainwindow.ui | 10 |
4 files changed, 72 insertions, 13 deletions
diff --git a/components/original.py b/components/original.py index e901c21..e543dac 100644 --- a/components/original.py +++ b/components/original.py @@ -34,6 +34,12 @@ class Component: self.visColor = RGBFromString(self.page.lineEdit_visColor.text()) self.parent.drawPreview() + def version(self): + return 1 + + def savePreset(self): + return {} + def previewRender(self, previewWorker): spectrum = numpy.fromfunction(lambda x: 0.008*(x-128)**2, (255,), dtype="int16") width = int(previewWorker.core.settings.value('outputWidth')) diff --git a/components/text.py b/components/text.py index eab33b2..334fc80 100644 --- a/components/text.py +++ b/components/text.py @@ -55,6 +55,9 @@ class Component: self.page = page return page + def version(self): + return 1 + def update(self): self.title = self.page.lineEdit_title.text() self.alignment = self.page.comboBox_textAlign.currentIndex() @@ -73,6 +76,9 @@ class Component: self.parent.drawPreview() + def savePreset(self): + return {} + def previewRender(self, previewWorker): width = int(previewWorker.core.settings.value('outputWidth')) height = int(previewWorker.core.settings.value('outputHeight')) @@ -1,11 +1,12 @@ import sys, io, os -from PyQt4 import QtCore, QtGui, uic from os.path import expanduser import atexit from queue import Queue -from PyQt4.QtCore import QSettings, QModelIndex import signal from importlib import import_module +from PyQt4 import QtCore, QtGui, uic +from PyQt4.QtCore import QSettings, QModelIndex +from PyQt4.QtGui import QDesktopServices import preview_thread, core, video_thread @@ -123,6 +124,14 @@ class Main(QtCore.QObject): self.settings = QSettings('settings.ini', QSettings.IniFormat) LoadDefaultSettings(self) + # create data directory structure if needed + self.dataDir = QDesktopServices.storageLocation(QDesktopServices.DataLocation) + if not os.path.exists(self.dataDir): + os.makedirs(self.dataDir) + for neededDirectory in ('projects', 'presets'): + if not os.path.exists(os.path.join(self.dataDir, neededDirectory)): + os.mkdir(os.path.join(self.dataDir, neededDirectory)) + self.pages = [] self.previewQueue = Queue() @@ -169,13 +178,11 @@ class Main(QtCore.QObject): self.window.pushButton_listMoveUp.clicked.connect(self.moveComponentUp) self.window.pushButton_listMoveDown.clicked.connect(self.moveComponentDown) - ''' - window.lineEdit_visColor.setText('%s,%s,%s' % self.visColor) - window.pushButton_visColor.clicked.connect(lambda: self.pickColor('vis')) - btnStyle = "QPushButton { background-color : %s; outline: none; }" % QColor(*self.visColor).name() - window.pushButton_visColor.setStyleSheet(btnStyle) - window.lineEdit_visColor.textChanged.connect(self.drawPreview) - ''' + self.window.pushButton_savePreset.clicked.connect(self.openSavePresetDialog) + self.window.comboBox_openPreset.currentIndexChanged.connect( \ + lambda _: self.openPreset(self.window.comboBox_openPreset.currentIndex()) + ) + self.drawPreview() window.show() @@ -297,6 +304,7 @@ class Main(QtCore.QObject): self.window.stackedWidget.addWidget(self.pages[-1]) self.window.stackedWidget.setCurrentIndex(index) self.selectedComponents[-1].update() + self.updateOpenPresetComboBox(self.selectedComponents[-1]) def removeComponent(self): for selected in self.window.listWidget_componentList.selectedItems(): @@ -311,6 +319,7 @@ class Main(QtCore.QObject): selected = self.window.listWidget_componentList.selectedItems() index = self.window.listWidget_componentList.row(selected[0]) self.window.stackedWidget.setCurrentIndex(index) + self.updateOpenPresetComboBox(self.selectedComponents[index]) def moveComponentUp(self): row = self.window.listWidget_componentList.currentRow() @@ -344,6 +353,40 @@ class Main(QtCore.QObject): self.window.listWidget_componentList.setCurrentRow(row + 1) self.window.stackedWidget.setCurrentIndex(row + 1) + def updateOpenPresetComboBox(self, component): + self.window.comboBox_openPreset.clear() + self.window.comboBox_openPreset.addItem("Open Preset") + destination = os.path.join(self.dataDir, 'presets', + str(component).strip(), str(component.version())) + if not os.path.exists(destination): + os.makedirs(destination) + for f in os.listdir(destination): + self.window.comboBox_openPreset.addItem(f) + + def openSavePresetDialog(self): + if self.window.listWidget_componentList.currentRow() == -1: + return + newName, OK = QtGui.QInputDialog.getText(QtGui.QWidget(), 'Audio Visualizer', 'New Preset Name:') + if OK and newName: + index = self.window.listWidget_componentList.currentRow() + if index != -1: + saveValueStore = self.selectedComponents[index].savePreset() + componentName = str(self.selectedComponents[index]).strip() + vers = self.selectedComponents[index].version() + self.createPresetFile(componentName, vers, saveValueStore, newName) + + def createPresetFile(self, componentName, version, saveValueStore, filename): + dirname = os.path.join(self.dataDir, 'presets', componentName, str(version)) + if not os.path.exists(dirname): + os.makedirs(dirname) + with open(os.path.join(dirname, filename), 'w') as f: + for itemset in saveValueStore.items(): + f.write('%s=%s' % itemset) + self.window.comboBox_openPreset.addItem(filename) + + def openPreset(self, comboBoxIndex): + pass + def LoadDefaultSettings(self): self.resolutions = [ @@ -382,6 +425,8 @@ else: # gui mode if __name__ == "__main__": app = QtGui.QApplication(sys.argv) + app.setApplicationName("audio-visualizer") + app.setOrganizationName("audio-visualizer") window = uic.loadUi("mainwindow.ui") # window.adjustSize() desc = QtGui.QDesktopWidget() diff --git a/mainwindow.ui b/mainwindow.ui index b15cc8e..0dcce91 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -217,10 +217,12 @@ <item> <layout class="QHBoxLayout" name="horizontalLayout_15"> <item> - <widget class="QPushButton" name="pushButton_openPreset"> - <property name="text"> - <string>Open Preset</string> - </property> + <widget class="QComboBox" name="comboBox_openPreset"> + <item> + <property name="text"> + <string>Open Preset</string> + </property> + </item> </widget> </item> <item> |
