-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow reading stdin/pipes as images #501
Comments
that's pretty niche 🤔 people may prefer pressing ctrl (or whatever they set as a keyboard shortcut) when doing their screenshot, so it goes in the clipboard instead of a new file, and then you can right-click on the app icon and choose "edit image in the clipboard" (or open it from the CLI with
no, there is a comment in utilities_gfile_is_image explaining what happens here:
you could remove that first check and things would still work fine,
stdin isn't an argument like the file names. In this line https://github.com/maoschanz/drawing/blob/master/src/main.py#L146 args[1] is a Gio.ApplicationCommandLine, and this object has a get_stdin() method but it provides a stream, it's not easy to get the data from it, especially since gtk apps are unique instances: cli invocations often activate the existing instance and die right away. I don't know how to deal with that, but if it's feasible i will try |
I tried with the clipboard but I use wayland and it's not working. If you want me to help debug that, feel free to give me a custom version to run. I subscribed to issue #377, so leaving a comment there is good enough for me to notice.
That was what I meant yes. I understand your concern about creating a useless tab. It was a quick suggestion so feel free to ignore.
In general apps that use files handle fd=<(cat /path/to/whatever)
python -c 'import os, stat; assert stat.S_ISFIFO(os.stat("'$fd'").st_mode)'
# Note that stdin is a char device, not a FIFO/pipe:
python -c 'import os, stat; print(stat.S_ISCHR(os.stat("/dev/stdin").st_mode))' In your loop over EDIT: I should also mention I don't use a DE. That's why my screenshot keyboard shortcut runs a shell pipeline and doesn't match what you're used to. |
this would be a great solution if i were developing from scratch, but here, reinventing the wheel with the i have a Gio.InputStream and i have to read it (asynchronously if i want to be clean, and it's always tricky to have scenarii with several threads), manage its errors, and close it. I said it's not easy compared to normal arguments, not that it's impossible and i have to parse command lines manually... |
You don't need to parse the command line manually, just add an if in the loop on if fpath == '-':
print("Do something special here") For stdin it'd be better to handle it synchronously: when running a shell pipeline, all processes run at the same time. So blocking on stdin is perfect since it pauses the program until all the previous ones had ran. In my case, not blocking on stdin would mean that |
i agree with the idea, but i'm not sure whether or not it's possible:
i don't know if this singleton pattern works the intended way on something as "KISS" as nix without a DE, but it's the default setup for everyone if the idea is feasible, its behavior has to consistently make sense for both "commands starting the instance" and "commands activating the previously started instance", and i'm afraid we will only know that after i try to implement it |
I see. From my tests, the behaviour depends on whether it's the first window that's opened or not:
Here's my thoughts on other/second launch just in case though (again I don't know much about GTK so I might be very wrong):
Honestly for my use, only supporting stdin on first launch is good enough. So avoiding all that complexity and just sticking with a sync Maybe adding a non-singleton/isolated launch mode would be a good middle ground, but I have no clue if that's easy with GTK. |
I would also like this feature please, it would make it behave also a tool other then just a drawing app. |
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 -
, ordrawing <(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 withcat /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 agfile
, so no file watching and create a pixbuf from bytes with: GdkPixbuf.Pixbuf.new_from_bytes.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 theutilities_gfile_is_image
check and in theDrImage
the pixbuf will give you an exception you display.The text was updated successfully, but these errors were encountered: