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

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 53c771e was 53c771e, checked in by Piotr Rozyczko <rozyczko@…>, 20 months ago

Converted unit tests

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