Verify if image can be used when pasting it

This commit is contained in:
jeffser 2024-06-30 22:12:46 -06:00
parent ff8b20df98
commit 2c2a1ac2bc

View File

@ -1383,12 +1383,15 @@ Generate a title following these rules:
try: try:
texture = clipboard.read_texture_finish(result) texture = clipboard.read_texture_finish(result)
if texture: if texture:
pixbuf = Gdk.pixbuf_get_from_texture(texture) if self.verify_if_image_can_be_used():
if not os.path.exists('/tmp/alpaca/images/'): pixbuf = Gdk.pixbuf_get_from_texture(texture)
os.makedirs('/tmp/alpaca/images/') if not os.path.exists('/tmp/alpaca/images/'):
image_name = self.generate_numbered_name('image.png', os.listdir('/tmp/alpaca/images')) os.makedirs('/tmp/alpaca/images/')
pixbuf.savev('/tmp/alpaca/images/{}'.format(image_name), "png", [], []) image_name = self.generate_numbered_name('image.png', os.listdir('/tmp/alpaca/images'))
self.attach_file('/tmp/alpaca/images/{}'.format(image_name), 'image') pixbuf.savev('/tmp/alpaca/images/{}'.format(image_name), "png", [], [])
self.attach_file('/tmp/alpaca/images/{}'.format(image_name), 'image')
else:
self.show_toast('error', 8, self.main_overlay)
except Exception as e: 'huh' except Exception as e: 'huh'
def on_clipboard_paste(self, textview): def on_clipboard_paste(self, textview):