source: sasview/src/sas/qtgui/DroppableDataLoadWidget.py @ e540cd2

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since e540cd2 was e540cd2, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

Status bar, progress bar, initial treeview context menu + minor cleanup

  • Property mode set to 100755
File size: 1.9 KB
Line 
1# global
2from PyQt4 import QtCore
3
4# UI
5from UI.DataExplorerUI import DataLoadWidget
6
7class DroppableDataLoadWidget(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
15        # Enable file drag-drop on treeView
16        self.setAcceptDrops(True)
17        self.communicator = guimanager.communicator()
18        flags = QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowSystemMenuHint
19        self.setWindowFlags(flags)
20
21    def dragIsOK(self, event):
22        """
23        Return True if the event contain URLs
24        """
25        # Analyze mime data
26        return bool(event.mimeData().hasUrls() and self.currentIndex() == 0)
27
28    def dragEnterEvent(self, event):
29        """
30        Called automatically on a drag into the treeview
31        """
32        if self.dragIsOK(event):
33            event.setDropAction(QtCore.Qt.CopyAction)
34            event.accept()
35        else:
36            event.ignore()
37
38    def dragMoveEvent(self, event):
39        """
40        Called automatically when a drag is
41        moved inside the treeview
42        """
43        if self.dragIsOK(event):
44            event.accept()
45        else:
46            event.ignore()
47
48    def dropEvent(self, event):
49        """
50        Called automatically when a drop
51        is added to the treeview.
52        """
53        if self.dragIsOK(event):
54            filenames=[]
55            for url in event.mimeData().urls():
56                filenames.append(str(url.toLocalFile()))
57            self.communicator.fileReadSignal.emit(filenames)
58            event.accept()
59        else:
60            event.ignore()
61
62    def closeEvent(self, event):
63        """
64        Overwrite the close event - no close!
65        """
66        event.ignore()
Note: See TracBrowser for help on using the repository browser.