diff options
| author | Brianna | 2017-09-02 09:49:35 -0400 |
|---|---|---|
| committer | GitHub | 2017-09-02 09:49:35 -0400 |
| commit | 22978a0635e906f8ebfa1de81cdc38fd96aad756 (patch) | |
| tree | 2dc5e033a4073d433aaa824113467032d35ca3c1 /src/gui | |
| parent | 39d6a4e5af94a8aa612a009bbe235715b84e7abc (diff) | |
| parent | 8411857030d92e448d5c64682f396e677161afbe (diff) | |
Undo feature
Diffstat (limited to '')
| -rw-r--r-- | src/gui/__init__.py | 0 | ||||
| -rw-r--r-- | src/gui/actions.py | 191 | ||||
| -rw-r--r-- | src/gui/background.png (renamed from src/background.png) | bin | 45367 -> 45367 bytes | |||
| -rw-r--r-- | src/gui/mainwindow.py (renamed from src/mainwindow.py) | 215 | ||||
| -rw-r--r-- | src/gui/mainwindow.ui (renamed from src/mainwindow.ui) | 7 | ||||
| -rw-r--r-- | src/gui/presetmanager.py (renamed from src/presetmanager.py) | 65 | ||||
| -rw-r--r-- | src/gui/presetmanager.ui (renamed from src/presetmanager.ui) | 0 | ||||
| -rw-r--r-- | src/gui/preview_thread.py (renamed from src/preview_thread.py) | 8 | ||||
| -rw-r--r-- | src/gui/preview_win.py (renamed from src/preview_win.py) | 9 |
9 files changed, 393 insertions, 102 deletions
diff --git a/src/gui/__init__.py b/src/gui/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/gui/__init__.py diff --git a/src/gui/actions.py b/src/gui/actions.py new file mode 100644 index 0000000..8e867b9 --- /dev/null +++ b/src/gui/actions.py @@ -0,0 +1,191 @@ +''' + QCommand classes for every undoable user action performed in the MainWindow +''' +from PyQt5.QtWidgets import QUndoCommand +import os +from copy import copy + +from core import Core + + +# =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~==~=~=~=~=~=~=~=~=~=~=~=~=~=~ +# COMPONENT ACTIONS +# =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~==~=~=~=~=~=~=~=~=~=~=~=~=~=~ + +class AddComponent(QUndoCommand): + def __init__(self, parent, compI, moduleI): + super().__init__( + "create new %s component" % + parent.core.modules[moduleI].Component.name + ) + self.parent = parent + self.moduleI = moduleI + self.compI = compI + self.comp = None + + def redo(self): + if self.comp is None: + self.parent.core.insertComponent( + self.compI, self.moduleI, self.parent) + else: + # inserting previously-created component + self.parent.core.insertComponent( + self.compI, self.comp, self.parent) + + def undo(self): + self.comp = self.parent.core.selectedComponents[self.compI] + self.parent._removeComponent(self.compI) + + +class RemoveComponent(QUndoCommand): + def __init__(self, parent, selectedRows): + super().__init__('remove component') + self.parent = parent + componentList = self.parent.window.listWidget_componentList + self.selectedRows = [ + componentList.row(selected) for selected in selectedRows + ] + self.components = [ + parent.core.selectedComponents[i] for i in self.selectedRows + ] + + def redo(self): + self.parent._removeComponent(self.selectedRows[0]) + + def undo(self): + componentList = self.parent.window.listWidget_componentList + for index, comp in zip(self.selectedRows, self.components): + self.parent.core.insertComponent( + index, comp, self.parent + ) + self.parent.drawPreview() + + +class MoveComponent(QUndoCommand): + def __init__(self, parent, row, newRow, tag): + super().__init__("move component %s" % tag) + self.parent = parent + self.row = row + self.newRow = newRow + self.id_ = ord(tag[0]) + + def id(self): + '''If 2 consecutive updates have same id, Qt will call mergeWith()''' + return self.id_ + + def mergeWith(self, other): + self.newRow = other.newRow + return True + + def do(self, rowa, rowb): + componentList = self.parent.window.listWidget_componentList + + page = self.parent.pages.pop(rowa) + self.parent.pages.insert(rowb, page) + + item = componentList.takeItem(rowa) + componentList.insertItem(rowb, item) + + stackedWidget = self.parent.window.stackedWidget + widget = stackedWidget.removeWidget(page) + stackedWidget.insertWidget(rowb, page) + componentList.setCurrentRow(rowb) + stackedWidget.setCurrentIndex(rowb) + self.parent.core.moveComponent(rowa, rowb) + self.parent.drawPreview(True) + + def redo(self): + self.do(self.row, self.newRow) + + def undo(self): + self.do(self.newRow, self.row) + + +# =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~==~=~=~=~=~=~=~=~=~=~=~=~=~=~ +# PRESET ACTIONS +# =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~==~=~=~=~=~=~=~=~=~=~=~=~=~=~ + +class ClearPreset(QUndoCommand): + def __init__(self, parent, compI): + super().__init__("clear preset") + self.parent = parent + self.compI = compI + self.component = self.parent.core.selectedComponents[compI] + self.store = self.component.savePreset() + self.store['preset'] = self.component.currentPreset + + def redo(self): + self.parent.core.clearPreset(self.compI) + self.parent.updateComponentTitle(self.compI, False) + + def undo(self): + self.parent.core.selectedComponents[self.compI].loadPreset(self.store) + self.parent.updateComponentTitle(self.compI, self.store) + + +class OpenPreset(QUndoCommand): + def __init__(self, parent, presetName, compI): + super().__init__("open %s preset" % presetName) + self.parent = parent + self.presetName = presetName + self.compI = compI + + comp = self.parent.core.selectedComponents[compI] + self.store = comp.savePreset() + self.store['preset'] = copy(comp.currentPreset) + + def redo(self): + self.parent._openPreset(self.presetName, self.compI) + + def undo(self): + self.parent.core.selectedComponents[self.compI].loadPreset( + self.store) + self.parent.parent.updateComponentTitle(self.compI, self.store) + + +class RenamePreset(QUndoCommand): + def __init__(self, parent, path, oldName, newName): + super().__init__('rename preset') + self.parent = parent + self.path = path + self.oldName = oldName + self.newName = newName + + def redo(self): + self.parent.renamePreset(self.path, self.oldName, self.newName) + + def undo(self): + self.parent.renamePreset(self.path, self.newName, self.oldName) + + +class DeletePreset(QUndoCommand): + def __init__(self, parent, compName, vers, presetFile): + self.parent = parent + self.preset = (compName, vers, presetFile) + self.path = os.path.join( + Core.presetDir, compName, str(vers), presetFile + ) + self.store = self.parent.core.getPreset(self.path) + self.presetName = self.store['preset'] + super().__init__('delete %s preset (%s)' % (self.presetName, compName)) + self.loadedPresets = [ + i for i, comp in enumerate(self.parent.core.selectedComponents) + if self.presetName == str(comp.currentPreset) + ] + + def redo(self): + os.remove(self.path) + for i in self.loadedPresets: + self.parent.core.clearPreset(i) + self.parent.parent.updateComponentTitle(i, False) + self.parent.findPresets() + self.parent.drawPresetList() + + def undo(self): + self.parent.createNewPreset(*self.preset, self.store) + selectedComponents = self.parent.core.selectedComponents + for i in self.loadedPresets: + selectedComponents[i].currentPreset = self.presetName + self.parent.parent.updateComponentTitle(i) + self.parent.findPresets() + self.parent.drawPresetList() diff --git a/src/background.png b/src/gui/background.png Binary files differindex fb58593..fb58593 100644 --- a/src/background.png +++ b/src/gui/background.png diff --git a/src/mainwindow.py b/src/gui/mainwindow.py index af6e190..81c5d7c 100644 --- a/src/mainwindow.py +++ b/src/gui/mainwindow.py @@ -11,18 +11,22 @@ from queue import Queue import sys import os import signal +import atexit import filecmp import time import logging from core import Core -import preview_thread -from preview_win import PreviewWindow -from presetmanager import PresetManager -from toolkit import disableWhenEncoding, disableWhenOpeningProject, checkOutput +import gui.preview_thread as preview_thread +from gui.preview_win import PreviewWindow +from gui.presetmanager import PresetManager +from gui.actions import * +from toolkit import ( + disableWhenEncoding, disableWhenOpeningProject, checkOutput, blockSignals +) -log = logging.getLogger('AVP.MainWindow') +log = logging.getLogger('AVP.Gui.MainWindow') class MainWindow(QtWidgets.QMainWindow): @@ -41,11 +45,11 @@ class MainWindow(QtWidgets.QMainWindow): def __init__(self, window, project): QtWidgets.QMainWindow.__init__(self) - self.window = window - self.core = Core() log.debug( 'Main thread id: {}'.format(int(QtCore.QThread.currentThreadId()))) - + self.window = window + self.core = Core() + Core.mode = 'GUI' # widgets of component settings self.pages = [] self.lastAutosave = time.time() @@ -60,14 +64,24 @@ class MainWindow(QtWidgets.QMainWindow): self.autosavePath = os.path.join(self.dataDir, 'autosave.avp') self.settings = Core.settings + # Register clean-up functions + signal.signal(signal.SIGINT, self.terminate) + atexit.register(self.cleanUp) + + # Create stack of undoable user actions + self.undoStack = QtWidgets.QUndoStack(self) + undoLimit = self.settings.value("pref_undoLimit") + self.undoStack.setUndoLimit(undoLimit) + + # Create Preset Manager self.presetManager = PresetManager( uic.loadUi( - os.path.join(Core.wd, 'presetmanager.ui')), self) + os.path.join(Core.wd, 'gui', 'presetmanager.ui')), self) # Create the preview window and its thread, queues, and timers log.debug('Creating preview window') self.previewWindow = PreviewWindow(self, os.path.join( - Core.wd, "background.png")) + Core.wd, 'gui', "background.png")) window.verticalLayout_previewWrapper.addWidget(self.previewWindow) log.debug('Starting preview thread') @@ -78,16 +92,58 @@ class MainWindow(QtWidgets.QMainWindow): self.previewWorker.moveToThread(self.previewThread) self.previewWorker.imageCreated.connect(self.showPreviewImage) self.previewThread.start() + self.previewThread.finished.connect( + lambda: + log.critical('PREVIEW THREAD DIED! This should never happen.') + ) - log.debug('Starting preview timer') + timeout = 500 + log.debug( + 'Preview timer set to trigger when idle for %sms' % str(timeout) + ) self.timer = QtCore.QTimer(self) self.timer.timeout.connect(self.processTask.emit) - self.timer.start(500) + self.timer.start(timeout) # Begin decorating the window and connecting events - self.window.installEventFilter(self) componentList = self.window.listWidget_componentList + style = window.pushButton_undo.style() + undoButton = window.pushButton_undo + undoButton.setIcon( + style.standardIcon(QtWidgets.QStyle.SP_FileDialogBack) + ) + undoButton.clicked.connect(self.undoStack.undo) + undoButton.setEnabled(False) + self.undoStack.cleanChanged.connect( + lambda change: undoButton.setEnabled(self.undoStack.count()) + ) + self.undoMenu = QMenu() + self.undoMenu.addAction( + self.undoStack.createUndoAction(self) + ) + self.undoMenu.addAction( + self.undoStack.createRedoAction(self) + ) + action = self.undoMenu.addAction('Show History...') + action.triggered.connect( + lambda _: self.showUndoStack() + ) + undoButton.setMenu(self.undoMenu) + + style = window.pushButton_listMoveUp.style() + window.pushButton_listMoveUp.setIcon( + style.standardIcon(QtWidgets.QStyle.SP_ArrowUp) + ) + style = window.pushButton_listMoveDown.style() + window.pushButton_listMoveDown.setIcon( + style.standardIcon(QtWidgets.QStyle.SP_ArrowDown) + ) + style = window.pushButton_removeComponent.style() + window.pushButton_removeComponent.setIcon( + style.standardIcon(QtWidgets.QStyle.SP_DialogDiscardButton) + ) + if sys.platform == 'darwin': log.debug( 'Darwin detected: showing progress label below progress bar') @@ -158,7 +214,7 @@ class MainWindow(QtWidgets.QMainWindow): for i, comp in enumerate(self.core.modules): action = self.compMenu.addAction(comp.Component.name) action.triggered.connect( - lambda _, item=i: self.core.insertComponent(0, item, self) + lambda _, item=i: self.addComponent(0, item) ) self.window.pushButton_addComponent.setMenu(self.compMenu) @@ -299,6 +355,10 @@ class MainWindow(QtWidgets.QMainWindow): QtWidgets.QShortcut("Ctrl+O", self.window, self.openOpenProjectDialog) QtWidgets.QShortcut("Ctrl+N", self.window, self.createNewProject) + QtWidgets.QShortcut("Ctrl+Z", self.window, self.undoStack.undo) + QtWidgets.QShortcut("Ctrl+Y", self.window, self.undoStack.redo) + QtWidgets.QShortcut("Ctrl+Shift+Z", self.window, self.undoStack.redo) + # Hotkeys for component list for inskey in ("Ctrl+T", QtCore.Qt.Key_Insert): QtWidgets.QShortcut( @@ -339,21 +399,41 @@ class MainWindow(QtWidgets.QMainWindow): activated=lambda: self.moveComponent('bottom') ) - # Debug Hotkeys QtWidgets.QShortcut( - "Ctrl+Alt+Shift+R", self.window, self.drawPreview + "Ctrl+Shift+F", self.window, self.showFfmpegCommand ) QtWidgets.QShortcut( - "Ctrl+Alt+Shift+F", self.window, self.showFfmpegCommand + "Ctrl+Shift+U", self.window, self.showUndoStack + ) + + if log.isEnabledFor(logging.DEBUG): + QtWidgets.QShortcut( + "Ctrl+Alt+Shift+R", self.window, self.drawPreview + ) + QtWidgets.QShortcut( + "Ctrl+Alt+Shift+A", self.window, lambda: log.debug(repr(self)) + ) + + def __repr__(self): + return ( + '\n%s\n' + '#####\n' + 'Preview thread is %s\n' % ( + repr(self.core), + 'live' if self.previewThread.isRunning() else 'dead', + ) ) - @QtCore.pyqtSlot() def cleanUp(self, *args): log.info('Ending the preview thread') self.timer.stop() self.previewThread.quit() self.previewThread.wait() + def terminate(self, *args): + self.cleanUp() + sys.exit(0) + @disableWhenOpeningProject def updateWindowTitle(self): appName = 'Audio Visualizer' @@ -366,35 +446,43 @@ class MainWindow(QtWidgets.QMainWindow): appName += '*' except AttributeError: pass - log.debug('Setting window title to %s' % appName) + log.verbose('Setting window title to %s' % appName) self.window.setWindowTitle(appName) @QtCore.pyqtSlot(int, dict) def updateComponentTitle(self, pos, presetStore=False): + ''' + Sets component title to modified or unmodified when given boolean. + If given a preset dict, compares it against the component to + determine if it is modified. + A component with no preset is always unmodified. + ''' if type(presetStore) is dict: name = presetStore['preset'] if name is None or name not in self.core.savedPresets: modified = False else: modified = (presetStore != self.core.savedPresets[name]) - else: - modified = bool(presetStore) + + modified = bool(presetStore) if pos < 0: pos = len(self.core.selectedComponents)-1 - name = str(self.core.selectedComponents[pos]) + name = self.core.selectedComponents[pos].name title = str(name) if self.core.selectedComponents[pos].currentPreset: title += ' - %s' % self.core.selectedComponents[pos].currentPreset if modified: title += '*' if type(presetStore) is bool: - log.debug('Forcing %s #%s\'s modified status to %s: %s' % ( + log.debug( + 'Forcing %s #%s\'s modified status to %s: %s', name, pos, modified, title - )) + ) else: - log.debug('Setting %s #%s\'s title: %s' % ( + log.debug( + 'Setting %s #%s\'s title: %s', name, pos, title - )) + ) self.window.listWidget_componentList.item(pos).setText(title) def updateCodecs(self): @@ -471,7 +559,7 @@ class MainWindow(QtWidgets.QMainWindow): return True except FileNotFoundError: log.error( - 'Project file couldn\'t be located:', self.currentProject) + 'Project file couldn\'t be located: %s', self.currentProject) return identical return False @@ -568,6 +656,7 @@ class MainWindow(QtWidgets.QMainWindow): detail=detail, icon='Critical', ) + log.info('%s', repr(self)) def changeEncodingStatus(self, status): self.encoding = status @@ -651,6 +740,14 @@ class MainWindow(QtWidgets.QMainWindow): def showPreviewImage(self, image): self.previewWindow.changePixmap(image) + def showUndoStack(self): + dialog = QtWidgets.QDialog(self.window) + undoView = QtWidgets.QUndoView(self.undoStack) + layout = QtWidgets.QVBoxLayout() + layout.addWidget(undoView) + dialog.setLayout(layout) + dialog.show() + def showFfmpegCommand(self): from textwrap import wrap from toolkit.ffmpeg import createFfmpegCommand @@ -664,7 +761,13 @@ class MainWindow(QtWidgets.QMainWindow): msg="Current FFmpeg command:\n\n %s" % " ".join(lines) ) + def addComponent(self, compPos, moduleIndex): + '''Creates an undoable action that adds a new component.''' + action = AddComponent(self, compPos, moduleIndex) + self.undoStack.push(action) + def insertComponent(self, index): + '''Triggered by Core to finish initializing a new component.''' componentList = self.window.listWidget_componentList stackedWidget = self.window.stackedWidget @@ -685,41 +788,38 @@ class MainWindow(QtWidgets.QMainWindow): def removeComponent(self): componentList = self.window.listWidget_componentList + selected = componentList.selectedItems() + if selected: + action = RemoveComponent(self, selected) + self.undoStack.push(action) - for selected in componentList.selectedItems(): - index = componentList.row(selected) - self.window.stackedWidget.removeWidget(self.pages[index]) - componentList.takeItem(index) - self.core.removeComponent(index) - self.pages.pop(index) - self.changeComponentWidget() + def _removeComponent(self, index): + stackedWidget = self.window.stackedWidget + componentList = self.window.listWidget_componentList + stackedWidget.removeWidget(self.pages[index]) + componentList.takeItem(index) + self.core.removeComponent(index) + self.pages.pop(index) + self.changeComponentWidget() self.drawPreview() @disableWhenEncoding def moveComponent(self, change): '''Moves a component relatively from its current position''' componentList = self.window.listWidget_componentList + tag = change if change == 'top': change = -componentList.currentRow() elif change == 'bottom': change = len(componentList)-componentList.currentRow()-1 - stackedWidget = self.window.stackedWidget + else: + tag = 'down' if change == 1 else 'up' row = componentList.currentRow() newRow = row + change if newRow > -1 and newRow < componentList.count(): - self.core.moveComponent(row, newRow) - - # update widgets - page = self.pages.pop(row) - self.pages.insert(newRow, page) - item = componentList.takeItem(row) - newItem = componentList.insertItem(newRow, item) - widget = stackedWidget.removeWidget(page) - stackedWidget.insertWidget(newRow, page) - componentList.setCurrentRow(newRow) - stackedWidget.setCurrentIndex(newRow) - self.drawPreview(True) + action = MoveComponent(self, row, newRow, tag) + self.undoStack.push(action) def getComponentListMousePos(self, position): ''' @@ -777,11 +877,11 @@ class MainWindow(QtWidgets.QMainWindow): self.window.lineEdit_audioFile, self.window.lineEdit_outputFile ): - field.blockSignals(True) - field.setText('') - field.blockSignals(False) + with blockSignals(field): + field.setText('') self.progressBarUpdated(0) self.progressBarSetText('') + self.undoStack.clear() @disableWhenEncoding def createNewProject(self, prompt=True): @@ -845,7 +945,7 @@ class MainWindow(QtWidgets.QMainWindow): def openProject(self, filepath, prompt=True): if not filepath or not os.path.exists(filepath) \ - or not filepath.endswith('.avp'): + or not filepath.endswith('.avp'): return self.clear() @@ -928,19 +1028,10 @@ class MainWindow(QtWidgets.QMainWindow): for i, comp in enumerate(self.core.modules): menuItem = self.submenu.addAction(comp.Component.name) menuItem.triggered.connect( - lambda _, item=i: self.core.insertComponent( - 0 if insertCompAtTop else index, item, self + lambda _, item=i: self.addComponent( + 0 if insertCompAtTop else index, item ) ) self.menu.move(parentPosition + QPos) self.menu.show() - - def eventFilter(self, object, event): - if event.type() == QtCore.QEvent.WindowActivate \ - or event.type() == QtCore.QEvent.FocusIn: - Core.windowHasFocus = True - elif event.type() == QtCore.QEvent.WindowDeactivate \ - or event.type() == QtCore.QEvent.FocusOut: - Core.windowHasFocus = False - return False diff --git a/src/mainwindow.ui b/src/gui/mainwindow.ui index b43d375..cd8454d 100644 --- a/src/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -111,6 +111,13 @@ <enum>QLayout::SetMinimumSize</enum> </property> <item> + <widget class="QPushButton" name="pushButton_undo"> + <property name="text"> + <string>Undo</string> + </property> + </widget> + </item> + <item> <spacer name="horizontalSpacer_6"> <property name="orientation"> <enum>Qt::Horizontal</enum> diff --git a/src/presetmanager.py b/src/gui/presetmanager.py index b1eeb34..2445760 100644 --- a/src/presetmanager.py +++ b/src/gui/presetmanager.py @@ -5,9 +5,14 @@ from PyQt5 import QtCore, QtWidgets import string import os +import logging from toolkit import badName from core import Core +from gui.actions import * + + +log = logging.getLogger('AVP.Gui.PresetManager') class PresetManager(QtWidgets.QDialog): @@ -130,8 +135,8 @@ class PresetManager(QtWidgets.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.parent.updateComponentTitle(compI, False) + action = ClearPreset(self.parent, compI) + self.parent.undoStack.push(action) def openSavePresetDialog(self): '''Functions on mainwindow level from the context menu''' @@ -196,12 +201,16 @@ class PresetManager(QtWidgets.QDialog): def openPreset(self, presetName, compPos=None): componentList = self.parent.window.listWidget_componentList - selectedComponents = self.core.selectedComponents - index = compPos if compPos is not None else componentList.currentRow() if index == -1: return - componentName = str(selectedComponents[index]).strip() + action = OpenPreset(self, presetName, index) + self.parent.undoStack.push(action) + + def _openPreset(self, presetName, index): + selectedComponents = self.core.selectedComponents + + componentName = selectedComponents[index].name.strip() version = selectedComponents[index].version dirname = os.path.join(self.presetDir, componentName, str(version)) filepath = os.path.join(dirname, presetName) @@ -224,16 +233,10 @@ class PresetManager(QtWidgets.QDialog): if not ch: return self.deletePreset(comp, vers, name) - self.findPresets() - self.drawPresetList() - - for i, comp in enumerate(self.core.selectedComponents): - if comp.currentPreset == name: - self.clearPreset(i) def deletePreset(self, comp, vers, name): - filepath = os.path.join(self.presetDir, comp, str(vers), name) - os.remove(filepath) + action = DeletePreset(self, comp, vers, name) + self.parent.undoStack.push(action) def warnMessage(self, window=None): self.parent.showMessage( @@ -270,7 +273,6 @@ class PresetManager(QtWidgets.QDialog): return index def openRenamePresetDialog(self): - # TODO: maintain consistency by changing this to call createNewPreset() presetList = self.window.listWidget_presets index = self.getPresetRow() if index == -1: @@ -293,22 +295,28 @@ class PresetManager(QtWidgets.QDialog): path = os.path.join( self.presetDir, comp, str(vers)) newPath = os.path.join(path, newName) - oldPath = os.path.join(path, oldName) if self.presetExists(newPath): return - if os.path.exists(newPath): - os.remove(newPath) - os.rename(oldPath, newPath) - self.findPresets() - self.drawPresetList() - for i, comp in enumerate(self.core.selectedComponents): - if getPresetDir(comp) == path \ - and comp.currentPreset == oldName: - self.core.openPreset(newPath, i, newName) - self.parent.updateComponentTitle(i, False) - self.parent.drawPreview() + action = RenamePreset(self, path, oldName, newName) + self.parent.undoStack.push(action) break + def renamePreset(self, path, oldName, newName): + oldPath = os.path.join(path, oldName) + newPath = os.path.join(path, newName) + if os.path.exists(newPath): + os.remove(newPath) + os.rename(oldPath, newPath) + self.findPresets() + self.drawPresetList() + path = os.path.dirname(newPath) + for i, comp in enumerate(self.core.selectedComponents): + if self.core.getPresetDir(comp) == path \ + and comp.currentPreset == oldName: + self.core.openPreset(newPath, i, newName) + self.parent.updateComponentTitle(i, False) + self.parent.drawPreview() + def openImportDialog(self): filename, _ = QtWidgets.QFileDialog.getOpenFileName( self.window, "Import Preset File", @@ -351,8 +359,3 @@ class PresetManager(QtWidgets.QDialog): def clearPresetListSelection(self): self.window.listWidget_presets.setCurrentRow(-1) - - -def getPresetDir(comp): - '''Get the preset subdir for a particular version of a component''' - return os.path.join(Core.presetDir, str(comp), str(comp.version)) diff --git a/src/presetmanager.ui b/src/gui/presetmanager.ui index 5257b1c..5257b1c 100644 --- a/src/presetmanager.ui +++ b/src/gui/presetmanager.ui diff --git a/src/preview_thread.py b/src/gui/preview_thread.py index 9615884..d3e0581 100644 --- a/src/preview_thread.py +++ b/src/gui/preview_thread.py @@ -14,7 +14,7 @@ from toolkit.frame import Checkerboard from toolkit import disableWhenOpeningProject -log = logging.getLogger("AVP.PreviewThread") +log = logging.getLogger("AVP.Gui.PreviewThread") class Worker(QtCore.QObject): @@ -45,8 +45,6 @@ class Worker(QtCore.QObject): @pyqtSlot() def process(self): - width = int(self.settings.value('outputWidth')) - height = int(self.settings.value('outputHeight')) try: nextPreviewInformation = self.queue.get(block=False) while self.queue.qsize() >= 2: @@ -54,12 +52,14 @@ class Worker(QtCore.QObject): self.queue.get(block=False) except Empty: continue + width = int(self.settings.value('outputWidth')) + height = int(self.settings.value('outputHeight')) if self.background.width != width \ or self.background.height != height: self.background = Checkerboard(width, height) frame = self.background.copy() - log.debug('Creating new preview frame') + log.info('Creating new preview frame') components = nextPreviewInformation["components"] for component in reversed(components): try: diff --git a/src/preview_win.py b/src/gui/preview_win.py index 40c19c6..3db420c 100644 --- a/src/preview_win.py +++ b/src/gui/preview_win.py @@ -1,14 +1,14 @@ from PyQt5 import QtCore, QtGui, QtWidgets import logging +log = logging.getLogger('AVP.Gui.PreviewWindow') + class PreviewWindow(QtWidgets.QLabel): ''' Paints the preview QLabel in MainWindow and maintains the aspect ratio when the window is resized. ''' - log = logging.getLogger('AVP.PreviewWindow') - def __init__(self, parent, img): super(PreviewWindow, self).__init__() self.parent = parent @@ -41,17 +41,15 @@ class PreviewWindow(QtWidgets.QLabel): if i >= 0: component = self.parent.core.selectedComponents[i] if not hasattr(component, 'previewClickEvent'): - self.log.info('Ignored click event') return pos = (event.x(), event.y()) size = (self.width(), self.height()) butt = event.button() - self.log.info('Click event for #%s: %s button %s' % ( + log.info('Click event for #%s: %s button %s' % ( i, pos, butt)) component.previewClickEvent( pos, size, butt ) - self.parent.core.updateComponent(i) @QtCore.pyqtSlot(str) def threadError(self, msg): @@ -60,3 +58,4 @@ class PreviewWindow(QtWidgets.QLabel): icon='Critical', parent=self ) + log.info('%', repr(self.parent)) |
