From d3e42b3ae09ff596d97d317dc0dd19e41081d30e Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Fri, 30 Sep 2022 23:30:38 -0500 Subject: [PATCH] Added PIL support for images like webp; changed emit name --- plugins/favorites/plugin.py | 2 +- plugins/file_properties/plugin.py | 2 +- plugins/movie_tv_info/plugin.py | 4 +-- plugins/searcher/plugin.py | 2 +- plugins/template/plugin.py | 2 +- plugins/vod_thumbnailer/plugin.py | 2 +- plugins/youtube_download/plugin.py | 2 +- .../SolarFM/solarfm/core/controller.py | 4 +-- .../SolarFM/solarfm/core/controller_data.py | 2 +- .../shellfm/windows/tabs/icons/icon.py | 28 +++++++++++++++++-- .../SolarFM/solarfm/utils/event_system.py | 2 +- .../SolarFM/solarfm/utils/ipc_server.py | 2 +- 12 files changed, 38 insertions(+), 16 deletions(-) diff --git a/plugins/favorites/plugin.py b/plugins/favorites/plugin.py index aca3f63..3a68f05 100644 --- a/plugins/favorites/plugin.py +++ b/plugins/favorites/plugin.py @@ -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 diff --git a/plugins/file_properties/plugin.py b/plugins/file_properties/plugin.py index 5177943..2cb6262 100644 --- a/plugins/file_properties/plugin.py +++ b/plugins/file_properties/plugin.py @@ -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 diff --git a/plugins/movie_tv_info/plugin.py b/plugins/movie_tv_info/plugin.py index 64df1c6..f7f9c3c 100644 --- a/plugins/movie_tv_info/plugin.py +++ b/plugins/movie_tv_info/plugin.py @@ -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)) diff --git a/plugins/searcher/plugin.py b/plugins/searcher/plugin.py index 9328a90..cc50574 100644 --- a/plugins/searcher/plugin.py +++ b/plugins/searcher/plugin.py @@ -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 diff --git a/plugins/template/plugin.py b/plugins/template/plugin.py index b99308a..dff5d40 100644 --- a/plugins/template/plugin.py +++ b/plugins/template/plugin.py @@ -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)) diff --git a/plugins/vod_thumbnailer/plugin.py b/plugins/vod_thumbnailer/plugin.py index 3d6f164..c74f551 100644 --- a/plugins/vod_thumbnailer/plugin.py +++ b/plugins/vod_thumbnailer/plugin.py @@ -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 diff --git a/plugins/youtube_download/plugin.py b/plugins/youtube_download/plugin.py index 5ebf3b1..da13c75 100644 --- a/plugins/youtube_download/plugin.py +++ b/plugins/youtube_download/plugin.py @@ -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) diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/core/controller.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/core/controller.py index 8d99d05..7a9c930 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/core/controller.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/core/controller.py @@ -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): diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/core/controller_data.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/core/controller_data.py index 04a6656..ea44a63 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/core/controller_data.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/core/controller_data.py @@ -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 diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/icons/icon.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/icons/icon.py index 3a18857..94a9b2e 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/icons/icon.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/icons/icon.py @@ -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 @@ -67,12 +74,27 @@ class Icon(DesktopIconMixin, VideoIconMixin): .get_static_image() \ .scale_simple(wxh[0], wxh[1], GdkPixbuf.InterpType.BILINEAR) 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: print("Image Scaling Issue:") 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) diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/utils/event_system.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/utils/event_system.py index 10b2765..25c96fc 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/utils/event_system.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/utils/event_system.py @@ -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: diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/utils/ipc_server.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/utils/ipc_server.py index c73dc0a..f71691b 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/utils/ipc_server.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/utils/ipc_server.py @@ -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