-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotTreeWidget.py
73 lines (57 loc) · 2.53 KB
/
PlotTreeWidget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from PySide6.QtWidgets import QTreeWidget, QTreeWidgetItem, QAbstractItemView
from PySide6.QtCore import QRect, Signal, QMimeData, QByteArray
from PySide6.QtGui import QDrag
from PlotTreeItems import TabItem, SubTabItem, PlotItem, PlottableItem
from PlotModifiers import PlotModifier
import ctypes
import copy
import pickle
class PlotTreeWidget(QTreeWidget):
dropSignal = Signal()
def __init__(self, DataViewer):
super().__init__(parent=DataViewer)
self.setGeometry(QRect(10, 332, 391, 312))
self.setDragEnabled(True)
self.setAcceptDrops(True)
self.setDropIndicatorShown(True)
self.setColumnCount(1)
self.setHeaderLabels(["Plot Names"])
def startDrag(self, supportedActions):
item = self.currentItem()
if item:
if isinstance(item, PlotModifier):
drag = QDrag(self)
mimeData = QMimeData()
mimeData.setData('Modifier', QByteArray(str(id(item))))
drag.setMimeData(mimeData)
drag.exec(supportedActions)
def dragEnterEvent(self, event):
event.acceptProposedAction()
def dragMoveEvent(self, event):
event.acceptProposedAction()
def dropEvent(self, event):
if event.mimeData().data('ID'):
data_id = event.mimeData().data('ID').data()
data_type = event.mimeData().data('Type').data()
targetItem = self.itemAt(event.position().toPoint())
if isinstance(targetItem.data(0, 1), PlotItem):
new_plottable = PlottableItem(targetItem, [str(data_id.decode('utf-8'))],
int(data_id), int(data_type))
elif isinstance(targetItem.data(0, 1), PlottableItem):
# as soon as slots for adjusting are there, the slots can be filled in here
pass
self.dropSignal.emit()
event.acceptProposedAction()
elif event.mimeData().data('Modifier'):
data_address = int(event.mimeData().data('Modifier').data())
data = ctypes.cast(data_address, ctypes.py_object).value
clone = data.clone()
targetItem = self.itemAt(event.position().toPoint())
if isinstance(targetItem.data(0, 1), PlottableItem):
targetItem.addChild(clone)
elif isinstance(targetItem.data(0, 1), PlotItem):
targetItem.addChild(clone)
self.dropSignal.emit()
event.acceptProposedAction()
else:
event.ignore()