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:
parent
567a526857
commit
4ede3aa4ab
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -3,7 +3,8 @@
|
||||
#
|
||||
# Copyright (C) 2009 Florian Heinle
|
||||
# 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
|
||||
# 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()
|
||||
|
Loading…
Reference in New Issue
Block a user