maoschanz / maoschanz/drawing

Allow reading stdin/pipes as images

Open
#501 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
Python
Stars
869
Forks
106
PR merge metrics
No merged PRs in 30d

Description

## Requested feature

Support opening pipes, or at least stdin.

## Use case

I want to use drawing when I take a screen shot, basically like `screenshot | drawing -`, or `drawing <(screenshot)`.
This avoids needing to store a temporary file, and makes the flow simpler: only explicitly saved screen shots are ever stored. This happens a fair amount because my `screenshot` commands includes a step where I select a part of the screen with my mouse, which I often decide I want to redo.

## How to test

You can replace `screenshot` in the above examples with `cat /path/to/image`.

## Implementation idea

I think the best would be to detect if a given file is a pipe, read it and try to create a `DrImage` with the bytes.
`DrImage` would need to be adapted to also support using bytes instead of a `gfile`, so no file watching and create a pixbuf from bytes with: [GdkPixbuf.Pixbuf.new_from_bytes](https://docs.gtk.org/gdk-pixbuf/ctor.Pixbuf.new_from_bytes.html).

In the case the read bytes are not an image you'll need to display an error window, but that could also help fix the TODO in `_get_valid_file`: remove the `utilities_gfile_is_image` check and in the `DrImage` the pixbuf will give you an exception you display.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing image opening through _get_valid_file, utilities_gfile_is_image, and DrImage, then review the suggested GdkPixbuf.Pixbuf.new_from_bytes API. Test with cat /path/to/image piped to the application and verify that valid image bytes open without a temporary file while invalid bytes produce an error window.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, desktop
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.