7097: spell.py hangs on a note for tens of secods

Back-port my fix from gramps40: [ef1027] [c81ff4] [ee9151]
This commit is contained in:
Vassilii Khachaturov 2014-02-19 16:28:28 +02:00
parent 567a526857
commit 4ede3aa4ab
4 changed files with 29 additions and 5 deletions

View File

@ -2,6 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2005-2006 Donald N. Allingham # Copyright (C) 2005-2006 Donald N. Allingham
# Copyright (C) 2014 Vassilii Khachaturov
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -97,7 +98,8 @@ class Spell(object):
return return
else: else:
try: try:
gtkspell_spell = gtkspell.Spell(self.textview) with self.textview.undo_disabled():
gtkspell_spell = gtkspell.Spell(self.textview)
self._active_spellcheck = spellcheck_code self._active_spellcheck = spellcheck_code
except: except:
# attaching the spellchecker will fail if # attaching the spellchecker will fail if

View File

@ -500,8 +500,8 @@ class StyledTextBuffer(UndoableBuffer):
end = self.get_char_count() end = self.get_char_count()
tagdict = {} tagdict = {}
iter = self.get_iter_at_offset(start)
for pos in range(start, end): for pos in range(start, end):
iter = self.get_iter_at_offset(pos)
for tag in iter.get_tags(): for tag in iter.get_tags():
name = tag.get_property('name') name = tag.get_property('name')
if name in tagdict: if name in tagdict:
@ -511,6 +511,7 @@ class StyledTextBuffer(UndoableBuffer):
tagdict[name].append((pos, pos)) tagdict[name].append((pos, pos))
else: else:
tagdict[name]=[(pos, pos)] tagdict[name]=[(pos, pos)]
iter.forward_char()
return tagdict return tagdict
def _find_tag_by_name(self, style, value): def _find_tag_by_name(self, style, value):

View File

@ -176,6 +176,7 @@ class StyledTextEditor(gtk.TextView):
def __init__(self): def __init__(self):
"""Setup initial instance variable values.""" """Setup initial instance variable values."""
self.textbuffer = UndoableStyledBuffer() 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('style-changed', self._on_buffer_style_changed)
self.textbuffer.connect('changed', self._on_buffer_changed) self.textbuffer.connect('changed', self._on_buffer_changed)
gtk.TextView.__init__(self, self.textbuffer) gtk.TextView.__init__(self, self.textbuffer)

View File

@ -3,7 +3,8 @@
# #
# Copyright (C) 2009 Florian Heinle # Copyright (C) 2009 Florian Heinle
# Copyright (C) 2010 Doug Blank <doug.blank@gmail.com> # Copyright (C) 2010 Doug Blank <doug.blank@gmail.com>
# 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 # 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 # 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 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# $Id$
""" """
gtk textbuffer with undo functionality gtk textbuffer with undo functionality
""" """
__all__ = ["UndoableStyledBuffer"] __all__ = ["UndoableStyledBuffer"]
from contextlib import contextmanager
import gtk import gtk
from gen.lib.styledtext import StyledText from gen.lib.styledtext import StyledText
@ -79,6 +80,25 @@ class UndoableStyledBuffer(StyledTextBuffer):
self.connect('apply-tag', self.on_tag_insert_undoable) self.connect('apply-tag', self.on_tag_insert_undoable)
self.connect_after('apply-tag', self.on_tag_afterinsert_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): def on_tag_insert_undoable(self, buffer, tag, start, end):
if not self.undo_in_progress: if not self.undo_in_progress:
self._empty_redo_stack() self._empty_redo_stack()