Skip to main content

No project description provided

Project description

Preview

preview is a tool for "previewing" files that require a compilatoin step, like LaTeX, Markdown, and more. It works by managing a "build" step and a "view" step, so it can be used to live-preview many different types of files, and if you filetype is not already supported, it is simple to add support for it.

Usage

Install with pip

$ pip install filepreviewer

to preview a file, just pass it to the preview command

$ preview file_to_preview.md

How it works

preview uses a handler to launch a view process in the background, and then run build process when the source file is changed. For example, the just handler can use a justfile like this

PREVIEW_INPUT_FILE := ""
PREVIEW_TMPDIR:= ""

preview-build:
    pandoc {{PREVIEW_INPUT_FILE}} -o {{PREVIEW_TMPDIR}}/out.pdf

preview-view:
    zathura {{PREVIEW_TMPDIR}}/out.pdf

to preview Markdown files by compiling them to a PDF (using Pandoc) and opening then PDF with Zathura, which does automatic reload.

You can use any tool(s) you want to build and view your file. The only requirement is that view process should block. preview will launch it in the background and exit when it returns.

Examples

To preview a Gnuplot script you could use sexpect to open gnuplot and load the script.

PREVIEW_INPUT_FILE := ""
PREVIEW_TMPDIR:= ""

preview-build:
    #! /bin/bash
    if [[ -e preview-gnuplot.sock ]]
    then
      sexpect -sock preview-gnuplot.sock send 'load "{{PREVIEW_INPUT_FILE}}"' -cr
      sexpect -sock preview-gnuplot.sock expect
    fi

preview-view:
    sexpect -sock preview-gnuplot.sock spawn gnuplot
    just --justfile {{justfile()}} PREVIEW_INPUT_FILE={{PREVIEW_INPUT_FILE}} PREVIEW_TMPDIR={{PREVIEW_TMPDIR}} preview-build
    zenity --info --no-markup --text="Click 'OK' when you are done to close the preview."
    sexpect -sock preview-gnuplot.sock send 'exit' -cr
    sexpect -sock preview-gnuplot.sock wait

The use of Zenity here is required to keep the view process from returning immediatly, which would cause preview to terminate.

Handlers

Currently, Preview supports just and Make for handing the build and view steps.

Just handler

To use the just handler, create a file named justfile.<file_extension> that defines a preview-build and preview-view recipe, as well as two variables named PREVIEW_INPUT_FILE and PREVIEW_TMPDIR. Preview will pass the name of the file being previewed, and the path to a temporary directory that is created for the hander to use.

Make handler

To use the make handler, create a file named makefile.<file_extension> that defines the preview-build and preview-view targets. Preview will set two variables named PREVIEW_INPUT_FILE and PREVIEW_TMPDIR that contain the name of the file being previewed, and the path to a temporary directory that is created for the hander to use.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

filepreviewer-4.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

filepreviewer-4.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file filepreviewer-4.0.tar.gz.

File metadata

  • Download URL: filepreviewer-4.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.10.6 Linux/5.19.0-32-generic

File hashes

Hashes for filepreviewer-4.0.tar.gz
Algorithm Hash digest
SHA256 85c2afc92b387c16c3ff3d362be50bf5f41381c2c3a3db62dea0824e14af3e4d
MD5 0aca00e1df8301b161b5c864d636b186
BLAKE2b-256 4a3296e15dadab8adf702241eb81429893584ac931b0ac1afa461b03c3f89c14

See more details on using hashes here.

File details

Details for the file filepreviewer-4.0-py3-none-any.whl.

File metadata

  • Download URL: filepreviewer-4.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.10.6 Linux/5.19.0-32-generic

File hashes

Hashes for filepreviewer-4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 937c9cb4e0360e1354e172d6af11060f441e7a951a1251067af385c62a13422c
MD5 f9cb26f75633367697e2917a0787b9f9
BLAKE2b-256 a4587013e57e94079d1102c2cd9996430637424bbf7f827d5ef06d7a71cf9c7e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page