Esempio n. 1
0
    def on_line_edit_editing_finished(self):
        """
        A handler to handle when the line edit has finished being edited.

        :rtype: None
        """
        path = str_to_path(self.line_edit.text())
        self.on_new_path(path)
Esempio n. 2
0
 def test_str_to_path_type_error(self):
     """
     Test that `str_to_path` returns None if called with invalid information
     """
     # GIVEN: The `str_to_path` function
     # WHEN: Calling `str_to_path` with an invalid Type
     # THEN: None is returned
     assert str_to_path(Path()) is None
Esempio n. 3
0
    def test_str_to_path_empty_str(self):
        """
        Test that `str_to_path` correctly converts the string parameter when passed with and empty string
        """
        # GIVEN: The `str_to_path` function
        # WHEN: Calling the `str_to_path` function with None
        result = str_to_path('')

        # THEN: `path_to_str` should return None
        assert result is None
Esempio n. 4
0
    def get_file_list(self):
        """
        Return the current list of files

        :rtype: list[openlp.core.common.path.Path]
        """
        file_paths = []
        for index in range(self.list_view.count()):
            list_item = self.list_view.item(index)
            filename = list_item.data(QtCore.Qt.UserRole)
            file_paths.append(str_to_path(filename))
        return file_paths
Esempio n. 5
0
    def getExistingDirectory(cls, *args, **kwargs):
        """
        Wraps `getExistingDirectory` so that it can be called with, and return Path objects

        :type parent: QtWidgets.QWidget | None
        :type caption: str
        :type directory: pathlib.Path
        :type options: QtWidgets.QFileDialog.Options
        :rtype: pathlib.Path
        """
        args, kwargs = replace_params(args, kwargs, ((2, 'directory', path_to_str),))

        return_value = super().getExistingDirectory(*args, **kwargs)

        # getExistingDirectory returns a str that represents the path. The string is empty if the user cancels the
        # dialog.
        return str_to_path(return_value)
Esempio n. 6
0
    def getSaveFileName(cls, *args, **kwargs):
        """
        Wraps `getSaveFileName` so that it can be called with, and return Path objects

        :type parent: QtWidgets.QWidget | None
        :type caption: str
        :type directory: pathlib.Path
        :type filter: str
        :type initialFilter: str
        :type options: QtWidgets.QFileDialog.Options
        :rtype: tuple[pathlib.Path | None, str]
        """
        args, kwargs = replace_params(args, kwargs, ((2, 'directory', path_to_str),))

        file_name, selected_filter = super().getSaveFileName(*args, **kwargs)

        # getSaveFileName returns a tuple. The first item represents the path as a str. The string is empty if the user
        # cancels the dialog.
        return str_to_path(file_name), selected_filter
Esempio n. 7
0
    def getOpenFileNames(cls, *args, **kwargs):
        """
        Wraps `getOpenFileNames` so that it can be called with, and return Path objects

        :type parent: QtWidgets.QWidget | None
        :type caption: str
        :type directory: pathlib.Path
        :type filter: str
        :type initialFilter: str
        :type options: QtWidgets.QFileDialog.Options
        :rtype: tuple[list[pathlib.Path], str]
        """
        args, kwargs = replace_params(args, kwargs, ((2, 'directory', path_to_str),))

        file_names, selected_filter = super().getOpenFileNames(*args, **kwargs)

        # getSaveFileName returns a tuple. The first item is a list of str's that represents the path. The list is
        # empty if the user cancels the dialog.
        paths = [str_to_path(path) for path in file_names]
        return paths, selected_filter
Esempio n. 8
0
 def on_delete_click(self):
     """
     Remove a presentation item from the list.
     """
     if check_item_selected(self.list_view, UiStrings().SelectDelete):
         items = self.list_view.selectedIndexes()
         row_list = [item.row() for item in items]
         row_list.sort(reverse=True)
         self.application.set_busy_cursor()
         self.main_window.display_progress_bar(len(row_list))
         for item in items:
             file_path = str_to_path(item.data(QtCore.Qt.UserRole))
             self.clean_up_thumbnails(file_path)
             self.main_window.increment_progress_bar()
         self.main_window.finished_progress_bar()
         for row in row_list:
             self.list_view.takeItem(row)
         Settings().setValue(self.settings_section + '/presentations files',
                             self.get_file_list())
         self.application.set_normal_cursor()
