rumps icon indicating copy to clipboard operation
rumps copied to clipboard

Any chance to display an image?

Open JokerQyou opened this issue 9 years ago • 5 comments

Like popup quick view window for an image in memory, rather than saving it to disk before programmatically open it via "Preview" app. Is that possible now? Or would you consider implementing this feature?

JokerQyou avatar Jan 09 '16 14:01 JokerQyou

You can do this by using StringIO for the file contents. I do this to generate QR Codes that pop-up in preview. I've made a PR to add this functionality #89

daredoes avatar Nov 29 '18 17:11 daredoes

I took a look at your PR, and it seems to be previewing an image on disk. I was initially thinking about directly previewing an image in memory, like by directly transforming an BytesIO content into an NSImage instance without writing the file to disk.

JokerQyou avatar Nov 30 '18 00:11 JokerQyou

Oh, I see. If you submit a Pull Request with the changes I'd be happy to review it.

daredoes avatar Nov 30 '18 16:11 daredoes

Actually that's the problem: I cannot show the image. First I tried your code in #89, and got this error:

2018-12-01 11:43:28.040 Python[42369:18111772] Traceback (most recent call last):
  File "/Users/joker/Works/rumps/rumps/rumps.py", line 1035, in callback_
    return _call_as_function_or_method(callback, self)
  File "/Users/joker/Works/rumps/rumps/rumps.py", line 384, in _call_as_function_or_method
    return method(event)
  File "simple.py", line 20, in sayhi
    rumps.show_image('/Users/joker/Downloads/256.png')
  File "/Users/joker/Works/rumps/rumps/rumps.py", line 212, in show_image
    return _nsimage_window_from_file(image)
  File "/Users/joker/Works/rumps/rumps/rumps.py", line 277, in _nsimage_window_from_file
    window = NSImageView.alloc().init(image)
TypeError: Need 0 arguments, got 1

I worked around by using this instead of NSImageView.alloc().init(image):

window = NSImageView.alloc().init()
window.setImage_(image)

This time I got no error, but the image did not show up either.

Now that I know how to converting raw bytes into an NSImage instance, it would be nice if I could be able to test it.

data = NSData.dataWithBytes_length_(raw_bytes, len(raw_bytes))
image = NSImage.alloc().initWithData_(data)

JokerQyou avatar Dec 01 '18 03:12 JokerQyou

/Users/joker

f4c4c416f43c8bd97b4a51f61d727829fdb4f175ab09763f3c589135116161f1

axeII avatar Dec 01 '18 11:12 axeII