GTK3: use style_context to draw correct link color, and to set shade color (not ideal, but better)

svn: r20234
This commit is contained in:
Benny Malengier 2012-08-20 15:20:33 +00:00
parent 885523602d
commit da05263402
2 changed files with 26 additions and 9 deletions

View File

@ -50,6 +50,7 @@ from gi.repository import Pango
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.constfunc import has_display, win from gen.constfunc import has_display, win
from gui.utils import rgb_to_hex
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -77,12 +78,22 @@ class LinkLabel(Gtk.EventBox):
def __init__(self, label, func, handle, emph=False, theme="CLASSIC"): def __init__(self, label, func, handle, emph=False, theme="CLASSIC"):
self.theme = theme self.theme = theme
self.emph = emph self.emph = emph
GObject.GObject.__init__(self)
st_cont = self.get_style_context()
col = st_cont.lookup_color('link_color')
if col[0]:
self.color = rgb_to_hex((col[1].red, col[1].green, col[1].blue))
else:
self.color = 'blue'
if emph: if emph:
#emphasize a link #emphasize a link
if theme == "CLASSIC": if theme == "CLASSIC":
format = 'underline="single" weight="heavy" style="italic"' format = 'underline="single" weight="heavy" style="italic"'
elif theme == "WEBPAGE": elif theme == "WEBPAGE":
format = 'foreground="blue" weight="heavy"' format = 'foreground="' + self.color + '" weight="heavy"'
else: else:
raise AttributeError("invalid theme: '%s'" % theme) raise AttributeError("invalid theme: '%s'" % theme)
elif emph is None: elif emph is None:
@ -98,11 +109,10 @@ class LinkLabel(Gtk.EventBox):
if theme == "CLASSIC": if theme == "CLASSIC":
format = 'underline="single"' format = 'underline="single"'
elif theme == "WEBPAGE": elif theme == "WEBPAGE":
format = 'foreground="blue"' format = 'foreground="' + self.color + '"'
else: else:
raise AttributeError("invalid theme: '%s'" % theme) raise AttributeError("invalid theme: '%s'" % theme)
GObject.GObject.__init__(self)
self.orig_text = cgi.escape(label[0]) self.orig_text = cgi.escape(label[0])
self.gender = label[1] self.gender = label[1]
self.decoration = format self.decoration = format
@ -139,10 +149,10 @@ class LinkLabel(Gtk.EventBox):
if self.emph: if self.emph:
#emphasize a link #emphasize a link
if self.theme == "CLASSIC": if self.theme == "CLASSIC":
format = 'foreground="blue" underline="single" '\ format = 'foreground="' + self.color + '" underline="single" '\
'weight="heavy" style="italic"' 'weight="heavy" style="italic"'
elif self.theme == "WEBPAGE": elif self.theme == "WEBPAGE":
format = 'underline="single" foreground="blue" '\ format = 'underline="single" foreground="' + self.color + '" '\
'weight="heavy"' 'weight="heavy"'
else: else:
raise AttributeError("invalid theme: '%s'" % theme) raise AttributeError("invalid theme: '%s'" % theme)
@ -157,9 +167,9 @@ class LinkLabel(Gtk.EventBox):
else: else:
#no emphasize, a link #no emphasize, a link
if self.theme == "CLASSIC": if self.theme == "CLASSIC":
format = 'foreground="blue" underline="single"' format = 'foreground="' + self.color + '" underline="single"'
elif self.theme == "WEBPAGE": elif self.theme == "WEBPAGE":
format = 'underline="single" foreground="blue"' format = 'underline="single" foreground="' + self.color + '"'
else: else:
raise AttributeError("invalid theme: '%s'" % theme) raise AttributeError("invalid theme: '%s'" % theme)

View File

@ -151,8 +151,6 @@ class RelationshipView(NavigationView):
uistate.connect('nameformat-changed', self.build_tree) uistate.connect('nameformat-changed', self.build_tree)
self.redrawing = False self.redrawing = False
self.color = Gdk.RGBA()
self.color.parse("White")
self.child = None self.child = None
self.old_handle = None self.old_handle = None
@ -313,6 +311,15 @@ class RelationshipView(NavigationView):
self.child = None self.child = None
self.scroll = Gtk.ScrolledWindow() self.scroll = Gtk.ScrolledWindow()
st_cont = self.scroll.get_style_context()
col = st_cont.lookup_color('base_color')
if col[0]:
self.color = col[1]
else:
self.color = Gdk.RGBA()
self.color.parse("White")
self.scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
self.scroll.show() self.scroll.show()