Esempio n. 9
0
    def generate_slide_data(self,
                            service_item,
                            item=None,
                            xml_version=False,
                            remote=False,
                            context=ServiceItemContext.Service,
                            file_path=None):
        """
        Generate the slide data. Needs to be implemented by the plugin.

        :param service_item: The service item to be built on
        :param item: The Song item to be used
        :param xml_version: The xml version (not used)
        :param remote: Triggered from remote
        :param context: Why is it being generated
        """
        if item:
            items = [item]
        else:
            items = self.list_view.selectedItems()
            if len(items) > 1:
                return False
        if file_path is None:
            file_path = str_to_path(items[0].data(QtCore.Qt.UserRole))
        file_type = file_path.suffix.lower()[1:]
        if not self.display_type_combo_box.currentText():
            return False
        service_item.add_capability(ItemCapabilities.CanEditTitle)
        if file_type in PDF_CONTROLLER_FILETYPES and context != ServiceItemContext.Service:
            service_item.add_capability(ItemCapabilities.CanMaintain)
            service_item.add_capability(ItemCapabilities.CanPreview)
            service_item.add_capability(ItemCapabilities.CanLoop)
            service_item.add_capability(ItemCapabilities.CanAppend)
            service_item.name = 'images'
            # force a nonexistent theme
            service_item.theme = -1
            for bitem in items:
                if file_path is None:
                    file_path = str_to_path(bitem.data(QtCore.Qt.UserRole))
                path, file_name = file_path.parent, file_path.name
                service_item.title = file_name
                if file_path.exists():
                    processor = self.find_controller_by_type(file_path)
                    if not processor:
                        return False
                    controller = self.controllers[processor]
                    service_item.processor = None
                    doc = controller.add_document(file_path)
                    if doc.get_thumbnail_path(1, True) is None or \
                            not (doc.get_temp_folder() / 'mainslide001.png').is_file():
                        doc.load_presentation()
                    i = 1
                    image_path = doc.get_temp_folder(
                    ) / 'mainslide{number:0>3d}.png'.format(number=i)
                    thumbnail_path = doc.get_thumbnail_folder(
                    ) / 'slide{number:d}.png'.format(number=i)
                    while image_path.is_file():
                        service_item.add_from_image(
                            str(image_path),
                            file_name,
                            thumbnail=str(thumbnail_path))
                        i += 1
                        image_path = doc.get_temp_folder(
                        ) / 'mainslide{number:0>3d}.png'.format(number=i)
                        thumbnail_path = doc.get_thumbnail_folder(
                        ) / 'slide{number:d}.png'.format(number=i)
                    service_item.add_capability(ItemCapabilities.HasThumbnails)
                    doc.close_presentation()
                    return True
                else:
                    # File is no longer present
                    if not remote:
                        critical_error_message_box(
                            translate('PresentationPlugin.MediaItem',
                                      'Missing Presentation'),
                            translate(
                                'PresentationPlugin.MediaItem',
                                'The presentation {name} no longer exists.').
                            format(name=file_path))
                    return False
        else:
            service_item.processor = self.display_type_combo_box.currentText()
            service_item.add_capability(ItemCapabilities.ProvidesOwnDisplay)
            for bitem in items:
                file_path = str_to_path(bitem.data(QtCore.Qt.UserRole))
                path, file_name = file_path.parent, file_path.name
                service_item.title = file_name
                if file_path.exists():
                    if self.display_type_combo_box.itemData(
                            self.display_type_combo_box.currentIndex(
                            )) == 'automatic':
                        service_item.processor = self.find_controller_by_type(
                            file_path)
                        if not service_item.processor:
                            return False
                    controller = self.controllers[service_item.processor]
                    doc = controller.add_document(file_path)
                    if doc.get_thumbnail_path(1, True) is None:
                        doc.load_presentation()
                    i = 1
                    thumbnail_path = doc.get_thumbnail_path(i, True)
                    if thumbnail_path:
                        # Get titles and notes
                        titles, notes = doc.get_titles_and_notes()
                        service_item.add_capability(
                            ItemCapabilities.HasDisplayTitle)
                        if notes.count('') != len(notes):
                            service_item.add_capability(
                                ItemCapabilities.HasNotes)
                        service_item.add_capability(
                            ItemCapabilities.HasThumbnails)
                        while thumbnail_path:
                            # Use title and note if available
                            title = ''
                            if titles and len(titles) >= i:
                                title = titles[i - 1]
                            note = ''
                            if notes and len(notes) >= i:
                                note = notes[i - 1]
                            service_item.add_from_command(
                                str(path), file_name, str(thumbnail_path),
                                title, note)
                            i += 1
                            thumbnail_path = doc.get_thumbnail_path(i, True)
                        doc.close_presentation()
                        return True
                    else:
                        # File is no longer present
                        if not remote:
                            critical_error_message_box(
                                translate('PresentationPlugin.MediaItem',
                                          'Missing Presentation'),
                                translate(
                                    'PresentationPlugin.MediaItem',
                                    'The presentation {name} is incomplete, '
                                    'please reload.').format(name=file_path))
                        return False
                else:
                    # File is no longer present
                    if not remote:
                        critical_error_message_box(
                            translate('PresentationPlugin.MediaItem',
                                      'Missing Presentation'),
                            translate(
                                'PresentationPlugin.MediaItem',
                                'The presentation {name} no longer exists.').
                            format(name=file_path))
                    return False
