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

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

Converted unit tests

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[f82ab8c]1# global
[4992ff2]2from PyQt5 import QtCore
3from PyQt5 import QtGui
4from PyQt5 import QtWidgets
[f82ab8c]5
6# UI
[cd2cc745]7from sas.qtgui.UI import main_resources_rc
[83eb5208]8from sas.qtgui.MainWindow.UI.DataExplorerUI import Ui_DataLoadWidget
[f82ab8c]9
[4992ff2]10class DroppableDataLoadWidget(QtWidgets.QTabWidget, Ui_DataLoadWidget):
[f82ab8c]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)
[f51ed67]17        self.setupUi(self)
[f82ab8c]18
19        # Enable file drag-drop on treeView
20        self.setAcceptDrops(True)
21        self.communicator = guimanager.communicator()
[e540cd2]22        flags = QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowSystemMenuHint
23        self.setWindowFlags(flags)
[f82ab8c]24
25    def dragIsOK(self, event):
26        """
27        Return True if the event contain URLs
28        """
29        # Analyze mime data
[e540cd2]30        return bool(event.mimeData().hasUrls() and self.currentIndex() == 0)
[f82ab8c]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():
[53c771e]60                filenames.append(url.toLocalFile())
[f82ab8c]61            self.communicator.fileReadSignal.emit(filenames)
62            event.accept()
63        else:
64            event.ignore()
65
[e540cd2]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.