added webp support, cleaned up configs
This commit is contained in:
parent
058a5a7ef6
commit
4c4cb051d8
|
@ -13,6 +13,12 @@ from .controller_data import Controller_Data
|
||||||
from .mixins.tree_view_update_mixin import TreeViewUpdateMixin
|
from .mixins.tree_view_update_mixin import TreeViewUpdateMixin
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from PIL import Image as PImage
|
||||||
|
except Exception as e:
|
||||||
|
PImage = None
|
||||||
|
|
||||||
|
|
||||||
def threaded(fn):
|
def threaded(fn):
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
||||||
|
@ -119,8 +125,25 @@ class Controller(TreeViewUpdateMixin, Controller_Data):
|
||||||
geom_rec = self.image_area.get_parent().get_parent().get_allocated_size()[0]
|
geom_rec = self.image_area.get_parent().get_parent().get_allocated_size()[0]
|
||||||
width = geom_rec.width - 15
|
width = geom_rec.width - 15
|
||||||
height = geom_rec.height - 15
|
height = geom_rec.height - 15
|
||||||
|
wxh = [width, height]
|
||||||
|
|
||||||
self.image_area.set_size_request(width, height)
|
self.image_area.set_size_request(width, height)
|
||||||
return GdkPixbuf.Pixbuf.new_from_file_at_scale(uri, width, height, True)
|
if PImage and uri.lower().endswith(".webp"):
|
||||||
|
return self.image2pixbuf(uri, wxh)
|
||||||
|
else:
|
||||||
|
return GdkPixbuf.Pixbuf.new_from_file_at_scale(uri, width, height, True)
|
||||||
|
|
||||||
|
def image2pixbuf(self, path, wxh):
|
||||||
|
"""Convert Pillow image to GdkPixbuf"""
|
||||||
|
im = PImage.open(path)
|
||||||
|
data = im.tobytes()
|
||||||
|
data = GLib.Bytes.new(data)
|
||||||
|
w, h = im.size
|
||||||
|
|
||||||
|
pixbuf = GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB,
|
||||||
|
False, 8, w, h, w * 3)
|
||||||
|
|
||||||
|
return pixbuf.scale_simple(wxh[0], wxh[1], 2) # BILINEAR = 2
|
||||||
|
|
||||||
def _load_image(self):
|
def _load_image(self):
|
||||||
self.clear_children(self.image_area)
|
self.clear_children(self.image_area)
|
||||||
|
|
|
@ -5,13 +5,19 @@ from os.path import isfile
|
||||||
# Gtk imports
|
# Gtk imports
|
||||||
import gi
|
import gi
|
||||||
gi.require_version('GdkPixbuf', '2.0')
|
gi.require_version('GdkPixbuf', '2.0')
|
||||||
from gi.repository import GdkPixbuf
|
from gi.repository import GdkPixbuf, GLib
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from .mixins.desktopiconmixin import DesktopIconMixin
|
from .mixins.desktopiconmixin import DesktopIconMixin
|
||||||
from .mixins.videoiconmixin import VideoIconMixin
|
from .mixins.videoiconmixin import VideoIconMixin
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from PIL import Image as PImage
|
||||||
|
except Exception as e:
|
||||||
|
PImage = None
|
||||||
|
|
||||||
|
|
||||||
def threaded(fn):
|
def threaded(fn):
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
||||||
|
@ -60,12 +66,27 @@ class Icon(DesktopIconMixin, VideoIconMixin):
|
||||||
.get_static_image() \
|
.get_static_image() \
|
||||||
.scale_simple(wxh[0], wxh[1], GdkPixbuf.InterpType.BILINEAR)
|
.scale_simple(wxh[0], wxh[1], GdkPixbuf.InterpType.BILINEAR)
|
||||||
else:
|
else:
|
||||||
return GdkPixbuf.Pixbuf.new_from_file_at_scale(path, wxh[0], wxh[1], True)
|
if PImage and path.lower().endswith(".webp"):
|
||||||
|
return self.image2pixbuf(path, wxh)
|
||||||
|
else:
|
||||||
|
return GdkPixbuf.Pixbuf.new_from_file_at_scale(path, wxh[0], wxh[1], True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Image Scaling Issue:")
|
print("Image Scaling Issue:")
|
||||||
print( repr(e) )
|
print( repr(e) )
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def image2pixbuf(self, path, wxh):
|
||||||
|
"""Convert Pillow image to GdkPixbuf"""
|
||||||
|
im = PImage.open(path)
|
||||||
|
data = im.tobytes()
|
||||||
|
data = GLib.Bytes.new(data)
|
||||||
|
w, h = im.size
|
||||||
|
|
||||||
|
pixbuf = GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB,
|
||||||
|
False, 8, w, h, w * 3)
|
||||||
|
|
||||||
|
return pixbuf.scale_simple(wxh[0], wxh[1], 2) # BILINEAR = 2
|
||||||
|
|
||||||
def create_from_file(self, path):
|
def create_from_file(self, path):
|
||||||
try:
|
try:
|
||||||
return GdkPixbuf.Pixbuf.new_from_file(path)
|
return GdkPixbuf.Pixbuf.new_from_file(path)
|
||||||
|
|
Loading…
Reference in New Issue