aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lmlib.py33
-rwxr-xr-xlogout-manager-tcl.py36
2 files changed, 43 insertions, 26 deletions
diff --git a/lmlib.py b/lmlib.py
index 2b0d6f9..91f9895 100644
--- a/lmlib.py
+++ b/lmlib.py
@@ -13,9 +13,9 @@
# Improve:
# Documentation:
-import configparser, platform
+import configparser, platform, os
-logout_manager_version="2019-06-14b"
+logout_manager_version="2019-06-17a"
class Actions:
@@ -64,6 +64,7 @@ class Config:
self.shutdown_fallback_icon = "system-shutdown"
self.icon_size = 24
self.icon_theme = "default"
+ self.gtk3_default_icon_theme = "hicolor"
self.icon_category = "actions"
self.can_hibernate = False
self.application_icon=("system-log-out")
@@ -104,6 +105,9 @@ class Config:
def set_icon_theme(self,icon_theme):
self.icon_theme = icon_theme
+ def set_gtk3_default_icon_theme(self,icon_theme):
+ self.gtk3_default_icon_theme= icon_theme
+
def set_icon_category(self,icon_category):
self.icon_category = icon_category
@@ -162,12 +166,32 @@ class Config:
def get_icon_theme(self):
return self.icon_theme
+ def get_gtk3_default_icon_theme(self):
+ return self.gtk3_default_icon_theme
+
def get_icon_category(self):
return self.icon_category
def get_can_hibernate(self):
return self.can_hibernate
+def get_gtk3_default_icon_theme():
+ # abstracted so it does not clutter get_scaled_icon
+ name = "hicolor"
+ gtk3_config_path = os.path.join(os.path.expanduser("~"),".config","gtk-3.0","settings.ini")
+ gtk3_config = configparser.ConfigParser()
+ gtk3_config.read(gtk3_config_path)
+ try:
+ if 'Settings' in gtk3_config:
+ name = gtk3_config['Settings']['gtk-icon-theme-name']
+ elif 'settings' in gtk3_config:
+ name = gtk3_config['settings']['gtk-icon-theme-name']
+ except:
+ # supposed failsafe: keep name = hicolor
+ pass
+ print("Found gtk3 default theme:",name)
+ return name
+
def Initialize_config():
# Read config
config_in = configparser.ConfigParser()
@@ -220,6 +244,11 @@ def Initialize_config():
pass
config.set_can_hibernate(can_hibernate)
+ # read gtk3_default_icon_theme
+ config.set_gtk3_default_icon_theme(get_gtk3_default_icon_theme())
+ if config.get_icon_theme() == "default":
+ config.set_icon_theme(config.get_gtk3_default_icon_theme())
+
# set icon category
# written primarily for el7 which uses "app" for the system-reboot icons, etc.
a = platform.dist()
diff --git a/logout-manager-tcl.py b/logout-manager-tcl.py
index cfeb851..5b0d29d 100755
--- a/logout-manager-tcl.py
+++ b/logout-manager-tcl.py
@@ -248,24 +248,6 @@ class Tooltip:
tw.destroy()
self.tw = None
-def get_gtk3_default_theme():
- # WORKHERE: move this to lmlib
- # abstracted so it does not clutter get_scaled_icon
- name = "hicolor"
- gtk3_config_path = os.path.join(os.path.expanduser("~"),".config","gtk-3.0","settings.ini")
- gtk3_config = configparser.ConfigParser()
- gtk3_config.read(gtk3_config_path)
- try:
- if 'Settings' in gtk3_config:
- name = gtk3_config['Settings']['gtk-icon-theme-name']
- elif 'settings' in gtk3_config:
- name = gtk3_config['settings']['gtk-icon-theme-name']
- except:
- # supposed failsafe
- name = "hicolor"
- print("Found gtk3 default theme:",name)
- return name
-
def tryint(s):
try:
return int(s)
@@ -309,13 +291,20 @@ def get_filename_of_icon(name, theme = "hicolor", size = 48, category = "actions
# example: Adwaita system-log-out
if theme == "default" or theme is None:
- theme = "hicolor"
+ try:
+ theme = lmlib.get_gtk3_default_icon_theme()
+ except:
+ theme = "hicolor"
# first, find all files underneath /usr/share/icons/$THEME/$SIZE
# WORKHERE, allow a prioritization of category, but tolerate any category if the requested category has no matches but another category does
print("Finding filename of icon, theme=",theme,"category=",category,"name=",name)
# WORKHERE: 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.
+ results = []
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+".*")
# the sort arranges it so a Numix/24 dir comes before a Numix/24@2x dir
results = sorted(results, key=sort_sizes)
#print(results)
@@ -333,9 +322,8 @@ def get_scaled_icon(icon_name, size = 24, icon_theme = "default", fallback_icon_
else:
if icon_theme == "default":
- # retrieve default theme from config file
- print("Discovering default icon theme...")
- icon_theme = get_gtk3_default_theme()
+ # this should not happen, because the Initialize_config should have checked gtk3 default value.
+ icon_theme = "hicolor"
# so now that icon_theme is defined, let us go find the icon that matches the requested name and size, in the actions category
#print("Using icon theme",icon_theme)
iconfilename = get_filename_of_icon(name=icon_name, theme=icon_theme, size=size, category=config.get_icon_category())
@@ -420,14 +408,14 @@ root = tk.Tk()
# MAIN LOOP
root.title("Log out options")
#root.iconbitmap(r'/usr/share/icons/Numix/48/actions/system-logout.svg')
-imgicon = get_scaled_icon(config.get_logout_icon(),24)
+imgicon = get_scaled_icon(config.get_logout_icon(),24,config.get_icon_theme())
#if USE_PRIVATE_TCL_IMAGES is None:
# #imgicon = PhotoImage(file=os.path.join("/usr/share/icons/Adwaita/24x24/actions","system-log-out.png"))
# imgicon = get_scaled_icon(config.get_logout_icon(),24)
#else:
# #imgicon = PhotoImage_from_png(file=os.path.join("/usr/share/icons/Adwaita/24x24/actions","system-log-out.png"))
# imgicon = get_scaled_icon(config.get_logout_icon(),24)
-print(imgicon)
+#print(imgicon)
root.tk.call('wm','iconphoto', root._w, imgicon)
app = App(root)
root.mainloop()
bgstack15