Ejemplo n.º 1
0
    def _add_rows(self, paths: List[str], are_directories: bool = False):
        """Generate a library row for each path and add it to the model.

        Args:
            paths: List of paths to create a library row for.
            are_directories: Whether all paths are directories.
        """
        get_size = files.get_size_directory if are_directories else files.get_size_file
        mark_prefix = api.mark.indicator + " "
        for i, path in enumerate(paths, start=self.rowCount() + 1):
            name = os.path.basename(path)
            if are_directories:
                name = utils.add_html(name + "/", "b")
            if path in api.mark.paths:
                name = mark_prefix + name
            with contextlib.suppress(
                    FileNotFoundError):  # Deleted in the meantime
                size = get_size(path)
                self.appendRow((QStandardItem(str(i)), QStandardItem(name),
                                QStandardItem(size)))
                self.paths.append(path)
Ejemplo n.º 2
0
    def _add_rows(self, paths: List[str], are_directories: bool = False):
        """Generate a library row for each path and add it to the model.

        Args:
            paths: List of paths to create a library row for.
            are_directories: Whether all paths are directories.
        """
        starting_index = self.rowCount() + 1  # Want to index from 1
        for i, path in enumerate(paths):
            name = os.path.basename(path)
            marked = path in api.mark.paths
            if are_directories:
                name = utils.add_html("b", name + "/")
            with suppress(
                    FileNotFoundError):  # Has been deleted in the meantime
                size = files.get_size(path)
                self.appendRow((
                    QStandardItem(str(starting_index + i)),
                    QStandardItem(api.mark.highlight(name, marked)),
                    QStandardItem(size),
                ))
Ejemplo n.º 3
0
 def highlighted_search_str(self, search: str) -> str:
     """Current search string wrapped in a highlight color span."""
     return utils.add_html(
         utils.wrap_style_span(f"color: {self._highlight_color}", search),
         "b", "u")
Ejemplo n.º 4
0
def _format_help(*, title: str, description: str, text: str = None) -> None:
    """Helper function to unify formatting of help texts."""
    header = add_html(title, "h3")
    text = f"{text}<br>" if text is not None else ""
    log.info("%s\n%s<br>%s", header, description, text)
Ejemplo n.º 5
0
def test_add_html():
    assert utils.add_html("b", "hello") == "<b>hello</b>"
Ejemplo n.º 6
0
def test_add_html_multiple():
    assert utils.add_html("hello", "b", "i") == "<i><b>hello</b></i>"