From 70fff6253d6296f86592ccfbaed401f331d40f3c Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Mon, 18 Dec 2017 23:40:06 +0000 Subject: [PATCH] Fix link colour for dark themes Issue #7749. --- gramps/gui/utils.py | 15 +++++++++++++++ gramps/gui/widgets/grampletpane.py | 11 +++-------- gramps/gui/widgets/labels.py | 8 ++------ gramps/gui/widgets/styledtexteditor.py | 8 ++------ 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/gramps/gui/utils.py b/gramps/gui/utils.py index c6d84b504..baa3b8d8a 100644 --- a/gramps/gui/utils.py +++ b/gramps/gui/utils.py @@ -544,6 +544,21 @@ def rgb_to_hex(rgb): rgbint = (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255)) return '#%02x%02x%02x' % rgbint +def get_link_color(context): + """ + Find the link color for the current theme. + """ + from gi.repository import Gtk + + if Gtk.get_minor_version() > 11: + col = context.get_color(Gtk.StateFlags.LINK) + else: + found, col = context.lookup_color('link_color') + if not found: + col.parse('blue') + + return rgb_to_hex((col.red, col.green, col.blue)) + def edit_object(dbstate, uistate, reftype, ref): """ Invokes the appropriate editor for an object type and given handle. diff --git a/gramps/gui/widgets/grampletpane.py b/gramps/gui/widgets/grampletpane.py index 0592a0e94..712295438 100644 --- a/gramps/gui/widgets/grampletpane.py +++ b/gramps/gui/widgets/grampletpane.py @@ -48,7 +48,7 @@ from gramps.gen.errors import WindowActiveError from gramps.gen.const import URL_MANUAL_PAGE, VERSION_DIR, COLON from ..editors import EditPerson, EditFamily from ..managedwindow import ManagedWindow -from ..utils import is_right_click, rgb_to_hex, get_primary_mask +from ..utils import is_right_click, get_primary_mask, get_link_color from .menuitem import add_menuitem from ..plug import make_gui_option from ..plug.quick import run_quick_report_by_name @@ -196,13 +196,8 @@ class LinkTag(Gtk.TextTag): lid = 0 #obtaining the theme link color once. Restart needed on theme change! linkcolor = Gtk.Label(label='test') #needed to avoid label destroyed to early - linkcolor = linkcolor.get_style_context().lookup_color('link_color') - if linkcolor[0]: - linkcolor = rgb_to_hex((linkcolor[1].red, linkcolor[1].green, - linkcolor[1].blue)) - else: - linkcolor = 'blue' - + linkcolor = get_link_color(linkcolor.get_style_context()) + def __init__(self, buffer): LinkTag.lid += 1 Gtk.TextTag.__init__(self, name=str(LinkTag.lid)) diff --git a/gramps/gui/widgets/labels.py b/gramps/gui/widgets/labels.py index 4226a964a..3ff9be1a3 100644 --- a/gramps/gui/widgets/labels.py +++ b/gramps/gui/widgets/labels.py @@ -48,7 +48,7 @@ from gi.repository import Pango # #------------------------------------------------------------------------- from gramps.gen.constfunc import has_display, win -from ..utils import rgb_to_hex +from ..utils import get_link_color #------------------------------------------------------------------------- # @@ -81,11 +81,7 @@ class LinkLabel(Gtk.EventBox): Gtk.EventBox.__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' + self.color = get_link_color(st_cont) if emph: #emphasize a link diff --git a/gramps/gui/widgets/styledtexteditor.py b/gramps/gui/widgets/styledtexteditor.py index 8879cb7ae..2dc10905f 100644 --- a/gramps/gui/widgets/styledtexteditor.py +++ b/gramps/gui/widgets/styledtexteditor.py @@ -60,7 +60,7 @@ from .toolcomboentry import ToolComboEntry from .springseparator import SpringSeparatorAction from ..spell import Spell from ..display import display_url -from ..utils import SystemFonts, rgb_to_hex, get_primary_mask +from ..utils import SystemFonts, get_primary_mask, get_link_color from gramps.gen.config import config from gramps.gen.constfunc import has_display from ..actiongroup import ActionGroup @@ -186,11 +186,7 @@ class StyledTextEditor(Gtk.TextView): self.set_buffer(self.textbuffer) st_cont = self.get_style_context() - col = st_cont.lookup_color('link_color') - if col[0]: - self.linkcolor = rgb_to_hex((col[1].red, col[1].green, col[1].blue)) - else: - self.linkcolor = 'blue' + self.linkcolor = get_link_color(st_cont) self.textbuffer.linkcolor = self.linkcolor self.match = None