Added PIL support for images like webp; changed emit name
This commit is contained in:
parent
bdd532060a
commit
d3e42b3ae0
|
@ -78,7 +78,7 @@ class Plugin(PluginBase):
|
|||
|
||||
@threaded
|
||||
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
|
||||
|
|
|
@ -107,7 +107,7 @@ class Plugin(PluginBase):
|
|||
|
||||
@threaded
|
||||
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
|
||||
self._event_message = None
|
||||
|
|
|
@ -77,7 +77,7 @@ class Plugin(PluginBase):
|
|||
|
||||
@threaded
|
||||
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
|
||||
self._event_message = None
|
||||
|
@ -111,6 +111,7 @@ class Plugin(PluginBase):
|
|||
path = self._fm_state.tab.get_current_directory()
|
||||
parts = uri.split("/")
|
||||
_title = parts[ len(parts) - 1 ]
|
||||
trailer = None
|
||||
|
||||
try:
|
||||
title = _title.split("(")[0].strip()
|
||||
|
@ -136,7 +137,6 @@ class Plugin(PluginBase):
|
|||
raise Exception("No key found. Defering to none...")
|
||||
except Exception as e:
|
||||
print("No trailer found...")
|
||||
trailer = None
|
||||
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
|
|
|
@ -125,7 +125,7 @@ class Plugin(PluginBase):
|
|||
|
||||
@daemon_threaded
|
||||
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
|
||||
self._event_message = None
|
||||
|
|
|
@ -43,4 +43,4 @@ class Plugin(PluginBase):
|
|||
|
||||
def send_message(self, widget=None, eve=None):
|
||||
message = "Hello, World!"
|
||||
event_system.post_event("display_message", ("warning", message, None))
|
||||
event_system.emit("display_message", ("warning", message, None))
|
||||
|
|
|
@ -75,7 +75,7 @@ class Plugin(PluginBase):
|
|||
|
||||
@threaded
|
||||
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
|
||||
self._event_message = None
|
||||
|
|
|
@ -44,7 +44,7 @@ class Plugin(PluginBase):
|
|||
|
||||
|
||||
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()
|
||||
self._download(dir)
|
||||
|
|
|
@ -36,11 +36,11 @@ class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMi
|
|||
for arg in unknownargs:
|
||||
if os.path.isdir(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):
|
||||
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):
|
||||
|
|
|
@ -154,7 +154,7 @@ class Controller_Data:
|
|||
# if self.to_cut_files:
|
||||
# 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
|
||||
|
||||
|
|
|
@ -2,10 +2,17 @@
|
|||
import os, subprocess, threading, hashlib
|
||||
from os.path import isfile
|
||||
|
||||
# Gtk imports
|
||||
# Lib imports
|
||||
import gi
|
||||
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
|
||||
from .mixins.desktopiconmixin import DesktopIconMixin
|
||||
|
@ -66,6 +73,9 @@ class Icon(DesktopIconMixin, VideoIconMixin):
|
|||
return GdkPixbuf.PixbufAnimation.new_from_file(path) \
|
||||
.get_static_image() \
|
||||
.scale_simple(wxh[0], wxh[1], GdkPixbuf.InterpType.BILINEAR)
|
||||
else:
|
||||
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:
|
||||
|
@ -73,6 +83,18 @@ class Icon(DesktopIconMixin, VideoIconMixin):
|
|||
print( repr(e) )
|
||||
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):
|
||||
try:
|
||||
return GdkPixbuf.Pixbuf.new_from_file(path)
|
||||
|
|
|
@ -18,7 +18,7 @@ class EventSystem:
|
|||
def subscribe(self, event_type, 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:
|
||||
for fn in self.subscribers[event_type]:
|
||||
if data:
|
||||
|
|
|
@ -65,7 +65,7 @@ class IPCServer:
|
|||
if "FILE|" in msg:
|
||||
file = msg.split("FILE|")[1].strip()
|
||||
if file:
|
||||
event_system.post_event("handle_file_from_ipc", file)
|
||||
event_system.emit("handle_file_from_ipc", file)
|
||||
|
||||
conn.close()
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue