source: sasview/src/sas/qtgui/MainWindow/DroppableDataLoadWidget.py @ d1a4793

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

Workaround for the resource file requirement in each UI directory

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