1 | # global |
---|
2 | from PyQt5 import QtCore |
---|
3 | from PyQt5 import QtGui |
---|
4 | from PyQt5 import QtWidgets |
---|
5 | |
---|
6 | # UI |
---|
7 | from sas.qtgui.UI import main_resources_rc |
---|
8 | from sas.qtgui.MainWindow.UI.DataExplorerUI import Ui_DataLoadWidget |
---|
9 | |
---|
10 | class DroppableDataLoadWidget(QtWidgets.QTabWidget, Ui_DataLoadWidget): |
---|
11 | """ |
---|
12 | Overwrite drag and drop methods in the base class |
---|
13 | so users can drop files directly onto the Data Explorer |
---|
14 | """ |
---|
15 | def __init__(self, parent=None, guimanager=None): |
---|
16 | super(DroppableDataLoadWidget, self).__init__(parent) |
---|
17 | self.setupUi(self) |
---|
18 | |
---|
19 | # Enable file drag-drop on treeView |
---|
20 | self.setAcceptDrops(True) |
---|
21 | self.communicator = guimanager.communicator() |
---|
22 | flags = QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowSystemMenuHint |
---|
23 | self.setWindowFlags(flags) |
---|
24 | |
---|
25 | def dragIsOK(self, event): |
---|
26 | """ |
---|
27 | Return True if the event contain URLs |
---|
28 | """ |
---|
29 | # Analyze mime data |
---|
30 | return bool(event.mimeData().hasUrls() and self.currentIndex() == 0) |
---|
31 | |
---|
32 | def dragEnterEvent(self, event): |
---|
33 | """ |
---|
34 | Called automatically on a drag into the treeview |
---|
35 | """ |
---|
36 | if self.dragIsOK(event): |
---|
37 | event.setDropAction(QtCore.Qt.CopyAction) |
---|
38 | event.accept() |
---|
39 | else: |
---|
40 | event.ignore() |
---|
41 | |
---|
42 | def dragMoveEvent(self, event): |
---|
43 | """ |
---|
44 | Called automatically when a drag is |
---|
45 | moved inside the treeview |
---|
46 | """ |
---|
47 | if self.dragIsOK(event): |
---|
48 | event.accept() |
---|
49 | else: |
---|
50 | event.ignore() |
---|
51 | |
---|
52 | def dropEvent(self, event): |
---|
53 | """ |
---|
54 | Called automatically when a drop |
---|
55 | is added to the treeview. |
---|
56 | """ |
---|
57 | if self.dragIsOK(event): |
---|
58 | filenames=[] |
---|
59 | for url in event.mimeData().urls(): |
---|
60 | filenames.append(str(url.toLocalFile())) |
---|
61 | self.communicator.fileReadSignal.emit(filenames) |
---|
62 | event.accept() |
---|
63 | else: |
---|
64 | event.ignore() |
---|
65 | |
---|
66 | def closeEvent(self, event): |
---|
67 | """ |
---|
68 | Overwrite the close event - no close! |
---|
69 | """ |
---|
70 | event.ignore() |
---|