From 599d1f5145f4a13e1edd94e4670f8c556fbff87c Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Thu, 27 Apr 2023 17:57:23 -0500 Subject: [PATCH] WIP GIF support --- src/core/containers/image_view_scroll.py | 4 +++- src/core/widgets/button_controls.py | 16 +++++--------- src/core/widgets/image.py | 12 ++++++---- src/core/widgets/image_view.py | 28 +++++++++++++----------- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/core/containers/image_view_scroll.py b/src/core/containers/image_view_scroll.py index da58b3f..1c23348 100644 --- a/src/core/containers/image_view_scroll.py +++ b/src/core/containers/image_view_scroll.py @@ -7,6 +7,7 @@ gi.require_version('Gtk', '3.0') gi.require_version('Gdk', '3.0') from gi.repository import Gtk from gi.repository import Gdk +from gi.repository import GLib # Application imports from ..widgets.image_view import ImageView @@ -105,5 +106,6 @@ class ImageViewScroll(Gtk.ScrolledWindow): event_system.emit("load_image_list", (path, img_list)) + @daemon_threaded def _size_request_change(self, widget = None, eve = None): - event_system.emit("size_allocate") + GLib.idle_add(event_system.emit, *("size_allocate",)) diff --git a/src/core/widgets/button_controls.py b/src/core/widgets/button_controls.py index 20726f2..df692ec 100644 --- a/src/core/widgets/button_controls.py +++ b/src/core/widgets/button_controls.py @@ -100,18 +100,14 @@ class ButtonControls(Gtk.ButtonBox): event_system.emit("vertical_flip") def _scale_1_two_1(self, widget = None, eve = None): - if eve.button == 1: - self._unset_class(self.fit_button) - self._set_class(self.one2one_button) - - event_system.emit("scale_1_two_1") + self._unset_class(self.fit_button) + self._set_class(self.one2one_button) + event_system.emit("scale_1_two_1") def _fit_to_container(self, widget = None, eve = None): - if eve.button == 1: - self._unset_class(self.one2one_button) - self._set_class(self.fit_button) - - event_system.emit("fit_to_container") + self._unset_class(self.one2one_button) + self._set_class(self.fit_button) + event_system.emit("fit_to_container") def _horizontal_flip(self, widget = None, eve = None): event_system.emit("horizontal_flip") diff --git a/src/core/widgets/image.py b/src/core/widgets/image.py index 5689c63..82f8cae 100644 --- a/src/core/widgets/image.py +++ b/src/core/widgets/image.py @@ -66,10 +66,14 @@ class Image(Gtk.EventBox): if PImage and path.endswith(".webp"): return self.image2pixbuf(path, w, h) - try: - pixbuf = Gtk.Image.new_from_file(path).get_pixbuf() - except Exception: - pixbuf = Gtk.Image.new_from_resource(path).get_pixbuf() + if path.endswith(".gif"): + pixbuf = GdkPixbuf.PixbufAnimation.new_from_file(path).get_static_image() + + if not pixbuf: + try: + pixbuf = Gtk.Image.new_from_file(path).get_pixbuf() + except Exception: + pixbuf = Gtk.Image.new_from_resource(path).get_pixbuf() return pixbuf.scale_simple(w, h, 2) # 2 = BILINEAR and is best by default diff --git a/src/core/widgets/image_view.py b/src/core/widgets/image_view.py index cc7b4dc..6c75566 100644 --- a/src/core/widgets/image_view.py +++ b/src/core/widgets/image_view.py @@ -4,6 +4,7 @@ import gi gi.require_version('Gtk', '3.0') gi.require_version('Gdk', '3.0') +gi.require_version('GdkPixbuf', '2.0') from gi.repository import Gtk from gi.repository import Gdk from gi.repository import GdkPixbuf @@ -65,17 +66,18 @@ class ImageView(Gtk.Image): self.animation = None if path.endswith(".gif"): + self.work_pixbuf = GdkPixbuf.PixbufAnimation.new_from_file(path).get_static_image() try: self.animation = Gtk.Image.new_from_file(path).get_animation() except Exception: self.animation = Gtk.Image.new_from_resource(path).get_animation() - return - try: - self.work_pixbuf = Gtk.Image.new_from_file(path).get_pixbuf() - except Exception: - self.work_pixbuf = Gtk.Image.new_from_resource(path).get_pixbuf() + if not self.work_pixbuf: + try: + self.work_pixbuf = Gtk.Image.new_from_file(path).get_pixbuf() + except Exception: + self.work_pixbuf = Gtk.Image.new_from_resource(path).get_pixbuf() self.pixbuf = self.work_pixbuf self.set_from_pixbuf(self.work_pixbuf) @@ -87,7 +89,7 @@ class ImageView(Gtk.Image): def _zoom_out(self): - if self.work_pixbuf: + if self.work_pixbuf and self.pixbuf: # TODO: Setup scale factor setting to pull from settings... stepx = self.work_pixbuf.get_width() * 0.05 stepy = self.work_pixbuf.get_height() * 0.05 @@ -99,26 +101,26 @@ class ImageView(Gtk.Image): self.set_from_pixbuf(self.work_pixbuf) def _rotate_left(self): - if self.work_pixbuf: + if self.work_pixbuf and self.pixbuf: self.work_pixbuf = self.work_pixbuf.rotate_simple(GdkPixbuf.PixbufRotation.COUNTERCLOCKWISE) self.pixbuf = self.pixbuf.rotate_simple(GdkPixbuf.PixbufRotation.COUNTERCLOCKWISE) self.set_from_pixbuf(self.work_pixbuf) def _vertical_flip(self): - if self.work_pixbuf: + if self.work_pixbuf and self.pixbuf: self.work_pixbuf = self.work_pixbuf.flip(True) self.pixbuf = self.pixbuf.flip(True) self.set_from_pixbuf(self.work_pixbuf) def _scale_1_two_1(self): self.fit_to_win = False - if self.work_pixbuf: + if self.work_pixbuf and self.pixbuf: self.work_pixbuf = self.pixbuf self.set_from_pixbuf(self.work_pixbuf) def _fit_to_container(self): self.fit_to_win = True - if self.work_pixbuf: + if self.work_pixbuf and self.pixbuf: parent_aloc = self.get_parent().get_parent().get_allocation() pw = parent_aloc.width ph = parent_aloc.height @@ -142,19 +144,19 @@ class ImageView(Gtk.Image): self.set_from_pixbuf(self.work_pixbuf) def _horizontal_flip(self): - if self.work_pixbuf: + if self.work_pixbuf and self.pixbuf: self.work_pixbuf = self.work_pixbuf.flip(False) self.pixbuf = self.pixbuf.flip(False) self.set_from_pixbuf(self.work_pixbuf) def _rotate_right(self): - if self.work_pixbuf: + if self.work_pixbuf and self.pixbuf: self.work_pixbuf = self.work_pixbuf.rotate_simple(GdkPixbuf.PixbufRotation.CLOCKWISE) self.pixbuf = self.pixbuf.rotate_simple(GdkPixbuf.PixbufRotation.CLOCKWISE) self.set_from_pixbuf(self.work_pixbuf) def _zoom_in(self): - if self.work_pixbuf: + if self.work_pixbuf and self.pixbuf: # TODO: Setup scale factor setting to pull from settings... stepx = self.work_pixbuf.get_width() * 0.05 stepy = self.work_pixbuf.get_height() * 0.05