Browse Source

better discovery for client icons

tags/v0.3.0
Nils 2 months ago
parent
commit
440514d3af
2 changed files with 25 additions and 5 deletions
  1. +25
    -3
      engine/findicons.py
  2. +0
    -2
      qtgui/sessiontreecontroller.py

+ 25
- 3
engine/findicons.py View File

@@ -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]}")

+ 0
- 2
qtgui/sessiontreecontroller.py View File

@@ -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)

Loading…
Cancel
Save