WIP GIF support

This commit is contained in:
itdominator 2023-04-27 17:57:23 -05:00
parent 0259727784
commit 599d1f5145
4 changed files with 32 additions and 28 deletions

View File

@ -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",))

View File

@ -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")

View File

@ -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

View File

@ -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