source: sasview/src/sas/qtgui/DroppableDataLoadWidget.py @ 15fd91b

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

Clean up and automate generation of UI and resources

  • Property mode set to 100755
File size: 1.9 KB
Line 
1# global
2from PyQt4 import QtGui, QtCore
3
4# UI
5from UI.DataExplorerUI import Ui_DataLoadWidget
6
7class 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()
Note: See TracBrowser for help on using the repository browser.