Shellfm updates
This commit is contained in:
parent
d9b471cbaa
commit
372e4ff3dc
|
@ -57,12 +57,15 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin):
|
||||||
|
|
||||||
return self.get_generic_icon()
|
return self.get_generic_icon()
|
||||||
|
|
||||||
def create_blender_thumbnail(self, full_path):
|
def create_blender_thumbnail(self, full_path, returnHashInstead=False):
|
||||||
try:
|
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:
|
if not path_exists:
|
||||||
self.generate_blender_thumbnail(full_path, hash_img_path)
|
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)
|
return self.create_scaled_image(hash_img_path, self.video_icon_wh)
|
||||||
except IconException as e:
|
except IconException as e:
|
||||||
print("Blender thumbnail generation issue:")
|
print("Blender thumbnail generation issue:")
|
||||||
|
@ -70,9 +73,9 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin):
|
||||||
|
|
||||||
return None
|
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:
|
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:
|
if path_exists and replace:
|
||||||
os.remove(hash_img_path)
|
os.remove(hash_img_path)
|
||||||
path_exists = False
|
path_exists = False
|
||||||
|
@ -80,6 +83,9 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin):
|
||||||
if not path_exists:
|
if not path_exists:
|
||||||
self.generate_video_thumbnail(full_path, hash_img_path, scrub_percent)
|
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)
|
return self.create_scaled_image(hash_img_path, self.video_icon_wh)
|
||||||
except IconException as e:
|
except IconException as e:
|
||||||
print("Image/Video thumbnail generation issue:")
|
print("Image/Video thumbnail generation issue:")
|
||||||
|
@ -150,11 +156,11 @@ class Icon(DesktopIconMixin, VideoIconMixin, MeshsIconMixin):
|
||||||
return GdkPixbuf.Pixbuf.new_from_file(self.DEFAULT_ICON)
|
return GdkPixbuf.Pixbuf.new_from_file(self.DEFAULT_ICON)
|
||||||
|
|
||||||
def generate_hash_and_path(self, full_path):
|
def generate_hash_and_path(self, full_path):
|
||||||
file_hash = self.fast_hash(full_path)
|
img_hash = self.fast_hash(full_path)
|
||||||
hash_img_path = f"{self.ABS_THUMBS_PTH}/{file_hash}.jpg"
|
hash_img_path = f"{self.ABS_THUMBS_PTH}/{img_hash}.jpg"
|
||||||
path_exists = True if isfile(hash_img_path) else False
|
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):
|
def fast_hash(self, filename, hash_factory=hashlib.md5, chunk_num_blocks=128, i=1):
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# Python imports
|
# Python imports
|
||||||
|
import os
|
||||||
import hashlib
|
import hashlib
|
||||||
import re
|
import re
|
||||||
from os import listdir
|
from os import listdir
|
||||||
|
@ -17,6 +18,23 @@ from .icons.icon import Icon
|
||||||
from .path import Path
|
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):
|
class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
||||||
|
@ -26,6 +44,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
||||||
|
|
||||||
self._id: str = ""
|
self._id: str = ""
|
||||||
self._wid: str = None
|
self._wid: str = None
|
||||||
|
self.error_message: str = None
|
||||||
self._dir_watcher = None
|
self._dir_watcher = None
|
||||||
self._hide_hidden: bool = self.HIDE_HIDDEN_FILES
|
self._hide_hidden: bool = self.HIDE_HIDDEN_FILES
|
||||||
self._files: list = []
|
self._files: list = []
|
||||||
|
@ -50,6 +69,7 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
||||||
self._files = []
|
self._files = []
|
||||||
|
|
||||||
if not isdir(path):
|
if not isdir(path):
|
||||||
|
self._set_error_message("Path can not be accessed.")
|
||||||
self.set_to_home()
|
self.set_to_home()
|
||||||
return ""
|
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):
|
def get_pixbuf_icon_str_combo(self):
|
||||||
data = []
|
data = []
|
||||||
dir = self.get_current_directory()
|
dir = self.get_current_directory()
|
||||||
|
@ -154,7 +183,6 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def get_gtk_icon_str_combo(self) -> list:
|
def get_gtk_icon_str_combo(self) -> list:
|
||||||
data = []
|
data = []
|
||||||
dir = self.get_current_directory()
|
dir = self.get_current_directory()
|
||||||
|
@ -223,24 +251,31 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
||||||
def get_dir_watcher(self):
|
def get_dir_watcher(self):
|
||||||
return self._dir_watcher
|
return self._dir_watcher
|
||||||
|
|
||||||
def _atoi(self, text):
|
def get_error_message(self):
|
||||||
return int(text) if text.isnumeric() else text
|
return self.error_message
|
||||||
|
|
||||||
def _atof(self, text):
|
def unset_error_message(self):
|
||||||
return float(text) if text.isnumeric() else text
|
self.error_message = None
|
||||||
|
|
||||||
|
def _atoi(self, text):
|
||||||
|
return int(text) if text.isdigit() else text
|
||||||
|
|
||||||
def _natural_keys(self, 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:
|
def _hash_text(self, text) -> str:
|
||||||
return hashlib.sha256(str.encode(text)).hexdigest()[:18]
|
return hashlib.sha256(str.encode(text)).hexdigest()[:18]
|
||||||
|
|
||||||
def _hash_set(self, arry: list) -> list:
|
def _hash_set(self, arry: list) -> list:
|
||||||
|
path = self.get_current_directory()
|
||||||
data = []
|
data = []
|
||||||
for arr in arry:
|
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
|
return data
|
||||||
|
|
||||||
|
|
||||||
def _random_with_N_digits(self, n: int) -> int:
|
def _random_with_N_digits(self, n: int) -> int:
|
||||||
range_start = 10**(n-1)
|
range_start = 10**(n-1)
|
||||||
range_end = (10**n)-1
|
range_end = (10**n)-1
|
||||||
|
@ -248,3 +283,6 @@ class Tab(Settings, FileHandler, Launcher, Icon, Path):
|
||||||
|
|
||||||
def _generate_id(self) -> str:
|
def _generate_id(self) -> str:
|
||||||
self._id = str(self._random_with_N_digits(self._id_length))
|
self._id = str(self._random_with_N_digits(self._id_length))
|
||||||
|
|
||||||
|
def _set_error_message(self, text: str):
|
||||||
|
self.error_message = text
|
||||||
|
|
|
@ -12,9 +12,9 @@ import shutil
|
||||||
class FileHandler:
|
class FileHandler:
|
||||||
def create_file(self, nFile, type):
|
def create_file(self, nFile, type):
|
||||||
try:
|
try:
|
||||||
if TYPE == "dir":
|
if type == "dir":
|
||||||
os.mkdir(nFile)
|
os.mkdir(nFile)
|
||||||
elif TYPE == "file":
|
elif type == "file":
|
||||||
open(nFile, 'a').close()
|
open(nFile, 'a').close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("An error occured creating the file/dir:")
|
print("An error occured creating the file/dir:")
|
||||||
|
|
|
@ -5,7 +5,6 @@ from os import path
|
||||||
|
|
||||||
# Lib imports
|
# Lib imports
|
||||||
|
|
||||||
|
|
||||||
# Apoplication imports
|
# Apoplication imports
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +12,6 @@ from os import path
|
||||||
|
|
||||||
class Settings:
|
class Settings:
|
||||||
logger = None
|
logger = None
|
||||||
|
|
||||||
USR_SOLARFM = "/usr/share/solarfm"
|
USR_SOLARFM = "/usr/share/solarfm"
|
||||||
USER_HOME = path.expanduser('~')
|
USER_HOME = path.expanduser('~')
|
||||||
CONFIG_PATH = f"{USER_HOME}/.config/solarfm"
|
CONFIG_PATH = f"{USER_HOME}/.config/solarfm"
|
||||||
|
@ -57,9 +55,9 @@ class Settings:
|
||||||
STEAM_CDN_URL = config["steam_cdn_url"]
|
STEAM_CDN_URL = config["steam_cdn_url"]
|
||||||
FFMPG_THUMBNLR = FFMPG_THUMBNLR if config["thumbnailer_path"] == "" else config["thumbnailer_path"]
|
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"]
|
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
|
HIDE_HIDDEN_FILES = True if config["hide_hidden_files"] in ["true", ""] else False
|
||||||
go_past_home = True if config["go_past_home"] == "" else config["go_past_home"]
|
go_past_home = True if config["go_past_home"] in ["true", ""] else False
|
||||||
lock_folder = True if config["lock_folder"] == "true" else False
|
lock_folder = False if config["lock_folder"] in ["false", ""] else True
|
||||||
locked_folders = config["locked_folders"].split("::::")
|
locked_folders = config["locked_folders"].split("::::")
|
||||||
mplayer_options = config["mplayer_options"].split()
|
mplayer_options = config["mplayer_options"].split()
|
||||||
music_app = config["music_app"]
|
music_app = config["music_app"]
|
||||||
|
|
Loading…
Reference in New Issue