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