Example #1
0
def _wildcard_help() -> None:
    """Display information on various wildcards and their usage."""

    description = (
        "Symbols used to refer to paths or path-lists within vimiv. "
        "These work in addition to the standard unix-shell wildcards * and ?.")
    table = format_html_table((wildcard.wildcard, wildcard.description)
                              for wildcard in wildcards.INTERNAL)
    _format_help(title="wildcards", description=description, text=table)
Example #2
0
def _setting_help(setting: api.settings.Setting) -> None:
    """Display information on this setting."""
    suggestions = ", ".join(setting.suggestions())
    content = [
        ("type", str(setting)),
        ("default", setting.default),
    ]
    if suggestions:
        content.append(("suggestions", suggestions))
    table = format_html_table(content)
    _format_help(title=setting.name, description=setting.desc, text=table)
def test_format_html_table(n_rows):
    # Format by hand
    iterable = list(range(n_rows))
    row = "<tr><td>{num}</td><td style='padding-left: 2ex'>{numsq}</td></tr>"
    text = "\n".join(row.format(num=num, numsq=num ** 2) for num in iterable)
    expected = "<table>" + text + "</table>"
    # Format using function
    content = [(f"{num:d}", f"{num**2:d}") for num in iterable]
    result = utils.format_html_table(content)
    # Ensure equal
    assert result == expected
Example #4
0
 def _update_text(self):
     """Update the metadata text if the current image has not been loaded."""
     if self._current_set == api.settings.metadata.current_keyset.value:
         return
     _logger.debug("%s: reading exif of %s",
                   self.__class__.__qualname__, self._path)
     exif_information = exif.ExifInformation(self._path)
     if exif_information:
         self.setText(utils.format_html_table(exif_information.items()))
     else:
         self.setText("No matching metadata found")
     self._update_geometry()
     self._current_set = api.settings.metadata.current_keyset.value
Example #5
0
 def _update_text(self):
     """Update the metadata text if the current image has not been loaded."""
     if self._current_set == api.settings.metadata.current_keyset.value:
         return
     _logger.debug("%s: reading exif of %s",
                   self.__class__.__qualname__, self._path)
     keys = [
         e.strip()
         for e in api.settings.metadata.current_keyset.value.split(",")
     ]
     _logger.debug(f"Read metadata.current_keys {keys}")
     formatted_exif = self.handler.get_formatted_exif(keys)
     if formatted_exif:
         self.setText(utils.format_html_table(formatted_exif.values()))
     else:
         self.setText("No matching metadata found")
     self._update_geometry()
     self._current_set = api.settings.metadata.current_keyset.value
Example #6
0
        def metadata_list_keys(self, n_cols: int = 3, to_term: bool = False):
            """Display a list of all valid metadata keys for the current image.

            **syntax:** ``:metadata-list-keys [--n-cols=NUMBER] [--to-term]``

            optional arguments:
                * ``--n-cols``: Number of columns used to display the keys.
                * ``--to-term``: Print the keys to the terminal instead.
            """

            keys = sorted(set(self.handler.get_keys()))
            if to_term:
                print(*keys, sep="\n")
            elif n_cols < 1:
                raise api.commands.CommandError(
                    "Number of columns must be positive")
            else:
                columns = list(utils.split(keys, n_cols))
                table = utils.format_html_table(
                    itertools.zip_longest(*columns, fillvalue=""))
                self.setText(table)
                self._update_geometry()
                self.show()
 def bindings_table(cls):
     """Return a formatted html table with the valid keybindings."""
     return utils.format_html_table(
         (f"<b>{utils.escape_html(binding)}</b>", command)
         for binding, command in cls.BINDINGS
     )