def renameImage(self) -> None:
        '''Rename the image'''

        name = pathlib.Path(self.image.path).name
        new_name, ok = QtWidgets.QInputDialog.getText(
            self,
            'New name',
            'Input a new name of the image:',
            text=name,
        )
        if ok:
            try:
                self.image.rename(new_name)

            except FileExistsError:
                err_msg = f'File with the name "{new_name}" already exists'
                logger.exception(err_msg)
                errornotifier.errorMessage([err_msg])

            except FileNotFoundError:
                err_msg = f'File with the name "{name}" does not exist'
                logger.exception(err_msg)
                errornotifier.errorMessage([err_msg])

            else:
                self.imagePathLabel.setText(self.image.path)
    def _callOnSelected(self, func: Callable[..., None], *args,
                        **kwargs) -> None:
        for group_w in self.widgets:
            func(group_w, *args, **kwargs)

        errornotifier.errorMessage(self._errors)
        self._errors.clear()
예제 #3
0
    def test_QMessageBox_exec_called_if_errors(self):
        errors = ['Error']
        with mock.patch('PyQt5.QtWidgets.QMessageBox',
                        return_value=self.mock_msgBox):
            errorMessage(errors)

        self.mock_msgBox.exec.assert_called_once_with()
예제 #4
0
    def _openLicensesDir() -> None:
        license_file = resources.License.LICENSE.get() # pylint:disable=no-member
        license_dir = pathlib.Path(license_file).parent

        try:
            utils.openFile(license_dir)

        except subprocess.CalledProcessError:
            err_msg = f"Something went wrong while opening '{license_dir}'"
            logger.exception(err_msg)
            # Crazy hack: on Windows, for some reason, 'explorer's exit code
            # is 1, even though the directory is opened in the file manager, so
            # we do not show the error message to the user
            if not sys.platform.startswith('win32'):
                errornotifier.errorMessage([err_msg])
    def openImage(self) -> None:
        '''Open the image in the OS default image viewer'''

        path = self.image.path

        try:
            utils.openFile(path)

        except subprocess.CalledProcessError:
            err_msg = f"Something went wrong while opening '{path}'"
            logger.exception(err_msg)
            # Crazy hack: on Windows, for some reason, 'explorer's exit code
            # is 1, even though the image is opened in the image viewer, so
            # we do not show the error message to the user
            if not sys.platform.startswith('win32'):
                errornotifier.errorMessage([err_msg])
예제 #6
0
    def _setImageViewWidget(self) -> None:
        self.imageViewWidget = imageviewwidget.ImageViewWidget(
            self.preferencesWindow.conf, self)

        self.imageViewWidget.finished.connect(self.processProg.setMaxValue)
        self.imageViewWidget.finished.connect(self.stopBtn.disable)
        self.imageViewWidget.finished.connect(self.startBtn.finished)
        self.imageViewWidget.finished.connect(lambda: (
            self.autoSelectBtn.enable()
            if self.imageViewWidget.widgets else self.autoSelectBtn.disable()))
        self.imageViewWidget.finished.connect(lambda: (
            self.menubar.enableAutoSelectAction() if self.imageViewWidget.
            widgets else self.menubar.disableAutoSelectAction()))
        self.imageViewWidget.finished.connect(
            lambda: errornotifier.errorMessage(self._errors))

        self.imageViewWidget.error.connect(self._errors.append)

        self.imageViewWidget.selected.connect(self.moveBtn.setEnabled)
        self.imageViewWidget.selected.connect(self.deleteBtn.setEnabled)
        self.imageViewWidget.selected.connect(self.unselectBtn.setEnabled)
        self.imageViewWidget.selected.connect(self.moveAction.setEnabled)
        self.imageViewWidget.selected.connect(self.deleteAction.setEnabled)
        self.imageViewWidget.selected.connect(self.unselectAction.setEnabled)

        self.scrollArea.setWidget(self.imageViewWidget)
예제 #7
0
    def _startProcessing(self):
        conf = self.preferencesWindow.conf
        p = workers.ImageProcessing(self.pathsList.paths(), conf)

        p.images_loaded.connect(self.loadedPicLbl.updateNumber)
        p.found_in_cache.connect(self.foundInCacheLbl.updateNumber)
        p.hashes_calculated.connect(self.calculatedLbl.updateNumber)
        p.duplicates_found.connect(self.duplicatesLbl.updateNumber)
        p.groups_found.connect(self.groupsLbl.updateNumber)

        p.update_progressbar.connect(self.processProg.setValue)
        p.image_group.connect(self.imageViewWidget.addGroup,
                              QtCore.Qt.BlockingQueuedConnection)
        p.error.connect(self._errors.append)
        p.interrupted.connect(self.startBtn.finished)
        p.interrupted.connect(self.stopBtn.disable)
        p.interrupted.connect(lambda: errornotifier.errorMessage(self._errors))

        self.imageViewWidget.interrupted.connect(p.interrupt)
        self.stopBtn.clicked.connect(p.interrupt)

        worker = workers.Worker(p.run)
        self.threadpool.start(worker)
예제 #8
0
    def test_QMessageBox_exec_not_called_if_no_errors(self):
        with mock.patch('PyQt5.QtWidgets.QMessageBox',
                        return_value=self.mock_msgBox):
            errorMessage([])

        self.mock_msgBox.exec.assert_not_called()