drag events for component list now working!

This commit is contained in:
tassaron 2017-06-15 23:13:36 -04:00
parent c05efc73ee
commit ee8031925f
4 changed files with 42 additions and 18 deletions

14
core.py
View File

@ -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

View File

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

View File

@ -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>

View File

@ -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'''