nexusLIMS.extractors.plugins.preview_generators.text_preview#

Text file preview generator.

Module Contents#

Classes#

TextPreviewGenerator

Preview generator for text files.

Functions#

text_to_thumbnail

Generate a preview thumbnail from a text file.

API#

nexusLIMS.extractors.plugins.preview_generators.text_preview.text_to_thumbnail(f: Path, out_path: Path, output_size: int = 500) Union[Figure, bool][source]#

Generate a preview thumbnail from a text file.

For a text file, the contents will be formatted and written to a 500x500 pixel jpg image of size 5 in by 5 in.

If the text file has many newlines, it is probably data and the first 42 characters of each of the first 20 lines of the text file will be written to the image.

If the text file has a few (or fewer) newlines, it is probably a manually generated note and the text will be written to a 42 column, 18 row box until the space is exhausted.

Parameters:
  • f – The path of a text file for which a thumbnail should be generated.

  • out_path – A path to the desired thumbnail filename. All formats supported by savefig() can be used.

  • output_size (int) – The pixel width (and height, since the image is padded to square) of the saved image file.

Returns:

f – Handle to a matplotlib Figure, or the value False if a preview could not be generated

Return type:

matplotlib.figure.Figure or bool

class nexusLIMS.extractors.plugins.preview_generators.text_preview.TextPreviewGenerator[source]#

Preview generator for text files.

This generator creates thumbnail previews of text files by rendering the first few lines of text as an image.

name#

‘text_preview’

priority#

100

supported_extensions#

Type: typing.ClassVar

supports(context: ExtractionContext) bool[source]#

Check if this generator supports the given file.

Parameters:

context – The extraction context containing file information

Returns:

True if file extension is .txt

Return type:

bool

generate(context: ExtractionContext, output_path: Path) bool[source]#

Generate a thumbnail preview from a text file.

Parameters:
  • context – The extraction context containing file information

  • output_path – Path where the preview image should be saved

Returns:

True if preview was successfully generated, False otherwise

Return type:

bool