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(-) 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