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

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 f82ab8c was f82ab8c, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

More dialogs, drag and drop onto File Load

  • Property mode set to 100755
File size: 1.7 KB
Line 
1# global
2from PyQt4 import QtCore
3
4# UI
5from UI.TabbedFileLoadUI import DataLoadWidget
6# from UI.Test2DataExplorerUI import DataLoadWidget
7
8class DroppableDataLoadWidget(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
16        # Enable file drag-drop on treeView
17        self.setAcceptDrops(True)
18        self.communicator = guimanager.communicator()
19
20    def dragIsOK(self, event):
21        """
22        Return True if the event contain URLs
23        """
24        # Analyze mime data
25        if event.mimeData().hasUrls():
26            return True
27        else:
28            return False
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
Note: See TracBrowser for help on using the repository browser.