Added PIL support for images like webp; changed emit name

This commit is contained in:
itdominator 2022-09-30 23:30:38 -05:00
parent bdd532060a
commit d3e42b3ae0
12 changed files with 38 additions and 16 deletions

View File

@ -78,7 +78,7 @@ class Plugin(PluginBase):
@threaded @threaded
def _get_state(self, widget=None, eve=None): def _get_state(self, widget=None, eve=None):
self._event_system.post_event("get_current_state", None) self._event_system.emit("get_current_state
@threaded @threaded

View File

@ -107,7 +107,7 @@ class Plugin(PluginBase):
@threaded @threaded
def _show_properties_page(self, widget=None, eve=None): def _show_properties_page(self, widget=None, eve=None):
event_system.post_event("get_current_state", None) event_system.emit("get_current_state
state = self._fm_state state = self._fm_state
self._event_message = None self._event_message = None

View File

@ -77,7 +77,7 @@ class Plugin(PluginBase):
@threaded @threaded
def _show_info_page(self, widget=None, eve=None): def _show_info_page(self, widget=None, eve=None):
self._event_system.post_event("get_current_state", None) self._event_system.emit("get_current_state")
state = self._fm_state state = self._fm_state
self._event_message = None self._event_message = None
@ -111,6 +111,7 @@ class Plugin(PluginBase):
path = self._fm_state.tab.get_current_directory() path = self._fm_state.tab.get_current_directory()
parts = uri.split("/") parts = uri.split("/")
_title = parts[ len(parts) - 1 ] _title = parts[ len(parts) - 1 ]
trailer = None
try: try:
title = _title.split("(")[0].strip() title = _title.split("(")[0].strip()
@ -136,7 +137,6 @@ class Plugin(PluginBase):
raise Exception("No key found. Defering to none...") raise Exception("No key found. Defering to none...")
except Exception as e: except Exception as e:
print("No trailer found...") print("No trailer found...")
trailer = None
except Exception as e: except Exception as e:
print(repr(e)) print(repr(e))

View File

@ -125,7 +125,7 @@ class Plugin(PluginBase):
@daemon_threaded @daemon_threaded
def _show_grep_list_page(self, widget=None, eve=None): def _show_grep_list_page(self, widget=None, eve=None):
self._event_system.post_event("get_current_state", None) self._event_system.emit("get_current_state
state = self._fm_state state = self._fm_state
self._event_message = None self._event_message = None

View File

@ -43,4 +43,4 @@ class Plugin(PluginBase):
def send_message(self, widget=None, eve=None): def send_message(self, widget=None, eve=None):
message = "Hello, World!" message = "Hello, World!"
event_system.post_event("display_message", ("warning", message, None)) event_system.emit("display_message", ("warning", message, None))

View File

@ -75,7 +75,7 @@ class Plugin(PluginBase):
@threaded @threaded
def _show_thumbnailer_page(self, widget=None, eve=None): def _show_thumbnailer_page(self, widget=None, eve=None):
self._event_system.post_event("get_current_state", None) self._event_system.emit("get_current_state
state = self._fm_state state = self._fm_state
self._event_message = None self._event_message = None

View File

@ -44,7 +44,7 @@ class Plugin(PluginBase):
def _do_download(self, widget=None, eve=None): def _do_download(self, widget=None, eve=None):
self._event_system.post_event("get_current_state", None) self._event_system.emit("get_current_state
dir = self._fm_state.tab.get_current_directory() dir = self._fm_state.tab.get_current_directory()
self._download(dir) self._download(dir)

View File

@ -36,11 +36,11 @@ class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMi
for arg in unknownargs: for arg in unknownargs:
if os.path.isdir(arg): if os.path.isdir(arg):
message = f"FILE|{arg}" message = f"FILE|{arg}"
event_system.post_event("post_file_to_ipc", message) event_system.emit("post_file_to_ipc", message)
if args.new_tab and os.path.isdir(args.new_tab): if args.new_tab and os.path.isdir(args.new_tab):
message = f"FILE|{args.new_tab}" message = f"FILE|{args.new_tab}"
event_system.post_event("post_file_to_ipc", message) event_system.emit("post_file_to_ipc", message)
def _subscribe_to_events(self): def _subscribe_to_events(self):

View File

@ -154,7 +154,7 @@ class Controller_Data:
# if self.to_cut_files: # if self.to_cut_files:
# state.to_cut_files = self.format_to_uris(state.store, state.wid, state.tid, self.to_cut_files, True) # state.to_cut_files = self.format_to_uris(state.store, state.wid, state.tid, self.to_cut_files, True)
event_system.post_event("update_state_info_plugins", state) event_system.emit("update_state_info_plugins", state)
return state return state

View File

@ -2,10 +2,17 @@
import os, subprocess, threading, hashlib import os, subprocess, threading, hashlib
from os.path import isfile from os.path import isfile
# Gtk imports # Lib 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
try:
from PIL import Image as PImage
except Exception as e:
PImage = None
# Application imports # Application imports
from .mixins.desktopiconmixin import DesktopIconMixin from .mixins.desktopiconmixin import DesktopIconMixin
@ -67,12 +74,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)

View File

@ -18,7 +18,7 @@ class EventSystem:
def subscribe(self, event_type, fn): def subscribe(self, event_type, fn):
self.subscribers[event_type].append(fn) self.subscribers[event_type].append(fn)
def post_event(self, event_type, data): def emit(self, event_type, data = None):
if event_type in self.subscribers: if event_type in self.subscribers:
for fn in self.subscribers[event_type]: for fn in self.subscribers[event_type]:
if data: if data:

View File

@ -65,7 +65,7 @@ class IPCServer:
if "FILE|" in msg: if "FILE|" in msg:
file = msg.split("FILE|")[1].strip() file = msg.split("FILE|")[1].strip()
if file: if file:
event_system.post_event("handle_file_from_ipc", file) event_system.emit("handle_file_from_ipc", file)
conn.close() conn.close()
break break