From 372e4ff3dcdddad65a16aa9cf6a860e1ed7f9876 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Thu, 9 Feb 2023 20:55:21 -0600 Subject: [PATCH] Shellfm updates --- .../shellfm/windows/tabs/icons/icon.py | 20 ++++--- .../solarfm/shellfm/windows/tabs/tab.py | 52 ++++++++++++++++--- .../shellfm/windows/tabs/utils/filehandler.py | 4 +- .../shellfm/windows/tabs/utils/settings.py | 10 ++-- 4 files changed, 64 insertions(+), 22 deletions(-) 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 fe9d677..c06e2be 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 @@ -57,12 +57,15 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin): return self.get_generic_icon() - def create_blender_thumbnail(self, full_path): + def create_blender_thumbnail(self, full_path, returnHashInstead=False): try: - path_exists, hash_img_path = self.generate_hash_and_path(full_path) + path_exists, img_hash, hash_img_path = self.generate_hash_and_path(full_path) if not path_exists: self.generate_blender_thumbnail(full_path, hash_img_path) + if returnHashInstead: + return img_hash, hash_img_path + return self.create_scaled_image(hash_img_path, self.video_icon_wh) except IconException as e: print("Blender thumbnail generation issue:") @@ -70,9 +73,9 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin): return None - def create_video_thumbnail(self, full_path, scrub_percent = "65%", replace=False): + def create_video_thumbnail(self, full_path, scrub_percent = "65%", replace=False, returnHashInstead=False): try: - path_exists, hash_img_path = self.generate_hash_and_path(full_path) + path_exists, img_hash, hash_img_path = self.generate_hash_and_path(full_path) if path_exists and replace: os.remove(hash_img_path) path_exists = False @@ -80,6 +83,9 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin): if not path_exists: self.generate_video_thumbnail(full_path, hash_img_path, scrub_percent) + if returnHashInstead: + return img_hash, hash_img_path + return self.create_scaled_image(hash_img_path, self.video_icon_wh) except IconException as e: print("Image/Video thumbnail generation issue:") @@ -150,11 +156,11 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin): return GdkPixbuf.Pixbuf.new_from_file(self.DEFAULT_ICON) def generate_hash_and_path(self, full_path): - file_hash = self.fast_hash(full_path) - hash_img_path = f"{self.ABS_THUMBS_PTH}/{file_hash}.jpg" + img_hash = self.fast_hash(full_path) + hash_img_path = f"{self.ABS_THUMBS_PTH}/{img_hash}.jpg" path_exists = True if isfile(hash_img_path) else False - return path_exists, hash_img_path + return path_exists, img_hash, hash_img_path def fast_hash(self, filename, hash_factory=hashlib.md5, chunk_num_blocks=128, i=1): diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/tab.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/tab.py index 1f78dec..6a05f28 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/tab.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/tab.py @@ -1,4 +1,5 @@ # Python imports +import os import hashlib import re from os import listdir @@ -17,6 +18,23 @@ from .icons.icon import Icon from .path import Path +try: + get_file_size("/") +except Exception as e: + import os + + def sizeof_fmt_def(num, suffix="B"): + for unit in ["", "K", "M", "G", "T", "Pi", "Ei", "Zi"]: + if abs(num) < 1024.0: + return f"{num:3.1f} {unit}{suffix}" + num /= 1024.0 + return f"{num:.1f} Yi{suffix}" + + def _get_file_size(file): + return "4K" if isdir(file) else sizeof_fmt_def(os.path.getsize(file)) + + get_file_size = _get_file_size + class Tab(Settings, FileHandler, Launcher, Icon, Path): @@ -26,6 +44,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path): self._id: str = "" self._wid: str = None + self.error_message: str = None self._dir_watcher = None self._hide_hidden: bool = self.HIDE_HIDDEN_FILES self._files: list = [] @@ -50,6 +69,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path): self._files = [] if not isdir(path): + self._set_error_message("Path can not be accessed.") self.set_to_home() return "" @@ -145,6 +165,15 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path): } } + def get_video_icons(self) -> list: + data = [] + dir = self.get_current_directory() + for file in self._vids: + img_hash, hash_img_path = self.create_video_thumbnail(full_path=f"{dir}/{file}", returnHashInstead=True) + data.append([img_hash, hash_img_path]) + + return data + def get_pixbuf_icon_str_combo(self): data = [] dir = self.get_current_directory() @@ -154,7 +183,6 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path): return data - def get_gtk_icon_str_combo(self) -> list: data = [] dir = self.get_current_directory() @@ -223,24 +251,31 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path): def get_dir_watcher(self): return self._dir_watcher - def _atoi(self, text): - return int(text) if text.isnumeric() else text + def get_error_message(self): + return self.error_message - def _atof(self, text): - return float(text) if text.isnumeric() else text + def unset_error_message(self): + self.error_message = None + + def _atoi(self, text): + return int(text) if text.isdigit() else text def _natural_keys(self, text): - return [ self._atof(c) for c in re.split('(\d+)', text) ] + return [ self._atoi(c) for c in re.split('(\d+)',text) ] def _hash_text(self, text) -> str: return hashlib.sha256(str.encode(text)).hexdigest()[:18] def _hash_set(self, arry: list) -> list: + path = self.get_current_directory() data = [] for arr in arry: - data.append([arr, self._hash_text(arr)]) + file = f"{path}/{arr}" + size = get_file_size(file) + data.append([arr, self._hash_text(arr), size]) return data + def _random_with_N_digits(self, n: int) -> int: range_start = 10**(n-1) range_end = (10**n)-1 @@ -248,3 +283,6 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path): def _generate_id(self) -> str: self._id = str(self._random_with_N_digits(self._id_length)) + + def _set_error_message(self, text: str): + self.error_message = text diff --git a/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/utils/filehandler.py b/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/utils/filehandler.py index 3855e24..750ed2c 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/utils/filehandler.py +++ b/src/versions/solarfm-0.0.1/SolarFM/solarfm/shellfm/windows/tabs/utils/filehandler.py @@ -12,9 +12,9 @@ import shutil class FileHandler: def create_file(self, nFile, type): try: - if TYPE == "dir": + if type == "dir": os.mkdir(nFile) - elif TYPE == "file": + elif type == "file": open(nFile, 'a').close() except Exception as e: print("An error occured creating the file/dir:") 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 6c6e7d9..b08809d 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 @@ -5,7 +5,6 @@ from os import path # Lib imports - # Apoplication imports @@ -13,7 +12,6 @@ from os import path class Settings: logger = None - USR_SOLARFM = "/usr/share/solarfm" USER_HOME = path.expanduser('~') CONFIG_PATH = f"{USER_HOME}/.config/solarfm" @@ -24,7 +22,7 @@ class Settings: DEFAULT_ICONS = f"{CONFIG_PATH}/icons" DEFAULT_ICON = f"{DEFAULT_ICONS}/text.png" FFMPG_THUMBNLR = f"{CONFIG_PATH}/ffmpegthumbnailer" # Thumbnail generator binary - BLENDER_THUMBNLR = f"{CONFIG_PATH}/blender-thumbnailer" # Blender thumbnail generator binary + BLENDER_THUMBNLR = f"{CONFIG_PATH}/blender-thumbnailer" # Blender thumbnail generator binary REMUX_FOLDER = f"{USER_HOME}/.remuxs" # Remuxed files folder ICON_DIRS = ["/usr/share/icons", f"{USER_HOME}/.icons" "/usr/share/pixmaps"] @@ -57,9 +55,9 @@ class Settings: STEAM_CDN_URL = config["steam_cdn_url"] FFMPG_THUMBNLR = FFMPG_THUMBNLR if config["thumbnailer_path"] == "" else config["thumbnailer_path"] BLENDER_THUMBNLR = BLENDER_THUMBNLR if config["blender_thumbnailer_path"] == "" else config["blender_thumbnailer_path"] - HIDE_HIDDEN_FILES = True if config["hide_hidden_files"] == "true" else False - go_past_home = True if config["go_past_home"] == "" else config["go_past_home"] - lock_folder = True if config["lock_folder"] == "true" else False + HIDE_HIDDEN_FILES = True if config["hide_hidden_files"] in ["true", ""] else False + go_past_home = True if config["go_past_home"] in ["true", ""] else False + lock_folder = False if config["lock_folder"] in ["false", ""] else True locked_folders = config["locked_folders"].split("::::") mplayer_options = config["mplayer_options"].split() music_app = config["music_app"]