Commits

Steve Borho committed a6e409b

gtklib: GTK version safe color detection

  • Participants
  • Parent commits 66fb6e2
  • Branches stable

Comments (0)

Files changed (1)

File tortoisehg/hgtk/gtklib.py

     ( 1.0, 0.0, 1.0 ),
     ]
 
+def get_gtk_colors():
+    color_scheme = gtk.settings_get_default().get_property('gtk-color-scheme')
+    colors = {}
+    for color in color_scheme.split('\n'):
+        color = color.strip()
+        if color:
+            name, color = color.split(':')
+            colors[name.strip()] = gtk.gdk.color_parse(color.strip())
+    return colors
+
 def get_gtk_text_color():
     w = gtk.Window()
     w.realize()
 
 def is_dark_theme():
     global NORMAL, MAINLINE_COLOR
-    normal = gtk.gdk.color_parse(get_gtk_text_color())
+    if gtk.pygtk_version < (2, 12, 0):
+        gtk_colors = get_gtk_colors()
+        normal = gtk_colors.get('fg_color', gtk.gdk.color_parse('black'))
+    else:
+        normal = gtk.gdk.color_parse(get_gtk_text_color())
     NORMAL = str(normal)
     MAINLINE_COLOR = (
             normal.red / 65535.0,