GTK3: forgotten util functions hex to rgb from previous commit, correct link color in notes
svn: r20235
This commit is contained in:
parent
da05263402
commit
61738c91b6
@ -409,3 +409,22 @@ def is_right_click(event):
|
||||
|
||||
if event.button == 3:
|
||||
return True
|
||||
|
||||
def hex_to_rgb(value):
|
||||
"""
|
||||
Convert a hexademical value #FF00FF to rgb. Returns tuple of integers
|
||||
"""
|
||||
value = value.lstrip('#')
|
||||
lenv = len(value)
|
||||
return tuple(int(value[i:i+lenv/3], 16) for i in range(0, lenv, lenv/3))
|
||||
|
||||
def rgb_to_hex(rgb):
|
||||
"""
|
||||
Convert a tuple of integer or float rgb values to its hex value
|
||||
"""
|
||||
if type(rgb[0]) == int:
|
||||
return '#%02x%02x%02x' % rgb
|
||||
else:
|
||||
rgbint = (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))
|
||||
return '#%02x%02x%02x' % rgbint
|
||||
|
||||
|
@ -294,6 +294,8 @@ class StyledTextBuffer(UndoableBuffer):
|
||||
self.connect_after('insert-text', self.after_insert_text)
|
||||
self.connect_after('delete-range', self.after_delete_range)
|
||||
|
||||
self.linkcolor = 'blue'
|
||||
|
||||
# init gtkspell "state machine"
|
||||
self.gtkspell_state = GtkSpellState(self)
|
||||
|
||||
@ -560,7 +562,7 @@ class StyledTextBuffer(UndoableBuffer):
|
||||
for s_tag in s_tags:
|
||||
if s_tag.name == _('Link'):
|
||||
g_tag = LinkTag(self, s_tag.value,
|
||||
foreground="blue",
|
||||
foreground=self.linkcolor,
|
||||
underline=UNDERLINE_SINGLE)
|
||||
else:
|
||||
g_tag = self._find_tag_by_name(int(s_tag.name), s_tag.value)
|
||||
|
@ -61,7 +61,7 @@ from gui.widgets.toolcomboentry import ToolComboEntry
|
||||
from gui.widgets.springseparator import SpringSeparatorAction
|
||||
from gui.spell import Spell
|
||||
from gui.display import display_url
|
||||
from gui.utils import SystemFonts
|
||||
from gui.utils import SystemFonts, rgb_to_hex
|
||||
from gen.config import config
|
||||
from gen.constfunc import has_display
|
||||
|
||||
@ -183,6 +183,14 @@ class StyledTextEditor(Gtk.TextView):
|
||||
self.textbuffer.connect('changed', self._on_buffer_changed)
|
||||
GObject.GObject.__init__(self, 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.textbuffer.linkcolor = self.linkcolor
|
||||
|
||||
self.match = None
|
||||
self.last_match = None
|
||||
self._init_url_match()
|
||||
@ -541,7 +549,7 @@ class StyledTextEditor(Gtk.TextView):
|
||||
"""Setup regexp matching for URL match."""
|
||||
self.textbuffer.create_tag('hyperlink',
|
||||
underline=Pango.Underline.SINGLE,
|
||||
foreground='blue')
|
||||
foreground=self.linkcolor)
|
||||
self.textbuffer.match_add(SCHEME + "//(" + USER + "@)?[" +
|
||||
HOSTCHARS + ".]+" + "(:[0-9]+)?(" +
|
||||
URLPATH + ")?/?", GENURL)
|
||||
@ -621,7 +629,7 @@ class StyledTextEditor(Gtk.TextView):
|
||||
tag = LinkTag(self.textbuffer,
|
||||
data=uri,
|
||||
underline=Pango.Underline.SINGLE,
|
||||
foreground="blue")
|
||||
foreground=self.linkcolor)
|
||||
selection_bounds = self.textbuffer.get_selection_bounds()
|
||||
self.textbuffer.apply_tag(tag,
|
||||
selection_bounds[0],
|
||||
|
Loading…
Reference in New Issue
Block a user