Exemple #1
0
def _open_file(tmpdir, data):
    """Open a file containing the bytes from data."""
    path = str(tmpdir.join("broken"))
    with open(path, "wb") as f:
        f.write(data)
    assert imghdr.what(path) is not None, "Invalid magic bytes in test setup"
    api.open_paths([path])
Exemple #2
0
def _open_file(directory, data):
    """Open a file containing the bytes from data."""
    path = directory / "broken"
    path.write_bytes(data)
    filename = str(path)
    assert imghdr.what(filename) is not None, "Invalid magic bytes in test setup"
    api.open_paths([filename])
Exemple #3
0
def init_paths(args: argparse.Namespace) -> None:
    """Open paths given from commandline or fallback to library if set."""
    _logger.debug("Opening paths")
    try:
        api.open_paths(args.paths)
    except api.commands.CommandError:
        _logger.debug("init_paths: No valid paths retrieved")
        if api.settings.startup_library.value:
            api.open_paths([os.getcwd()])
    api.status.update("startup paths initialized")
Exemple #4
0
 def _process_pipe(self) -> None:
     """Open paths from stdout."""
     _logger.debug("Opening paths from '%s'...", self.program())
     stdout = qbytearray_to_str(self.readAllStandardOutput())
     try:
         api.open_paths(path for path in stdout.split("\n") if os.path.exists(path))
         _logger.debug("... opened paths from pipe")
         api.status.update("opened paths from pipe")
     except api.commands.CommandError:
         log.warning("%s: No paths from pipe", self.program())
Exemple #5
0
def paste_name(primary: bool = True) -> None:
    """Paste path from clipboard to open command.

    **syntax:** ``:paste-name [--primary]``

    optional arguments:
        * ``--primary``: Paste from  primary selection.
    """
    clipboard = QGuiApplication.clipboard()
    mode = QClipboard.Selection if primary else QClipboard.Clipboard
    api.open_paths([clipboard.text(mode=mode)])
Exemple #6
0
def init_paths(args: argparse.Namespace) -> None:
    """Open paths given from commandline or fallback to library if set."""
    _logger.debug("Opening paths")
    read_stdin = args.stdinput and not sys.stdin.isatty()
    paths = ([os.path.realpath(line.strip())
              for line in sys.stdin] if read_stdin else args.paths)
    try:
        api.open_paths(paths)
    except api.commands.CommandError:
        _logger.debug("init_paths: No valid paths retrieved")
        if api.settings.startup_library.value:
            api.open_paths([os.getcwd()])
    api.status.update("startup paths initialized")
    def tag_open(self, name: str) -> None:
        """Open images from a tag in image mode.

        **syntax:** ``tag-open name``

        .. hint:: This is equivalent to ``:tag-load name && open %m``.

        positional arguments:
            * ``name``: Name of the tag to open.
        """
        from vimiv.api import open_paths  # Otherwise we have a circular import

        self.tag_load(name)
        open_paths(self._marked)