[f82ab8c] | 1 | # global |
---|
[4992ff2] | 2 | from PyQt5 import QtCore |
---|
| 3 | from PyQt5 import QtGui |
---|
| 4 | from PyQt5 import QtWidgets |
---|
[f82ab8c] | 5 | |
---|
| 6 | # UI |
---|
[cd2cc745] | 7 | from sas.qtgui.UI import main_resources_rc |
---|
[83eb5208] | 8 | from sas.qtgui.MainWindow.UI.DataExplorerUI import Ui_DataLoadWidget |
---|
[f82ab8c] | 9 | |
---|
[4992ff2] | 10 | class DroppableDataLoadWidget(QtWidgets.QTabWidget, Ui_DataLoadWidget): |
---|
[f82ab8c] | 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) |
---|
[f51ed67] | 17 | self.setupUi(self) |
---|
[f82ab8c] | 18 | |
---|
| 19 | # Enable file drag-drop on treeView |
---|
| 20 | self.setAcceptDrops(True) |
---|
| 21 | self.communicator = guimanager.communicator() |
---|
[e540cd2] | 22 | flags = QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowSystemMenuHint |
---|
| 23 | self.setWindowFlags(flags) |
---|
[f82ab8c] | 24 | |
---|
| 25 | def dragIsOK(self, event): |
---|
| 26 | """ |
---|
| 27 | Return True if the event contain URLs |
---|
| 28 | """ |
---|
| 29 | # Analyze mime data |
---|
[e540cd2] | 30 | return bool(event.mimeData().hasUrls() and self.currentIndex() == 0) |
---|
[f82ab8c] | 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(): |
---|
[53c771e] | 60 | filenames.append(url.toLocalFile()) |
---|
[f82ab8c] | 61 | self.communicator.fileReadSignal.emit(filenames) |
---|
| 62 | event.accept() |
---|
| 63 | else: |
---|
| 64 | event.ignore() |
---|
| 65 | |
---|
[e540cd2] | 66 | def closeEvent(self, event): |
---|
| 67 | """ |
---|
| 68 | Overwrite the close event - no close! |
---|
| 69 | """ |
---|
| 70 | event.ignore() |
---|