Esempio n. 10
0
    def load_list(self, file_paths, target_group=None, initial_load=False):
        """
        Add presentations into the media manager. This is called both on initial load of the plugin to populate with
        existing files, and when the user adds new files via the media manager.

        :param list[openlp.core.common.path.Path] file_paths: List of file paths to add to the media manager.
        """
        file_paths = [str_to_path(filename) for filename in file_paths]
        current_paths = self.get_file_list()
        titles = [file_path.name for file_path in current_paths]
        self.application.set_busy_cursor()
        if not initial_load:
            self.main_window.display_progress_bar(len(file_paths))
        # Sort the presentations by its filename considering language specific characters.
        file_paths.sort(key=lambda file_path: get_natural_key(file_path.name))
        for file_path in file_paths:
            if not initial_load:
                self.main_window.increment_progress_bar()
            if current_paths.count(file_path) > 0:
                continue
            file_name = file_path.name
            if not file_path.exists():
                item_name = QtWidgets.QListWidgetItem(file_name)
                item_name.setIcon(UiIcons().delete)
                item_name.setData(QtCore.Qt.UserRole, path_to_str(file_path))
                item_name.setToolTip(str(file_path))
                self.list_view.addItem(item_name)
            else:
                if titles.count(file_name) > 0:
                    if not initial_load:
                        critical_error_message_box(
                            translate('PresentationPlugin.MediaItem',
                                      'File Exists'),
                            translate(
                                'PresentationPlugin.MediaItem',
                                'A presentation with that filename already exists.'
                            ))
                    continue
                controller_name = self.find_controller_by_type(file_path)
                if controller_name:
                    controller = self.controllers[controller_name]
                    doc = controller.add_document(file_path)
                    thumbnail_path = doc.get_thumbnail_folder() / 'icon.png'
                    preview_path = doc.get_thumbnail_path(1, True)
                    if not preview_path and not initial_load:
                        doc.load_presentation()
                        preview_path = doc.get_thumbnail_path(1, True)
                    doc.close_presentation()
                    if not (preview_path and preview_path.exists()):
                        icon = UiIcons().delete
                    else:
                        if validate_thumb(preview_path, thumbnail_path):
                            icon = build_icon(thumbnail_path)
                        else:
                            icon = create_thumb(preview_path, thumbnail_path)
                else:
                    if initial_load:
                        icon = UiIcons().delete
                    else:
                        critical_error_message_box(
                            UiStrings().UnsupportedFile,
                            translate(
                                'PresentationPlugin.MediaItem',
                                'This type of presentation is not supported.'))
                        continue
                item_name = QtWidgets.QListWidgetItem(file_name)
                item_name.setData(QtCore.Qt.UserRole, path_to_str(file_path))
                item_name.setIcon(icon)
                item_name.setToolTip(str(file_path))
                self.list_view.addItem(item_name)
        if not initial_load:
            self.main_window.finished_progress_bar()
        self.application.set_normal_cursor()