From 4ede3aa4abfb00af54d4cee9a16e0976bc819fc6 Mon Sep 17 00:00:00 2001 From: Vassilii Khachaturov Date: Wed, 19 Feb 2014 16:28:28 +0200 Subject: [PATCH] 7097: spell.py hangs on a note for tens of secods Back-port my fix from gramps40: [ef1027] [c81ff4] [ee9151] --- src/Spell.py | 4 +++- src/gui/widgets/styledtextbuffer.py | 3 ++- src/gui/widgets/styledtexteditor.py | 1 + src/gui/widgets/undoablestyledbuffer.py | 26 ++++++++++++++++++++++--- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/Spell.py b/src/Spell.py index da2f6381b..9f157acff 100644 --- a/src/Spell.py +++ b/src/Spell.py @@ -2,6 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2005-2006 Donald N. Allingham +# Copyright (C) 2014 Vassilii Khachaturov # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -97,7 +98,8 @@ class Spell(object): return else: try: - gtkspell_spell = gtkspell.Spell(self.textview) + with self.textview.undo_disabled(): + gtkspell_spell = gtkspell.Spell(self.textview) self._active_spellcheck = spellcheck_code except: # attaching the spellchecker will fail if diff --git a/src/gui/widgets/styledtextbuffer.py b/src/gui/widgets/styledtextbuffer.py index d789c9944..8a3ae3615 100644 --- a/src/gui/widgets/styledtextbuffer.py +++ b/src/gui/widgets/styledtextbuffer.py @@ -500,8 +500,8 @@ class StyledTextBuffer(UndoableBuffer): end = self.get_char_count() tagdict = {} + iter = self.get_iter_at_offset(start) for pos in range(start, end): - iter = self.get_iter_at_offset(pos) for tag in iter.get_tags(): name = tag.get_property('name') if name in tagdict: @@ -511,6 +511,7 @@ class StyledTextBuffer(UndoableBuffer): tagdict[name].append((pos, pos)) else: tagdict[name]=[(pos, pos)] + iter.forward_char() return tagdict def _find_tag_by_name(self, style, value): diff --git a/src/gui/widgets/styledtexteditor.py b/src/gui/widgets/styledtexteditor.py index bd4cf9cf5..002a3dd61 100644 --- a/src/gui/widgets/styledtexteditor.py +++ b/src/gui/widgets/styledtexteditor.py @@ -176,6 +176,7 @@ class StyledTextEditor(gtk.TextView): def __init__(self): """Setup initial instance variable values.""" self.textbuffer = UndoableStyledBuffer() + self.undo_disabled = self.textbuffer.undo_disabled # see bug 7097 self.textbuffer.connect('style-changed', self._on_buffer_style_changed) self.textbuffer.connect('changed', self._on_buffer_changed) gtk.TextView.__init__(self, self.textbuffer) diff --git a/src/gui/widgets/undoablestyledbuffer.py b/src/gui/widgets/undoablestyledbuffer.py index 498f7da6f..b0ac81a7a 100644 --- a/src/gui/widgets/undoablestyledbuffer.py +++ b/src/gui/widgets/undoablestyledbuffer.py @@ -3,7 +3,8 @@ # # Copyright (C) 2009 Florian Heinle # Copyright (C) 2010 Doug Blank -# Copyright (C) 2010 Benny Malengier +# Copyright (C) 2010 Benny Malengier +# Copyright (C) 2014 Vassilii Khachaturov # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,14 +21,14 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# $Id$ - """ gtk textbuffer with undo functionality """ __all__ = ["UndoableStyledBuffer"] +from contextlib import contextmanager + import gtk from gen.lib.styledtext import StyledText @@ -79,6 +80,25 @@ class UndoableStyledBuffer(StyledTextBuffer): self.connect('apply-tag', self.on_tag_insert_undoable) self.connect_after('apply-tag', self.on_tag_afterinsert_undoable) + @contextmanager + def undo_disabled(self): + """ + Assures that not_undoable_action is False during the context. + + Usage example (see src/gui/widgets/styledtexteditor.py):: + + with self.buffer.undo_disabled(): + ... # heavy stuff like spell checking + """ + oldflag = self.not_undoable_action + self.not_undoable_action = True + try: + yield + except: + raise + finally: + self.not_undoable_action = oldflag + def on_tag_insert_undoable(self, buffer, tag, start, end): if not self.undo_in_progress: self._empty_redo_stack()