From a4e1be7d6219f486ae4a408338b228048c404253 Mon Sep 17 00:00:00 2001 From: Zsolt Foldvari Date: Wed, 23 Apr 2008 09:54:30 +0000 Subject: [PATCH] Catch ValueError exception in case of 'foregin' gtk.TextTags in the text. svn: r10627 --- src/Editors/_StyledTextBuffer.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Editors/_StyledTextBuffer.py b/src/Editors/_StyledTextBuffer.py index 4ddd9165b..427a94687 100644 --- a/src/Editors/_StyledTextBuffer.py +++ b/src/Editors/_StyledTextBuffer.py @@ -549,17 +549,20 @@ class StyledTextBuffer(gtk.TextBuffer): for g_tagname, g_ranges in g_tags.items(): style_and_value = g_tagname.split(' ', 1) - style = int(style_and_value[0]) - if len(style_and_value) == 1: - s_value = None - else: - s_value = STYLE_TYPE[style](style_and_value[1]) - - if style in ALLOWED_STYLES: - s_ranges = [(start, end+1) for (start, end) in g_ranges] - s_tag = StyledTextTag(style, s_value, s_ranges) - - s_tags.append(s_tag) + try: + style = int(style_and_value[0]) + if len(style_and_value) == 1: + s_value = None + else: + s_value = STYLE_TYPE[style](style_and_value[1]) + + if style in ALLOWED_STYLES: + s_ranges = [(start, end+1) for (start, end) in g_ranges] + s_tag = StyledTextTag(style, s_value, s_ranges) + + s_tags.append(s_tag) + except ValueError: + _LOG.debug("silently skipping gtk.TextTag '%s'" % g_tagname) return StyledText(txt, s_tags)