aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2019-06-20 13:51:14 -0400
committerB Stack <bgstack15@gmail.com>2019-06-20 13:51:14 -0400
commitb9713cccba008a57b05313b79d3d86867bdedc4a (patch)
tree2b029813339eb2e7185a2b4fb3d6ef39559ac734
parentWIP: rearrange the photoimage error check (diff)
downloadlogout-manager-b9713cccba008a57b05313b79d3d86867bdedc4a.tar.gz
logout-manager-b9713cccba008a57b05313b79d3d86867bdedc4a.tar.bz2
logout-manager-b9713cccba008a57b05313b79d3d86867bdedc4a.zip
tcl frontend: add full svg support
Now the program can get correct-sized thumbnails as required. This svg support needs to be turned into an option, based on if it could import the dependency.
-rwxr-xr-xlogout-manager-tcl.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/logout-manager-tcl.py b/logout-manager-tcl.py
index 9d8f999..c8ba228 100755
--- a/logout-manager-tcl.py
+++ b/logout-manager-tcl.py
@@ -246,7 +246,7 @@ def get_filename_of_icon(name, theme = "hicolor", size = 48, category = "actions
# first, find all files underneath /usr/share/icons/$THEME/$SIZE
print("Finding filename of icon, theme=",theme,"category=",category,"name=",name)
- # FUTUREIMPROVEMENT: this glob affects if scalable/ dir is included. When support for svg is added (which is beyond PIL), need to add a conditional and use a second glob if USE_SVG=1.
+ # IMPROVEHERE: this glob affects if scalable/ dir is included. When support for svg is added (which is beyond PIL), need to add a conditional and use a second glob if USE_SVG=1.
# to exclude the scalable/ contents, replace dir 5 asterisk with [0-9]*
results = []
# COMMENTED to test with the svg. results = glob.glob("/usr/share/icons/"+theme+"/*/"+category+"/"+name+".{png,PNG}")
@@ -269,8 +269,9 @@ def photoimage_from_svg(filename = "",size = "48"):
def image_from_svg(filename = "",size = "48"):
# open svg
- item = cairosvg.svg2png(url=filename,parent_width = size,parent_height = size)
- return ImageTk.PhotoImage(data=item)
+ cairosvg.svg2png(url=filename,write_to="/tmp/file3.png",parent_width = size,parent_height = size)
+ photo = Image.open("/tmp/file3.png")
+ return photo
def get_scaled_icon(icon_name, size = 24, icon_theme = "default", fallback_icon_name = ""):
iconfilename = None
@@ -294,17 +295,17 @@ def get_scaled_icon(icon_name, size = 24, icon_theme = "default", fallback_icon_
# try an svg
if re.compile(".*\.svg").match(iconfilename):
print("Trying svg...")
- photo = photoimage_from_svg(filename=iconfilename, size=size)
+ photo = image_from_svg(filename=iconfilename, size=size)
else:
photo = Image.open(iconfilename)
- photo.thumbnail(size=[size, size])
- try:
- photo = ImageTk.PhotoImage(photo)
- except Exception as e:
- print("Error was ",e)
except:
print("Error with icon file.")
return None
+ photo.thumbnail(size=[size, size])
+ try:
+ photo = ImageTk.PhotoImage(photo)
+ except Exception as e:
+ print("Error was ",e)
# If I ever add HiDPI support, multiple size here by the factor. So, size * 1.25
return photo
bgstack15