Fix link colour for dark themes

Issue #7749.
This commit is contained in:
Nick Hall 2017-12-18 23:40:06 +00:00
parent 84e76de2b1
commit 70fff6253d
4 changed files with 22 additions and 20 deletions

View File

@ -544,6 +544,21 @@ def rgb_to_hex(rgb):
rgbint = (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255)) rgbint = (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))
return '#%02x%02x%02x' % rgbint 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): def edit_object(dbstate, uistate, reftype, ref):
""" """
Invokes the appropriate editor for an object type and given handle. Invokes the appropriate editor for an object type and given handle.

View File

@ -48,7 +48,7 @@ from gramps.gen.errors import WindowActiveError
from gramps.gen.const import URL_MANUAL_PAGE, VERSION_DIR, COLON from gramps.gen.const import URL_MANUAL_PAGE, VERSION_DIR, COLON
from ..editors import EditPerson, EditFamily from ..editors import EditPerson, EditFamily
from ..managedwindow import ManagedWindow 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 .menuitem import add_menuitem
from ..plug import make_gui_option from ..plug import make_gui_option
from ..plug.quick import run_quick_report_by_name from ..plug.quick import run_quick_report_by_name
@ -196,12 +196,7 @@ class LinkTag(Gtk.TextTag):
lid = 0 lid = 0
#obtaining the theme link color once. Restart needed on theme change! #obtaining the theme link color once. Restart needed on theme change!
linkcolor = Gtk.Label(label='test') #needed to avoid label destroyed to early linkcolor = Gtk.Label(label='test') #needed to avoid label destroyed to early
linkcolor = linkcolor.get_style_context().lookup_color('link_color') linkcolor = get_link_color(linkcolor.get_style_context())
if linkcolor[0]:
linkcolor = rgb_to_hex((linkcolor[1].red, linkcolor[1].green,
linkcolor[1].blue))
else:
linkcolor = 'blue'
def __init__(self, buffer): def __init__(self, buffer):
LinkTag.lid += 1 LinkTag.lid += 1

View File

@ -48,7 +48,7 @@ from gi.repository import Pango
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.constfunc import has_display, win 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) Gtk.EventBox.__init__(self)
st_cont = self.get_style_context() st_cont = self.get_style_context()
col = st_cont.lookup_color('link_color') self.color = get_link_color(st_cont)
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

View File

@ -60,7 +60,7 @@ from .toolcomboentry import ToolComboEntry
from .springseparator import SpringSeparatorAction from .springseparator import SpringSeparatorAction
from ..spell import Spell from ..spell import Spell
from ..display import display_url 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.config import config
from gramps.gen.constfunc import has_display from gramps.gen.constfunc import has_display
from ..actiongroup import ActionGroup from ..actiongroup import ActionGroup
@ -186,11 +186,7 @@ class StyledTextEditor(Gtk.TextView):
self.set_buffer(self.textbuffer) self.set_buffer(self.textbuffer)
st_cont = self.get_style_context() st_cont = self.get_style_context()
col = st_cont.lookup_color('link_color') self.linkcolor = get_link_color(st_cont)
if col[0]:
self.linkcolor = rgb_to_hex((col[1].red, col[1].green, col[1].blue))
else:
self.linkcolor = 'blue'
self.textbuffer.linkcolor = self.linkcolor self.textbuffer.linkcolor = self.linkcolor
self.match = None self.match = None