Updated Launcher, made Settings more generic, updated config file

This commit is contained in:
itdominator 2023-02-21 13:15:00 -06:00
parent 2fa207f5fc
commit 2029fbbca9
5 changed files with 78 additions and 30 deletions

View File

@ -1,6 +1,34 @@
# Python imports
import builtins
import threading
# NOTE: Threads WILL NOT die with parent's destruction.
def threaded_wrapper(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
return wrapper
# NOTE: Threads WILL die with parent's destruction.
def daemon_threaded_wrapper(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
return wrapper
# NOTE: Defined for ShellFM
builtins.threaded = threaded_wrapper
builtins.daemon_threaded = daemon_threaded_wrapper
# Lib imports
# Apoplication imports
from shellfm.windows.controller import WindowController from shellfm.windows.controller import WindowController
def main(): def main():
print("\n\n-------------------------------------------\n\n") print("\n\n-------------------------------------------\n\n")
window_controller = WindowController() window_controller = WindowController()

View File

@ -1,13 +1,15 @@
# Python imports # Python imports
import os import os
import subprocess import subprocess
import shlex
# Lib imports # Lib imports
# Apoplication imports # Apoplication imports
class ShellFMLauncherException(Exception):
...
class Launcher: class Launcher:
@ -16,12 +18,7 @@ class Launcher:
command = [] command = []
if lowerName.endswith(self.fvideos): if lowerName.endswith(self.fvideos):
command = [self.media_app] command = [self.media_app, file]
if "mplayer" in self.media_app:
command += self.mplayer_options
command += [file]
elif lowerName.endswith(self.fimages): elif lowerName.endswith(self.fimages):
command = [self.image_app, file] command = [self.image_app, file]
elif lowerName.endswith(self.fmusic): elif lowerName.endswith(self.fmusic):
@ -43,20 +40,29 @@ class Launcher:
def execute(self, command, start_dir=os.getenv("HOME"), use_shell=False): def execute(self, command, start_dir=os.getenv("HOME"), use_shell=False):
self.logger.debug(command) try:
subprocess.Popen(command, cwd=start_dir, shell=use_shell, start_new_session=True, stdout=None, stderr=None, close_fds=True) self.logger.debug(command)
subprocess.Popen(command, cwd=start_dir, shell=use_shell, start_new_session=True, stdout=None, stderr=None, close_fds=True)
except ShellFMLauncherException as e:
self.logger.error(f"Couldn't execute: {command}")
self.logger.error(e)
# TODO: Return stdout and in handlers along with subprocess instead of sinking to null # TODO: Return std(out/in/err) handlers along with subprocess instead of sinking to null
def execute_and_return_thread_handler(self, command, start_dir=os.getenv("HOME"), use_shell=False): def execute_and_return_thread_handler(self, command, start_dir=os.getenv("HOME"), use_shell=False):
DEVNULL = open(os.devnull, 'w') try:
return subprocess.Popen(command, cwd=start_dir, shell=use_shell, start_new_session=False, stdout=DEVNULL, stderr=DEVNULL, close_fds=False) DEVNULL = open(os.devnull, 'w')
return subprocess.Popen(command, cwd=start_dir, shell=use_shell, start_new_session=False, stdout=DEVNULL, stderr=DEVNULL, close_fds=False)
except ShellFMLauncherException as e:
self.logger.error(f"Couldn't execute and return thread: {command}")
self.logger.error(e)
return None
@threaded @threaded
def app_chooser_exec(self, app_info, uris): def app_chooser_exec(self, app_info, uris):
app_info.launch_uris_async(uris) app_info.launch_uris_async(uris)
def remux_video(self, hash, file): def remux_video(self, hash, file):
remux_vid_pth = self.REMUX_FOLDER + "/" + hash + ".mp4" remux_vid_pth = "{self.REMUX_FOLDER}/{hash}.mp4"
self.logger.debug(remux_vid_pth) self.logger.debug(remux_vid_pth)
if not os.path.isfile(remux_vid_pth): if not os.path.isfile(remux_vid_pth):
@ -76,9 +82,9 @@ class Launcher:
try: try:
proc = subprocess.Popen(command) proc = subprocess.Popen(command)
proc.wait() proc.wait()
except Exception as e: except ShellFMLauncherException as e:
self.logger.debug(message) self.logger.error(message)
self.logger.debug(e) self.logger.error(e)
return False return False
return True return True
@ -87,7 +93,7 @@ class Launcher:
limit = self.remux_folder_max_disk_usage limit = self.remux_folder_max_disk_usage
try: try:
limit = int(limit) limit = int(limit)
except Exception as e: except ShellFMLauncherException as e:
self.logger.debug(e) self.logger.debug(e)
return return

View File

@ -8,18 +8,29 @@ from os import path
# Apoplication imports # Apoplication imports
class ShellFMSettingsException(Exception):
...
class Settings: class Settings:
logger = None logger = None
USR_SHELLFM = "/usr/share/shellfm" # NOTE: app_name should be defined using python 'builtins'
app_name_exists = False
try:
app_name
app_name_exists = True
except Exception as e:
...
APP_CONTEXT = f"{app_name.lower()}" if app_name_exists else "shellfm"
USR_APP_CONTEXT = f"/usr/share/{APP_CONTEXT}"
USER_HOME = path.expanduser('~') USER_HOME = path.expanduser('~')
CONFIG_PATH = f"{USER_HOME}/.config/shellfm" CONFIG_PATH = f"{USER_HOME}/.config/{APP_CONTEXT}"
CONFIG_FILE = f"{CONFIG_PATH}/settings.json" CONFIG_FILE = f"{CONFIG_PATH}/settings.json"
HIDE_HIDDEN_FILES = True HIDE_HIDDEN_FILES = True
GTK_ORIENTATION = 1 # HORIZONTAL (0) VERTICAL (1)
DEFAULT_ICONS = f"{CONFIG_PATH}/icons" DEFAULT_ICONS = f"{CONFIG_PATH}/icons"
DEFAULT_ICON = f"{DEFAULT_ICONS}/text.png" DEFAULT_ICON = f"{DEFAULT_ICONS}/text.png"
FFMPG_THUMBNLR = f"{CONFIG_PATH}/ffmpegthumbnailer" # Thumbnail generator binary FFMPG_THUMBNLR = f"{CONFIG_PATH}/ffmpegthumbnailer" # Thumbnail generator binary
@ -27,11 +38,14 @@ class Settings:
REMUX_FOLDER = f"{USER_HOME}/.remuxs" # Remuxed files folder REMUX_FOLDER = f"{USER_HOME}/.remuxs" # Remuxed files folder
ICON_DIRS = ["/usr/share/icons", f"{USER_HOME}/.icons" "/usr/share/pixmaps"] ICON_DIRS = ["/usr/share/icons", f"{USER_HOME}/.icons" "/usr/share/pixmaps"]
BASE_THUMBS_PTH = f"{USER_HOME}/.thumbnails" # Used for thumbnail generation BASE_THUMBS_PTH = f"{USER_HOME}/.thumbnails"
ABS_THUMBS_PTH = f"{BASE_THUMBS_PTH}/normal" # Used for thumbnail generation ABS_THUMBS_PTH = f"{BASE_THUMBS_PTH}/normal"
STEAM_ICONS_PTH = f"{BASE_THUMBS_PTH}/steam_icons" STEAM_ICONS_PTH = f"{BASE_THUMBS_PTH}/steam_icons"
# Dir structure check if not os.path.exists(CONFIG_PATH) or not os.path.exists(CONFIG_FILE):
msg = f"No config file located! Aborting loading ShellFM library...\nExpected: {CONFIG_FILE}"
raise ShellFMSettingsException(msg)
if not path.isdir(REMUX_FOLDER): if not path.isdir(REMUX_FOLDER):
os.mkdir(REMUX_FOLDER) os.mkdir(REMUX_FOLDER)
@ -45,7 +59,7 @@ class Settings:
os.mkdir(STEAM_ICONS_PTH) os.mkdir(STEAM_ICONS_PTH)
if not os.path.exists(DEFAULT_ICONS): if not os.path.exists(DEFAULT_ICONS):
DEFAULT_ICONS = f"{USR_SHELLFM}/icons" DEFAULT_ICONS = f"{USR_APP_CONTEXT}/icons"
DEFAULT_ICON = f"{DEFAULT_ICONS}/text.png" DEFAULT_ICON = f"{DEFAULT_ICONS}/text.png"
with open(CONFIG_FILE) as f: with open(CONFIG_FILE) as f:

View File

@ -8,24 +8,24 @@
"lock_folder": "false", "lock_folder": "false",
"locked_folders": "venv::::flasks", "locked_folders": "venv::::flasks",
"mplayer_options": "-quiet -really-quiet -xy 1600 -geometry 50%:50%", "mplayer_options": "-quiet -really-quiet -xy 1600 -geometry 50%:50%",
"music_app": "/opt/deadbeef/bin/deadbeef", "music_app": "deadbeef",
"media_app": "mpv", "media_app": "mpv",
"image_app": "mirage", "image_app": "mirage2",
"office_app": "libreoffice", "office_app": "libreoffice",
"pdf_app": "evince", "pdf_app": "evince",
"code_app": "mousepad", "code_app": "atom",
"text_app": "leafpad", "text_app": "mousepad",
"terminal_app": "terminator", "terminal_app": "terminator",
"container_icon_wh": [128, 128], "container_icon_wh": [128, 128],
"video_icon_wh": [128, 64], "video_icon_wh": [128, 64],
"sys_icon_wh": [56, 56], "sys_icon_wh": [56, 56],
"file_manager_app": "spacefm", "file_manager_app": "solarfm",
"steam_cdn_url": "https://steamcdn-a.akamaihd.net/steam/apps/", "steam_cdn_url": "https://steamcdn-a.akamaihd.net/steam/apps/",
"remux_folder_max_disk_usage": "8589934592" "remux_folder_max_disk_usage": "8589934592"
}, },
"filters": { "filters": {
"meshs": [".dae", ".fbx", ".gltf", ".obj", ".stl"], "meshs": [".dae", ".fbx", ".gltf", ".obj", ".stl"],
"code": [".cpp", ".css", ".c", ".go", ".html", ".htm", ".java", ".js", ".json", ".lua", ".md", ".py", ".rs"], "code": [".cpp", ".css", ".c", ".go", ".html", ".htm", ".java", ".js", ".json", ".lua", ".md", ".py", ".rs", ".toml", ".xml", ".pom"],
"videos": [".mkv", ".mp4", ".webm", ".avi", ".mov", ".m4v", ".mpg", ".mpeg", ".wmv", ".flv"], "videos": [".mkv", ".mp4", ".webm", ".avi", ".mov", ".m4v", ".mpg", ".mpeg", ".wmv", ".flv"],
"office": [".doc", ".docx", ".xls", ".xlsx", ".xlt", ".xltx", ".xlm", ".ppt", ".pptx", ".pps", ".ppsx", ".odt", ".rtf"], "office": [".doc", ".docx", ".xls", ".xlsx", ".xlt", ".xltx", ".xlm", ".ppt", ".pptx", ".pps", ".ppsx", ".odt", ".rtf"],
"images": [".png", ".jpg", ".jpeg", ".gif", ".ico", ".tga", ".webp"], "images": [".png", ".jpg", ".jpeg", ".gif", ".ico", ".tga", ".webp"],