示例#1
0
    def dropEvent(self, event):
        """Add local files and web URLS with drag and drop.

        For each file, attempt to open with existing associated reader
        (if available). If no reader is associated or opening fails,
        and more than one reader is available, open dialog and ask
        user to choose among available readers. User can choose to persist
        this choice.

        Parameters
        ----------
        event : qtpy.QtCore.QEvent
            Event from the Qt context.
        """
        shift_down = QGuiApplication.keyboardModifiers() & Qt.ShiftModifier
        filenames = []
        for url in event.mimeData().urls():
            if url.isLocalFile():
                # directories get a trailing "/", Path conversion removes it
                filenames.append(str(Path(url.toLocalFile())))
            else:
                filenames.append(url.toString())

        # if trying to open as a stack, open with any available reader
        if shift_down:
            self._qt_open(filenames, stack=bool(shift_down))
            return

        for filename in filenames:
            self._qt_open([filename], stack=bool(shift_down))
示例#2
0
    def dropEvent(self, event):
        """Add local files and web URLS with drag and drop.

        For each file, attempt to open with existing associated reader
        (if available). If no reader is associated or opening fails,
        and more than one reader is available, open dialog and ask
        user to choose among available readers. User can choose to persist
        this choice.

        Parameters
        ----------
        event : qtpy.QtCore.QEvent
            Event from the Qt context.
        """
        shift_down = QGuiApplication.keyboardModifiers() & Qt.ShiftModifier
        filenames = []
        for url in event.mimeData().urls():
            if url.isLocalFile():
                filenames.append(url.toLocalFile())
            else:
                filenames.append(url.toString())

        # if trying to open as a stack, open with any available reader
        if shift_down:
            self.viewer.open(filenames, stack=bool(shift_down))
            return

        for filename in filenames:
            # get available readers for this file from all registered plugins
            readers = get_potential_readers(filename)
            if not readers:
                warnings.warn(
                    trans._(
                        'No readers found to try reading {filename}.',
                        deferred=True,
                        filename=filename,
                    )
                )
                continue

            # see whether an existing setting can be used
            _, extension = os.path.splitext(filename)
            error_message = self._try_reader_from_settings(
                readers, extension, filename
            )
            # we've successfully opened file, move to the next one
            if error_message is None:
                continue

            # there is no existing setting, or it failed, get choice from user
            readerDialog = QtReaderDialog(
                parent=self,
                pth=filename,
                extension=extension,
                error_message=error_message,
                readers=readers,
            )
            self._get_and_try_preferred_reader(
                readerDialog, readers, error_message
            )
示例#3
0
    def dropEvent(self, event):
        """Add local files and web URLS with drag and drop.

        Parameters
        ----------
        event : qtpy.QtCore.QEvent
            Event from the Qt context.
        """
        shift_down = QGuiApplication.keyboardModifiers() & Qt.ShiftModifier
        filenames = []
        for url in event.mimeData().urls():
            if url.isLocalFile():
                filenames.append(url.toLocalFile())
            else:
                filenames.append(url.toString())
        self.viewer.open(filenames, stack=bool(shift_down))