From c2456c4bac2c93f500e112dd998e4b781821f7c2 Mon Sep 17 00:00:00 2001 From: B Stack Date: Wed, 12 Jun 2019 07:12:47 -0400 Subject: add icon error handling --- .gitignore | 1 + logout-manager.py | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a4bc7e0..6ad48aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.2019-* +*.swp diff --git a/logout-manager.py b/logout-manager.py index d1583e6..33795fd 100755 --- a/logout-manager.py +++ b/logout-manager.py @@ -54,8 +54,21 @@ def get_scaled_icon(icon_name, size=24, fallback_icon_name = "", icon_theme = "d icon_info = this_theme.lookup_icon(icon_name, size, 0) iconfilename = icon_info.get_filename() except: - icon_info = this_theme.lookup_icon(fallback_icon_name, size, 0) - iconfilename = icon_info.get_filename() + try: + icon_info = this_theme.lookup_icon(fallback_icon_name, size, 0) + iconfilename = icon_info.get_filename() + except: + # no icon in the current theme. Try a hard-coded fallback: + try: + # if debuglev 3 + print("Error: could not find default icon for",icon_name+", so using fallback.") + this_theme = Gtk.IconTheme.new() + this_theme.set_custom_theme("Numix-Circle") + icon_info = this_theme.lookup_icon(icon_name, size, 0) + iconfilename = icon_info.get_filename() + except: + print("Error: Could not find any icon for",icon_name) + return None #print(iconfilename) return Gtk.Image.new_from_pixbuf(Pixbuf.new_from_file_at_scale( filename=iconfilename, -- cgit