aboutsummaryrefslogtreecommitdiff
path: root/logout-manager-tcl.py
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2019-06-20 10:56:24 -0400
committerB Stack <bgstack15@gmail.com>2019-06-20 10:56:24 -0400
commit924266f16fa5c11efce06f896879d436eba00654 (patch)
tree2ad011fd95f1b30bfb137a69ee2747ab31d8b50d /logout-manager-tcl.py
parenttcl: add all tooltips... (diff)
downloadlogout-manager-924266f16fa5c11efce06f896879d436eba00654.tar.gz
logout-manager-924266f16fa5c11efce06f896879d436eba00654.tar.bz2
logout-manager-924266f16fa5c11efce06f896879d436eba00654.zip
WIP: add initial svg support
Diffstat (limited to 'logout-manager-tcl.py')
-rwxr-xr-xlogout-manager-tcl.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/logout-manager-tcl.py b/logout-manager-tcl.py
index 74c914b..f774088 100755
--- a/logout-manager-tcl.py
+++ b/logout-manager-tcl.py
@@ -28,8 +28,9 @@
# package: RPM | DPKG
# tkinter: python36-tkinter | python3-tk
# PIL: python36-pillow-tk | python3-pil.imagetk
+# pip3 install cairosvg
-import glob, re
+import glob, re, cairosvg
import tkinter as tk
from functools import partial
from pathlib import Path
@@ -248,7 +249,8 @@ def get_filename_of_icon(name, theme = "hicolor", size = 48, category = "actions
# 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.
# to exclude the scalable/ contents, replace dir 5 asterisk with [0-9]*
results = []
- results = glob.glob("/usr/share/icons/"+theme+"/*/"+category+"/"+name+".{png,PNG}")
+ # COMMENTED to test with the svg. results = glob.glob("/usr/share/icons/"+theme+"/*/"+category+"/"+name+".{png,PNG}")
+ results = glob.glob("/usr/share/icons/"+theme+"/*/"+category+"/"+name+".*")
if len(results) == 0:
# no results with that category, so try all categories
results = glob.glob("/usr/share/icons/"+theme+"/*/*/"+name+".*")
@@ -259,6 +261,17 @@ def get_filename_of_icon(name, theme = "hicolor", size = 48, category = "actions
filename = find_best_size_match(size,results)
return filename
+def photoimage_from_svg(filename = "",size = "48"):
+ # this one works, but does not allow me to set the size.
+ # open svg
+ item = cairosvg.svg2png(url=filename, parent_width = size, parent_height = size)
+ return ImageTk.PhotoImage(data=item)
+
+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)
+
def get_scaled_icon(icon_name, size = 24, icon_theme = "default", fallback_icon_name = ""):
iconfilename = None
@@ -281,19 +294,19 @@ 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(iconfilename)
+ photo = photoimage_from_svg(filename=iconfilename, size=size)
else:
photo = Image.open(iconfilename)
+ photo.thumbnail(size=[size, size])
except:
print("Error with icon file.")
return None
# If I ever add HiDPI support, multiple size here by the factor. So, size * 1.25
- photo.thumbnail(size=[size, size])
try:
- photo2 = ImageTk.PhotoImage(photo)
+ photo = ImageTk.PhotoImage(photo)
except Exception as e:
print("Error was ",e)
- return photo2
+ return photo
class App:
def __init__(self, master):
bgstack15