From 440514d3af43743dd55c045ce9dcae7ef6b57ec6 Mon Sep 17 00:00:00 2001 From: Nils <> Date: Thu, 8 Jul 2021 23:54:29 +0200 Subject: [PATCH] better discovery for client icons --- engine/findicons.py | 28 +++++++++++++++++++++++++--- qtgui/sessiontreecontroller.py | 2 -- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/engine/findicons.py b/engine/findicons.py index ef520d4..9b93d34 100644 --- a/engine/findicons.py +++ b/engine/findicons.py @@ -35,6 +35,8 @@ $XDG_DATA_DIRS/icons /usr/share/pixmaps """ +EXTENSIONS = [".png", ".xpm", ".svg"] + SEARCH_DIRECTORIES = [pathlib.Path(pathlib.Path.home(), ".icons")] XDG_DATA_DIRS = getenv("XDG_DATA_DIRS") #colon : separated, most likely empty @@ -47,6 +49,8 @@ else: SEARCH_DIRECTORIES += [pathlib.Path(p, "icons/scalable") for p in "/usr/local/share/:/usr/share/".split(":")] SEARCH_DIRECTORIES.append(pathlib.Path("/usr/share/pixmaps")) +SEARCH_DIRECTORIES.append(pathlib.Path("/usr/share/icons")) #for icons wrongly put directly there. +SEARCH_DIRECTORIES.append(pathlib.Path("/usr/local/share/icons")) #for icons wrongly put directly there. SEARCH_DIRECTORIES = set(p.resolve() for p in SEARCH_DIRECTORIES) #resolve follows symlinks, set() makes it unique @@ -82,7 +86,7 @@ def run_fast_scandir(dir, ext): def _buildCache()->set: result = [] for basePath in SEARCH_DIRECTORIES: - forget, files = run_fast_scandir(basePath, [".png", ".xpm", ".svg"]) + forget, files = run_fast_scandir(basePath, EXTENSIONS) result += files #Convert str to real paths @@ -112,7 +116,10 @@ def getSerializedCache()->list: #list of strings, not paths. This is for saving rePattern = re.compile("\d+x\d+") #we don't put .* around this because we are searching for the subpattern def findIconPath(executableName:str)->list: - """Return order is: svg first, then highest resolution first, then the rest unordered. + """ + Parameter executableName can be a direct icon name as well, from the .desktop icon path. + + Return order is: svg first, then highest resolution first, then the rest unordered. so you can use result[0] for the best variant. It is not guaranteed that [1], or even [0] exists. This is not a sorted list, these extra variants are just added to the front of the list again""" @@ -124,6 +131,17 @@ def findIconPath(executableName:str)->list: bestr = 0 #resolution best = None + #Did we get an icon name directly? Remove the extension + #For example "ams_32.xpm" becomes "ams_32" + exeAsPath = pathlib.Path(executableName) + if exeAsPath.suffix in EXTENSIONS: + print (executableName, "to", exeAsPath.stem) + executableName = exeAsPath.stem + + #for ext in EXTENSIONS: #all extensions + # if executableName.endswith(ext): + # executableName = executableName[:-4] + result = [] for f in _cache: if f.stem == executableName: @@ -138,11 +156,15 @@ def findIconPath(executableName:str)->list: best = f result.append(f) + if best: result.insert(0, best) if svg: result.insert(0, svg) + if not result: + logger.warning(f"Did not find an icon for {executableName}") + return result if __name__ == "__main__": @@ -154,7 +176,7 @@ if __name__ == "__main__": print(SEARCH_DIRECTORIES) print() - for exe in ("zynaddsubfx", "patroneo", "jack_mixer", "carla", "ardour6", "synthv1"): + for exe in ("zynaddsubfx", "patroneo", "jack_mixer", "carla", "ardour6", "synthv1", "ams_32.xpm"): r = findIconPath(exe) if r: print (f"{exe} Best resolution: {r[0]}") diff --git a/qtgui/sessiontreecontroller.py b/qtgui/sessiontreecontroller.py index 02a6a99..4830121 100644 --- a/qtgui/sessiontreecontroller.py +++ b/qtgui/sessiontreecontroller.py @@ -316,8 +316,6 @@ class SessionTreeController(object): else: sessionSelectedState = True - print (self.treeWidget.currentItem()) - self.mainWindow.ui.button_load_selected_session.setEnabled(sessionSelectedState) self.mainWindow.ui.button_copy_selected_session.setEnabled(sessionSelectedState) self.mainWindow.ui.button_rename_selected_session.setEnabled(sessionSelectedState)