Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions gradia/ui/image_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,32 @@ def _on_uris_get(self, clipboard, result, user_data=None) -> None:
self._handle_uri(uri, ImageOrigin.Clipboard)
except GLib.GError as e:
print(f"Error reading URIs: {e}")
clipboard.read_texture_async(
callback=self._on_texture_get
)

def _on_texture_get(self, clipboard, result, user_data=None) -> None:
try:
texture = clipboard.read_texture_finish(result)
if texture:
self._handle_clipboard_texture(texture)
except GLib.GError as e:
print(f"Error reading image from clipboard: {e}")

def _handle_clipboard_texture(self, texture: Gdk.Texture) -> None:
try:
content = texture.save_to_png_bytes()

filename = "imported_clipboard_image.png"
temp_path = os.path.join(self.temp_dir, filename)

with open(temp_path, 'wb') as f:
f.write(content.get_data())

self._set_image_and_update_ui(temp_path, ImageOrigin.Clipboard)

except Exception as e:
logger.error(f"Error processing clipboard image: {e}")


class ScreenshotImageLoader(BaseImageLoader):
Expand Down