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