aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortassaron2017-06-15 23:13:36 -0400
committertassaron2017-06-15 23:13:36 -0400
commitee8031925fcd93d7bedceff6e98a06f3806426b3 (patch)
tree99fd013c1c87f6bb1d2ed22859b56b0bced081bc
parentc05efc73ee069fe2eb8776a27b503ada2adb4af6 (diff)
drag events for component list now working!
-rw-r--r--core.py14
-rw-r--r--mainwindow.py34
-rw-r--r--mainwindow.ui9
-rw-r--r--presetmanager.py3
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 @@
<rect>
<x>0</x>
<y>0</y>
- <width>1008</width>
- <height>575</height>
+ <width>1028</width>
+ <height>592</height>
</rect>
</property>
<property name="sizePolicy">
@@ -175,6 +175,9 @@
<height>16777215</height>
</size>
</property>
+ <property name="acceptDrops">
+ <bool>true</bool>
+ </property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
@@ -188,7 +191,7 @@
<bool>true</bool>
</property>
<property name="dragEnabled">
- <bool>false</bool>
+ <bool>true</bool>
</property>
<property name="dragDropOverwriteMode">
<bool>false</bool>
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'''