GIF animation finalized, fixed too manyu size-request updates

This commit is contained in:
2023-04-27 22:45:20 -05:00
parent 3fc6fbae86
commit 2b0703eb60
3 changed files with 105 additions and 69 deletions

View File

@@ -1,16 +1,14 @@
# Python imports
import inspect
# Lib imports
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
from gi.repository.GLib import Bytes
try:
from PIL import Image as PImage
logger.debug("Pillow library exists. Loading PIL as PImage...")
@@ -27,10 +25,11 @@ class ImageView(ImageViewMixin, Gtk.Image):
def __init__(self):
super(ImageView, self).__init__()
self.pixbuf = None
self.work_pixbuf = None
self.animation = None
self.fit_to_win = True
self.pixbuff = None
self.work_pixbuff = None
self.fit_to_win = True
self.animation = None
self.playing_animation = False
self._setup_styling()
self._setup_signals()
@@ -68,51 +67,49 @@ class ImageView(ImageViewMixin, Gtk.Image):
self.load_path(path)
if self.animation:
logger.debug("Start animation stub...")
self._play_animation()
def load_path(self, path):
self.pixbuf = None
self.work_pixbuf = None
self.animation = None
self.pixbuff = None
self.work_pixbuff = None
self.animation = None
self._stop_animation()
event_system.emit("update_path_label", (path,))
if path.endswith(".gif"):
self.set_as_gif(path)
return
if PImage and path.endswith(".webp"):
self.set_as_webp(path)
if not self.work_pixbuf:
if not self.work_pixbuff:
self.set_as_static(path)
self.pixbuf = self.work_pixbuf
if self.animation:
...
else:
self.set_from_pixbuf(self.work_pixbuf)
if self.fit_to_win:
self._fit_to_container()
def set_as_gif(self, path):
self.work_pixbuf = GdkPixbuf.PixbufAnimation.new_from_file(path).get_static_image()
image = None
try:
self.animation = Gtk.Image.new_from_file(path).get_animation()
image = GdkPixbuf.PixbufAnimation.new_from_file(path)
except Exception:
self.animation = Gtk.Image.new_from_resource(path).get_animation()
image = GdkPixbuf.PixbufAnimation.new_from_resource(path)
self.animation = image.get_iter()
def set_as_static(self, path):
try:
self.work_pixbuf = Gtk.Image.new_from_file(path).get_pixbuf()
self.work_pixbuff = Gtk.Image.new_from_file(path).get_pixbuf()
except Exception:
self.work_pixbuf = Gtk.Image.new_from_resource(path).get_pixbuf()
self.work_pixbuff = Gtk.Image.new_from_resource(path).get_pixbuf()
self.pixbuff = self.work_pixbuff
def set_as_webp(self, path):
w = settings.get_thumbnail_with()
h = settings.get_thumbnail_height()
print("shit")
self.work_pixbuf = self.image2pixbuf(path, w, h)
self.work_pixbuff = self.image2pixbuf(path, w, h)
@staticmethod
def image2pixbuf(path, _w, _h):