externalized settings, cleanup
This commit is contained in:
parent
14c601be0a
commit
38464c84b9
|
@ -30,7 +30,7 @@ class Icon(DesktopIconMixin, VideoIconMixin):
|
|||
if file.lower().endswith(self.fvideos): # Video icon
|
||||
thumbnl = self.create_thumbnail(dir, file)
|
||||
elif file.lower().endswith(self.fimages): # Image Icon
|
||||
thumbnl = self.create_scaled_image(full_path, self.VIDEO_ICON_WH)
|
||||
thumbnl = self.create_scaled_image(full_path, self.video_icon_wh)
|
||||
elif full_path.lower().endswith( ('.desktop',) ): # .desktop file parsing
|
||||
thumbnl = self.parse_desktop_files(full_path)
|
||||
|
||||
|
@ -46,7 +46,7 @@ class Icon(DesktopIconMixin, VideoIconMixin):
|
|||
if isfile(hash_img_pth) == False:
|
||||
self.generate_video_thumbnail(full_path, hash_img_pth)
|
||||
|
||||
thumbnl = self.create_scaled_image(hash_img_pth, self.VIDEO_ICON_WH)
|
||||
thumbnl = self.create_scaled_image(hash_img_pth, self.video_icon_wh)
|
||||
if thumbnl == None: # If no icon whatsoever, return internal default
|
||||
thumbnl = GdkPixbuf.Pixbuf.new_from_file(f"{self.DEFAULT_ICONS}/video.png")
|
||||
|
||||
|
|
|
@ -18,23 +18,23 @@ class DesktopIconMixin:
|
|||
if "steam" in icon:
|
||||
name = xdgObj.getName()
|
||||
file_hash = hashlib.sha256(str.encode(name)).hexdigest()
|
||||
hash_img_pth = self.STEAM_ICONS_PTH + "/" + file_hash + ".jpg"
|
||||
hash_img_pth = f"{self.STEAM_ICONS_PTH}/{file_hash}.jpg"
|
||||
|
||||
if isfile(hash_img_pth) == True:
|
||||
# Use video sizes since headers are bigger
|
||||
return self.create_scaled_image(hash_img_pth, self.VIDEO_ICON_WH)
|
||||
return self.create_scaled_image(hash_img_pth, self.video_icon_wh)
|
||||
|
||||
exec_str = xdgObj.getExec()
|
||||
parts = exec_str.split("steam://rungameid/")
|
||||
id = parts[len(parts) - 1]
|
||||
imageLink = self.STEAM_BASE_URL + id + "/header.jpg"
|
||||
imageLink = f"{self.STEAM_CDN_URL}{id}/header.jpg"
|
||||
proc = subprocess.Popen(["wget", "-O", hash_img_pth, imageLink])
|
||||
proc.wait()
|
||||
|
||||
# Use video thumbnail sizes since headers are bigger
|
||||
return self.create_scaled_image(hash_img_pth, self.VIDEO_ICON_WH)
|
||||
return self.create_scaled_image(hash_img_pth, self.video_icon_wh)
|
||||
elif os.path.exists(icon):
|
||||
return self.create_scaled_image(icon, self.SYS_ICON_WH)
|
||||
return self.create_scaled_image(icon, self.sys_icon_wh)
|
||||
else:
|
||||
alt_icon_path = ""
|
||||
|
||||
|
@ -43,7 +43,7 @@ class DesktopIconMixin:
|
|||
if alt_icon_path != "":
|
||||
break
|
||||
|
||||
return self.create_scaled_image(alt_icon_path, self.SYS_ICON_WH)
|
||||
return self.create_scaled_image(alt_icon_path, self.sys_icon_wh)
|
||||
except Exception as e:
|
||||
print(".desktop icon generation issue:")
|
||||
print( repr(e) )
|
||||
|
|
|
@ -31,6 +31,8 @@ class Launcher:
|
|||
command = [self.music_app, file]
|
||||
elif lowerName.endswith(self.foffice):
|
||||
command = [self.office_app, file]
|
||||
elif lowerName.endswith(self.fcode):
|
||||
command = [self.code_app, file]
|
||||
elif lowerName.endswith(self.ftext):
|
||||
command = [self.text_app, file]
|
||||
elif lowerName.endswith(self.fpdf):
|
||||
|
|
|
@ -13,74 +13,22 @@ from os import path
|
|||
class Settings:
|
||||
logger = None
|
||||
|
||||
USR_SOLARFM = "/usr/share/solarfm"
|
||||
USR_SHELLFM = "/usr/share/shellfm"
|
||||
USER_HOME = path.expanduser('~')
|
||||
CONFIG_PATH = f"{USER_HOME}/.config/solarfm"
|
||||
CONFIG_PATH = f"{USER_HOME}/.config/shellfm"
|
||||
CONFIG_FILE = f"{CONFIG_PATH}/settings.json"
|
||||
HIDE_HIDDEN_FILES = True
|
||||
|
||||
GTK_ORIENTATION = 1 # HORIZONTAL (0) VERTICAL (1)
|
||||
GTK_ORIENTATION = 1 # HORIZONTAL (0) VERTICAL (1)
|
||||
DEFAULT_ICONS = f"{CONFIG_PATH}/icons"
|
||||
DEFAULT_ICON = f"{DEFAULT_ICONS}/text.png"
|
||||
FFMPG_THUMBNLR = f"{CONFIG_PATH}/ffmpegthumbnailer" # Thumbnail generator binary
|
||||
REMUX_FOLDER = f"{USER_HOME}/.remuxs" # Remuxed files folder
|
||||
|
||||
STEAM_BASE_URL = "https://steamcdn-a.akamaihd.net/steam/apps/"
|
||||
ICON_DIRS = ["/usr/share/pixmaps", "/usr/share/icons", f"{USER_HOME}/.icons" ,]
|
||||
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"
|
||||
CONTAINER_ICON_WH = [128, 128]
|
||||
VIDEO_ICON_WH = [128, 64]
|
||||
SYS_ICON_WH = [56, 56]
|
||||
|
||||
# CONTAINER_ICON_WH = [128, 128]
|
||||
# VIDEO_ICON_WH = [96, 48]
|
||||
# SYS_ICON_WH = [96, 96]
|
||||
|
||||
subpath = ""
|
||||
go_past_home = None
|
||||
lock_folder = None
|
||||
locked_folders = None
|
||||
mplayer_options = None
|
||||
music_app = None
|
||||
media_app = None
|
||||
image_app = None
|
||||
office_app = None
|
||||
pdf_app = None
|
||||
text_app = None
|
||||
file_manager_app = None
|
||||
remux_folder_max_disk_usage = None
|
||||
|
||||
if path.isfile(CONFIG_FILE):
|
||||
with open(CONFIG_FILE) as infile:
|
||||
settings = json.load(infile)["settings"]
|
||||
|
||||
subpath = settings["base_of_home"]
|
||||
HIDE_HIDDEN_FILES = True if settings["hide_hidden_files"] == "true" else False
|
||||
FFMPG_THUMBNLR = FFMPG_THUMBNLR if settings["thumbnailer_path"] == "" else settings["thumbnailer_path"]
|
||||
go_past_home = True if settings["go_past_home"] == "" else settings["go_past_home"]
|
||||
lock_folder = True if settings["lock_folder"] == "true" else False
|
||||
locked_folders = settings["locked_folders"].split("::::")
|
||||
mplayer_options = settings["mplayer_options"].split()
|
||||
music_app = settings["music_app"]
|
||||
media_app = settings["media_app"]
|
||||
image_app = settings["image_app"]
|
||||
office_app = settings["office_app"]
|
||||
pdf_app = settings["pdf_app"]
|
||||
text_app = settings["text_app"]
|
||||
file_manager_app = settings["file_manager_app"]
|
||||
terminal_app = settings["terminal_app"]
|
||||
remux_folder_max_disk_usage = settings["remux_folder_max_disk_usage"]
|
||||
|
||||
# Filters
|
||||
fvideos = ('.mkv', '.avi', '.flv', '.mov', '.m4v', '.mpg', '.wmv', '.mpeg', '.mp4', '.webm')
|
||||
foffice = ('.doc', '.docx', '.xls', '.xlsx', '.xlt', '.xltx', '.xlm', '.ppt', 'pptx', '.pps', '.ppsx', '.odt', '.rtf')
|
||||
fimages = ('.png', '.jpg', '.jpeg', '.gif', '.ico', '.tga')
|
||||
ftext = ('.txt', '.text', '.sh', '.cfg', '.conf')
|
||||
fmusic = ('.psf', '.mp3', '.ogg', '.flac', '.m4a')
|
||||
fpdf = ('.pdf')
|
||||
|
||||
|
||||
# Dir structure check
|
||||
if not path.isdir(REMUX_FOLDER):
|
||||
|
@ -96,5 +44,41 @@ class Settings:
|
|||
os.mkdir(STEAM_ICONS_PTH)
|
||||
|
||||
if not os.path.exists(DEFAULT_ICONS):
|
||||
DEFAULT_ICONS = f"{USR_SOLARFM}/icons"
|
||||
DEFAULT_ICONS = f"{USR_SHELLFM}/icons"
|
||||
DEFAULT_ICON = f"{DEFAULT_ICONS}/text.png"
|
||||
|
||||
with open(CONFIG_FILE) as f:
|
||||
settings = json.load(f)
|
||||
config = settings["config"]
|
||||
|
||||
subpath = config["base_of_home"]
|
||||
STEAM_CDN_URL = config["steam_cdn_url"]
|
||||
FFMPG_THUMBNLR = FFMPG_THUMBNLR if config["thumbnailer_path"] == "" else config["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
|
||||
locked_folders = config["locked_folders"].split("::::")
|
||||
mplayer_options = config["mplayer_options"].split()
|
||||
music_app = config["music_app"]
|
||||
media_app = config["media_app"]
|
||||
image_app = config["image_app"]
|
||||
office_app = config["office_app"]
|
||||
pdf_app = config["pdf_app"]
|
||||
code_app = config["code_app"]
|
||||
text_app = config["text_app"]
|
||||
terminal_app = config["terminal_app"]
|
||||
container_icon_wh = config["container_icon_wh"]
|
||||
video_icon_wh = config["video_icon_wh"]
|
||||
sys_icon_wh = config["sys_icon_wh"]
|
||||
file_manager_app = config["file_manager_app"]
|
||||
remux_folder_max_disk_usage = config["remux_folder_max_disk_usage"]
|
||||
|
||||
# Filters
|
||||
filters = settings["filters"]
|
||||
fcode = tuple(filters["code"])
|
||||
fvideos = tuple(filters["videos"])
|
||||
foffice = tuple(filters["office"])
|
||||
fimages = tuple(filters["images"])
|
||||
ftext = tuple(filters["text"])
|
||||
fmusic = tuple(filters["music"])
|
||||
fpdf = tuple(filters["pdf"])
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"settings": {
|
||||
"config": {
|
||||
"base_of_home": "",
|
||||
"hide_hidden_files": "true",
|
||||
"thumbnailer_path": "ffmpegthumbnailer",
|
||||
|
@ -12,8 +12,24 @@
|
|||
"image_app": "mirage",
|
||||
"office_app": "libreoffice",
|
||||
"pdf_app": "evince",
|
||||
"code_app": "mousepad",
|
||||
"text_app": "leafpad",
|
||||
"terminal_app": "terminator",
|
||||
"container_icon_wh": [128, 128],
|
||||
"video_icon_wh": [128, 64],
|
||||
"sys_icon_wh": [56, 56],
|
||||
"file_manager_app": "spacefm",
|
||||
"steam_cdn_url": "https://steamcdn-a.akamaihd.net/steam/apps/",
|
||||
"remux_folder_max_disk_usage": "8589934592"
|
||||
}
|
||||
},
|
||||
"filters": {
|
||||
"code": [".cpp", ".css", ".c", ".go", ".html", ".htm", ".java", ".js", ".json", ".lua", ".md", ".py", ".rs"],
|
||||
"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"],
|
||||
"images": [".png", ".jpg", ".jpeg", ".gif", ".ico", ".tga", ".webp"],
|
||||
"text": [".txt", ".text", ".sh", ".cfg", ".conf", ".log"],
|
||||
"music": [".psf", ".mp3", ".ogg", ".flac", ".m4a"],
|
||||
"pdf": [".pdf"]
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue