From 75da08d0819fada0ab51e5fece11036527c2dd36 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Thu, 20 Oct 2022 22:23:14 -0500 Subject: [PATCH] Added dirty start check, added images to plugin buttons, cleanup --- plugins/archiver/plugin.py | 4 ++ plugins/file_properties/plugin.py | 4 ++ plugins/movie_tv_info/plugin.py | 4 ++ plugins/searcher/mixins/file_search_mixin.py | 2 +- plugins/searcher/mixins/grep_search_mixin.py | 5 ++- plugins/searcher/plugin.py | 4 ++ plugins/searcher/utils/search.py | 14 +++---- plugins/trasher/trasher.glade | 2 +- plugins/vod_thumbnailer/plugin.py | 5 +++ .../solarfm-0.0.1/SolarFM/solarfm/__main__.py | 1 - .../SolarFM/solarfm/core/controller.py | 1 + .../tabs/icons/mixins/desktopiconmixin.py | 7 +--- .../shellfm/windows/tabs/utils/launcher.py | 2 +- .../shellfm/windows/tabs/utils/settings.py | 2 +- .../SolarFM/solarfm/utils/ipc_server.py | 4 +- .../SolarFM/solarfm/utils/settings.py | 42 +++++++++++++++++++ .../usr/share/solarfm/Main_Window.glade | 28 ------------- 17 files changed, 81 insertions(+), 50 deletions(-) diff --git a/plugins/archiver/plugin.py b/plugins/archiver/plugin.py index 1c02225..ccfd732 100644 --- a/plugins/archiver/plugin.py +++ b/plugins/archiver/plugin.py @@ -81,8 +81,12 @@ class Plugin(PluginBase): self._archiver_dialogue = self._builder.get_object("archiver_dialogue") self._arc_command_buffer = self._builder.get_object("arc_command_buffer") + icon = Gtk.Image(stock=Gtk.STOCK_FLOPPY) button = Gtk.Button(label=self.name) + + button.set_image(icon) button.connect("button-release-event", self.show_archiver_dialogue) + return button def run(self): diff --git a/plugins/file_properties/plugin.py b/plugins/file_properties/plugin.py index ec41032..c20bc1a 100644 --- a/plugins/file_properties/plugin.py +++ b/plugins/file_properties/plugin.py @@ -99,8 +99,12 @@ class Plugin(PluginBase): self._file_group = self._builder.get_object("file_group") def generate_reference_ui_element(self): + icon = Gtk.Image(stock=Gtk.STOCK_PROPERTIES ) button = Gtk.Button(label=self.name) + button.connect("button-release-event", self._show_properties_page) + button.set_image(icon) + return button diff --git a/plugins/movie_tv_info/plugin.py b/plugins/movie_tv_info/plugin.py index 3f8459e..2bae410 100644 --- a/plugins/movie_tv_info/plugin.py +++ b/plugins/movie_tv_info/plugin.py @@ -70,8 +70,12 @@ class Plugin(PluginBase): self._trailer_link = self._builder.get_object("trailer_link") def generate_reference_ui_element(self): + icon = Gtk.Image(stock=Gtk.STOCK_FIND) button = Gtk.Button(label=self.name) + button.connect("button-release-event", self._show_info_page) + button.set_image(icon) + return button @threaded diff --git a/plugins/searcher/mixins/file_search_mixin.py b/plugins/searcher/mixins/file_search_mixin.py index 749cf9d..6f17f08 100644 --- a/plugins/searcher/mixins/file_search_mixin.py +++ b/plugins/searcher/mixins/file_search_mixin.py @@ -49,8 +49,8 @@ class FileSearchMixin: GLib.idle_add(self.reset_file_list_box) # NOTE: If query create new process and do all new loop. - self.pause_fifo_update = False if query: + self.pause_fifo_update = False GLib.idle_add(self._exec_find_file_query, query) def _exec_find_file_query(self, widget=None, eve=None): diff --git a/plugins/searcher/mixins/grep_search_mixin.py b/plugins/searcher/mixins/grep_search_mixin.py index ad5c9da..a7590c1 100644 --- a/plugins/searcher/mixins/grep_search_mixin.py +++ b/plugins/searcher/mixins/grep_search_mixin.py @@ -1,5 +1,6 @@ # Python imports -import threading, subprocess, signal, json, shlex +import ctypes, threading, subprocess, signal, json, shlex +libgcc_s = ctypes.CDLL('libgcc_s.so.1') # Lib imports import gi @@ -49,8 +50,8 @@ class GrepSearchMixin: GLib.idle_add(self.reset_grep_box) # NOTE: If query create new process and do all new loop. - self.pause_fifo_update = False if query: + self.pause_fifo_update = False GLib.idle_add(self._exec_grep_query, query) def _exec_grep_query(self, widget=None, eve=None): diff --git a/plugins/searcher/plugin.py b/plugins/searcher/plugin.py index f941dc9..ab63097 100644 --- a/plugins/searcher/plugin.py +++ b/plugins/searcher/plugin.py @@ -80,8 +80,12 @@ class Plugin(IPCServer, FileSearchMixin, GrepSearchMixin, PluginBase): self.create_ipc_listener() def generate_reference_ui_element(self): + icon = Gtk.Image(stock=Gtk.STOCK_FIND) button = Gtk.Button(label=self.name) + button.connect("button-release-event", self._show_page) + button.set_image(icon) + return button diff --git a/plugins/searcher/utils/search.py b/plugins/searcher/utils/search.py index 692fbc2..be0b31c 100755 --- a/plugins/searcher/utils/search.py +++ b/plugins/searcher/utils/search.py @@ -16,9 +16,9 @@ from multiprocessing.connection import Client _ipc_address = f'/tmp/solarfm-search_grep-ipc.sock' _ipc_authkey = b'' + bytes(f'solarfm-search_grep-ipc', 'utf-8') -filter = (".mkv", ".mp4", ".webm", ".avi", ".mov", ".m4v", ".mpg", ".mpeg", ".wmv", ".flv") + \ - (".png", ".jpg", ".jpeg", ".gif", ".ico", ".tga", ".webp") + \ - (".psf", ".mp3", ".ogg", ".flac", ".m4a") +filter = (".cpp", ".css", ".c", ".go", ".html", ".htm", ".java", ".js", ".json", ".lua", ".md", ".py", ".rs", ".toml", ".xml", ".pom") + \ + (".txt", ".text", ".sh", ".cfg", ".conf", ".log") + # NOTE: Threads WILL NOT die with parent's destruction. def threaded(fn): @@ -59,7 +59,7 @@ def _search_for_string(file, query): grep_result_set = {} padding = 15 - with open(file, 'r') as fp: + with open(file, 'rb') as fp: # NOTE: I know there's an issue if there's a very large file with content # all on one line will lower and dupe it. And, yes, it will only # return one instance from the file. @@ -80,7 +80,7 @@ def _search_for_string(file, query): else: line = raw - b64_line = base64.urlsafe_b64encode(line.encode('utf-8')).decode('utf-8') + b64_line = base64.urlsafe_b64encode(line).decode('utf-8') if f"{b64_file}" in grep_result_set.keys(): grep_result_set[f"{b64_file}"][f"{i+1}"] = b64_line else: @@ -109,7 +109,7 @@ def grep_search(path, query): if os.path.isdir(target): grep_search(target, query) else: - if not target.lower().endswith(filter): + if target.lower().endswith(filter): size = os.path.getsize(target) if not size > 5000: _search_for_string(target, query) @@ -125,7 +125,7 @@ def search(args): file_search(args.dir, args.query.lower()) if args.type == "grep_search": - grep_search(args.dir, args.query.lower()) + grep_search(args.dir, args.query.lower().encode("utf-8")) if __name__ == "__main__": diff --git a/plugins/trasher/trasher.glade b/plugins/trasher/trasher.glade index 54837b9..2867476 100644 --- a/plugins/trasher/trasher.glade +++ b/plugins/trasher/trasher.glade @@ -47,6 +47,7 @@ True True Empty Trash... + 20 @@ -63,7 +64,6 @@ True True Move to Trash... - 20 trash_img True diff --git a/plugins/vod_thumbnailer/plugin.py b/plugins/vod_thumbnailer/plugin.py index e730797..694972f 100644 --- a/plugins/vod_thumbnailer/plugin.py +++ b/plugins/vod_thumbnailer/plugin.py @@ -68,8 +68,13 @@ class Plugin(PluginBase): self._file_hash = self._builder.get_object("file_hash") def generate_reference_ui_element(self): + pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(f"{self.path}/../../icons/video.png", 16, 16, True) + icon = Gtk.Image.new_from_pixbuf(pixbuf) button = Gtk.Button(label=self.name) + + button.set_image(icon) button.connect("button-release-event", self._show_thumbnailer_page) + return button diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/__main__.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/__main__.py index 9bfffcb..daee641 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/__main__.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/__main__.py @@ -1,6 +1,5 @@ #!/usr/bin/python3 - # Python imports import argparse, faulthandler, traceback from setproctitle import setproctitle 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 22ab397..2174dda 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 @@ -54,6 +54,7 @@ class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMi if not settings.is_trace_debug(): self.fm_controller.save_state() + settings.clear_pid() time.sleep(event_sleep_time) Gtk.main_quit() diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/icons/mixins/desktopiconmixin.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/icons/mixins/desktopiconmixin.py index 3f69ea3..3ee2a50 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/icons/mixins/desktopiconmixin.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/icons/mixins/desktopiconmixin.py @@ -50,13 +50,8 @@ class DesktopIconMixin: return None def traverse_icons_folder(self, path, icon): - alt_icon_path = "" - for (dirpath, dirnames, filenames) in os.walk(path): for file in filenames: appNM = "application-x-" + icon if icon in file or appNM in file: - alt_icon_path = dirpath + "/" + file - break - - return alt_icon_path + return f"{dirpath}/{file}" diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/utils/launcher.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/utils/launcher.py index eab19cd..87f7da6 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/utils/launcher.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/utils/launcher.py @@ -1,5 +1,5 @@ # System import -import os, threading, subprocess, shlex +import os, threading, subprocess # Lib imports diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/utils/settings.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/utils/settings.py index 928bf6a..b1e5dec 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/utils/settings.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/utils/settings.py @@ -25,7 +25,7 @@ class Settings: FFMPG_THUMBNLR = f"{CONFIG_PATH}/ffmpegthumbnailer" # Thumbnail generator binary REMUX_FOLDER = f"{USER_HOME}/.remuxs" # Remuxed files folder - ICON_DIRS = ["/usr/share/pixmaps", "/usr/share/icons", f"{USER_HOME}/.icons" ,] + ICON_DIRS = ["/usr/share/icons", f"{USER_HOME}/.icons" "/usr/share/pixmaps"] BASE_THUMBS_PTH = f"{USER_HOME}/.thumbnails" # Used for thumbnail generation ABS_THUMBS_PTH = f"{BASE_THUMBS_PTH}/normal" # Used for thumbnail generation STEAM_ICONS_PTH = f"{BASE_THUMBS_PTH}/steam_icons" 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 5aa0ebd..f8c4fd9 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 @@ -38,8 +38,8 @@ class IPCServer: @daemon_threaded def create_ipc_listener(self) -> None: if self._conn_type == "socket": - if os.path.exists(self._ipc_address): - return + if os.path.exists(self._ipc_address) and settings.is_dirty_start(): + os.unlink(self._ipc_address) listener = Listener(address=self._ipc_address, family="AF_UNIX", authkey=self._ipc_authkey) elif "unsecured" not in self._conn_type: diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/utils/settings.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/utils/settings.py index 0967a25..392b672 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/utils/settings.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/utils/settings.py @@ -31,6 +31,7 @@ class Settings: self._KEY_BINDINGS = f"{self._CONFIG_PATH}/key-bindings.json" self._DEFAULT_ICONS = f"{self._CONFIG_PATH}/icons" self._WINDOW_ICON = f"{self._DEFAULT_ICONS}/{app_name.lower()}.png" + self._PID_FILE = f"{self._CONFIG_PATH}/solarfm.pid" self._ICON_THEME = Gtk.IconTheme.get_default() if not os.path.exists(self._CONFIG_PATH): @@ -65,6 +66,44 @@ class Settings: self._trace_debug = False self._debug = False + self._dirty_start = False + + self._check_for_dirty_state() + + + def _check_for_dirty_state(self): + if not os.path.exists(self._PID_FILE): + self._write_new_pid() + else: + with open(self._PID_FILE, "r") as _pid: + pid = _pid.readline().strip() + if pid not in ("", None): + self._check_alive_status(int(pid)) + else: + self._write_new_pid() + + """ Check For the existence of a unix pid. """ + def _check_alive_status(self, pid): + print(f"PID Found: {pid}") + try: + os.kill(pid, 0) + except OSError: + print("SolarFM Is starting dirty...") + self._dirty_start = True + self._write_new_pid() + + print("PID is alive... Let downstream errors handle app closure.") + + def _write_new_pid(self): + pid = os.getpid() + self._write_pid(pid) + + def _clean_pid(self): + os.unlink(self._PID_FILE) + + def _write_pid(self, pid): + with open(self._PID_FILE, "w") as _pid: + _pid.write(f"{pid}") def create_window(self) -> None: @@ -104,6 +143,7 @@ class Settings: return monitors + def get_main_window(self) -> Gtk.ApplicationWindow: return self._main_window def get_builder(self) -> Gtk.Builder: return self._builder def get_logger(self) -> Logger: return self._logger @@ -117,6 +157,8 @@ class Settings: def is_trace_debug(self) -> str: return self._trace_debug def is_debug(self) -> str: return self._debug + def is_dirty_start(self) -> bool: return self._dirty_start + def clear_pid(self): self._clean_pid() def set_trace_debug(self, trace_debug): diff --git a/user_config/usr/share/solarfm/Main_Window.glade b/user_config/usr/share/solarfm/Main_Window.glade index d102e67..fa62070 100644 --- a/user_config/usr/share/solarfm/Main_Window.glade +++ b/user_config/usr/share/solarfm/Main_Window.glade @@ -740,23 +740,6 @@ SolarFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspe 4 - - - Archive - archive - True - True - True - Archive... - True - - - - False - True - 5 - - @@ -1079,17 +1062,6 @@ SolarFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspe - - - gtk-delete - delete - True - False - True - True - - -