From e51a2983fd6762ca3357cca8a7b63e7b0a0376fb Mon Sep 17 00:00:00 2001 From: B Stack Date: Sat, 15 Jun 2019 15:28:52 -0400 Subject: WIP: try with rsvg and cairo Unfortunately I just couldn't get the examples working with rsvg and cairo, so I will have to try something else. References: http://code.activestate.com/lists/python-list/595078/ https://grokbase.com/t/python/python-list/112fsd3tyw/displaying-svg-in-tkinter-using-cairo-and-rsvg --- logout-manager-tcl.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'logout-manager-tcl.py') diff --git a/logout-manager-tcl.py b/logout-manager-tcl.py index cfeb851..0a0a1f7 100755 --- a/logout-manager-tcl.py +++ b/logout-manager-tcl.py @@ -29,11 +29,8 @@ # tkinter: python36-tkinter | python3-tk # PIL: python36-pillow-tk | python3-pil.imagetk # cairo: python36-cairo | python3-cairo -# Rsvg: python36-gobject | python3-gobject +# Rsvg: python36-gobject | gir1.2-rsvg-3.0 -from gi import require_version -require_version('Rsvg', '2.0') -from gi.repository import Rsvg import os, sys, configparser, glob, re, cairo import tkinter as tk import tkinter.ttk as ttk @@ -42,6 +39,11 @@ from pathlib import Path from PIL import Image, ImageTk sys.path.append("/home/bgirton/dev/logout-manager") import lmlib +WITH_SVG=True +if not WITH_SVG is None and WITH_SVG: + from gi import require_version + require_version('Rsvg', '2.0') + from gi.repository import Rsvg as rsvg #if TkVersion < 8.6: # USE_PRIVATE_TCL_IMAGES = 1 # print("Loading private PIL translation layter") @@ -86,7 +88,7 @@ def convert(bgra_buffer, width, height): def photoimage_from_svg(file_path_name): '''Return a Tkinter.PhotoImage with the content set to the rendered SVG.''' - svg = rsvg.Handle(file=file_path_name) + svg = rsvg.Handle(file_path_name) width, height = svg.get_dimension_data()[:2] surface = cairo.ImageSurface(cairo.FORMAT_RGB24, int(width), int(height)) context = cairo.Context(surface) @@ -349,8 +351,10 @@ def get_scaled_icon(icon_name, size = 24, icon_theme = "default", fallback_icon_ photo = photoimage_from_svg(iconfilename) else: photo = Image.open(iconfilename) - except: - print("Error with icon file.") + except Exception as e: + print("Error with icon file:",e) + if "gobject" in str(e): + raise return None # If I ever add HiDPI stuff, multiple size here by the factor. So, size * 1.25 photo.thumbnail(size=[size, size]) -- cgit