3866 3976 3977: Two 'spell' entries; remove Enchant dependency; Gramps does spellcheck on/off menu, gtkspell does the different languages. Cleaned-up code to reflect fact that spellcheck can only be on or off (see 3866).
svn: r17669
This commit is contained in:
parent
b86b1ae8ae
commit
9a497b9264
37
src/Spell.py
37
src/Spell.py
@ -82,33 +82,29 @@ import config
|
|||||||
class Spell(object):
|
class Spell(object):
|
||||||
"""Attach a gtkspell instance to the passed TextView instance.
|
"""Attach a gtkspell instance to the passed TextView instance.
|
||||||
"""
|
"""
|
||||||
_spellcheck_options = {'off': _('Off')}
|
_spellcheck_options = {False: _('Off'), True: _('On') }
|
||||||
|
|
||||||
if HAVE_GTKSPELL:
|
|
||||||
_spellcheck_options['on'] = _('On')
|
|
||||||
|
|
||||||
def __init__(self, textview):
|
def __init__(self, textview):
|
||||||
self.textview = textview
|
self.textview = textview
|
||||||
|
|
||||||
if HAVE_GTKSPELL and config.get('behavior.spellcheck'):
|
if HAVE_GTKSPELL and config.get('behavior.spellcheck'):
|
||||||
self.spellcheck = 'on'
|
self.spellcheck = True
|
||||||
else:
|
else:
|
||||||
self.spellcheck = 'off'
|
self.spellcheck = False
|
||||||
|
|
||||||
self._active_spellcheck = 'off'
|
self._previous_spellcheck = False
|
||||||
self.__real_set_active_spellcheck(self.spellcheck)
|
self.__real_set_active_spellcheck(self.spellcheck)
|
||||||
|
|
||||||
# Private
|
# Private
|
||||||
|
|
||||||
def __real_set_active_spellcheck(self, spellcheck_code):
|
def __real_set_active_spellcheck(self, next_spellcheck):
|
||||||
"""Set active spellcheck by its code."""
|
"""Set active spellcheck by its code."""
|
||||||
if self._active_spellcheck == 'off':
|
if self._previous_spellcheck == next_spellcheck:
|
||||||
if spellcheck_code == 'off':
|
|
||||||
return
|
return
|
||||||
else:
|
elif self._previous_spellcheck == False and next_spellcheck == True:
|
||||||
try:
|
try:
|
||||||
gtkspell_spell = gtkspell.Spell(self.textview)
|
gtkspell_spell = gtkspell.Spell(self.textview)
|
||||||
self._active_spellcheck = spellcheck_code
|
self._previous_spellcheck = next_spellcheck
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
print traceback.print_exc()
|
print traceback.print_exc()
|
||||||
@ -116,28 +112,27 @@ class Spell(object):
|
|||||||
# the language does not exist
|
# the language does not exist
|
||||||
# and presumably if there is no dictionary
|
# and presumably if there is no dictionary
|
||||||
pass
|
pass
|
||||||
else:
|
elif self._previous_spellcheck == True and next_spellcheck == False:
|
||||||
if spellcheck_code == 'on':
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
gtkspell_spell = gtkspell.get_from_text_view(self.textview)
|
gtkspell_spell = gtkspell.get_from_text_view(self.textview)
|
||||||
gtkspell_spell.detach()
|
gtkspell_spell.detach()
|
||||||
self._active_spellcheck = spellcheck_code
|
self._previous_spellcheck = next_spellcheck
|
||||||
|
else:
|
||||||
|
assert False, "spellcheck flags are not boolean -- shouldn't get here"
|
||||||
|
|
||||||
# Public API
|
# Public API
|
||||||
|
|
||||||
def get_all_spellchecks(self):
|
def get_spellcheck_options(self):
|
||||||
"""Get the list of installed spellcheck names."""
|
"""Get the list of installed spellcheck names."""
|
||||||
return self._spellcheck_options.values()
|
return self._spellcheck_options.values()
|
||||||
|
|
||||||
def set_active_spellcheck(self, spellcheck):
|
def set_spellcheck_state(self, spellcheck):
|
||||||
"""Set active spellcheck by it's name."""
|
"""Set active spellcheck by it's name."""
|
||||||
for code, name in self._spellcheck_options.items():
|
for code, name in self._spellcheck_options.items():
|
||||||
if name == spellcheck:
|
if name == spellcheck:
|
||||||
self.__real_set_active_spellcheck(code)
|
self.__real_set_active_spellcheck(code)
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_active_spellcheck(self):
|
def get_spellcheck_state(self):
|
||||||
"""Get the name of the active spellcheck."""
|
"""Get the name of the active spellcheck."""
|
||||||
return self._spellcheck_options[self._active_spellcheck]
|
return self._spellcheck_options[self._previous_spellcheck]
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ from gui.widgets.undoablestyledbuffer import UndoableStyledBuffer
|
|||||||
from gui.widgets.valueaction import ValueAction
|
from gui.widgets.valueaction import ValueAction
|
||||||
from gui.widgets.toolcomboentry import ToolComboEntry
|
from gui.widgets.toolcomboentry import ToolComboEntry
|
||||||
from gui.widgets.springseparator import SpringSeparatorAction
|
from gui.widgets.springseparator import SpringSeparatorAction
|
||||||
from Spell import Spell
|
from Spell import Spell, HAVE_GTKSPELL
|
||||||
from GrampsDisplay import url as display_url
|
from GrampsDisplay import url as display_url
|
||||||
import config
|
import config
|
||||||
from constfunc import has_display
|
from constfunc import has_display
|
||||||
@ -364,6 +364,7 @@ class StyledTextEditor(gtk.TextView):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
# spell checker submenu
|
# spell checker submenu
|
||||||
|
if HAVE_GTKSPELL:
|
||||||
spell_menu = gtk.MenuItem(_('Spellcheck'))
|
spell_menu = gtk.MenuItem(_('Spellcheck'))
|
||||||
spell_menu.set_submenu(self._create_spell_menu())
|
spell_menu.set_submenu(self._create_spell_menu())
|
||||||
spell_menu.show_all()
|
spell_menu.show_all()
|
||||||
@ -548,23 +549,23 @@ class StyledTextEditor(gtk.TextView):
|
|||||||
"[a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+", MAIL)
|
"[a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+", MAIL)
|
||||||
|
|
||||||
def _create_spell_menu(self):
|
def _create_spell_menu(self):
|
||||||
"""Create a menu with all the installed spellchecks.
|
"""Create a menu with the spellcheck option Off and On.
|
||||||
|
|
||||||
It is called each time the popup menu is opened. Each spellcheck
|
It is called each time the popup menu is opened. Each option
|
||||||
forms a radio menu item, and the selected spellcheck is set as active.
|
forms a radio menu item, and the selected option is set as active.
|
||||||
|
|
||||||
@returns: menu containing all the installed spellchecks.
|
@returns: menu containing the spellcheck options.
|
||||||
@returntype: gtk.Menu
|
@returntype: gtk.Menu
|
||||||
|
|
||||||
"""
|
"""
|
||||||
active_spellcheck = self.spellcheck.get_active_spellcheck()
|
spellcheck_state = self.spellcheck.get_spellcheck_state()
|
||||||
|
|
||||||
menu = gtk.Menu()
|
menu = gtk.Menu()
|
||||||
group = None
|
group = None
|
||||||
for lang in self.spellcheck.get_all_spellchecks():
|
for spellcheck in self.spellcheck.get_spellcheck_options():
|
||||||
menuitem = gtk.RadioMenuItem(group, lang)
|
menuitem = gtk.RadioMenuItem(group, spellcheck)
|
||||||
menuitem.set_active(lang == active_spellcheck)
|
menuitem.set_active(spellcheck == spellcheck_state)
|
||||||
menuitem.connect('activate', self._spell_change_cb, lang)
|
menuitem.connect('activate', self._spell_change_cb, spellcheck)
|
||||||
menu.append(menuitem)
|
menu.append(menuitem)
|
||||||
|
|
||||||
if group is None:
|
if group is None:
|
||||||
@ -706,8 +707,8 @@ class StyledTextEditor(gtk.TextView):
|
|||||||
self._internal_style_change = False
|
self._internal_style_change = False
|
||||||
|
|
||||||
def _spell_change_cb(self, menuitem, spellcheck):
|
def _spell_change_cb(self, menuitem, spellcheck):
|
||||||
"""Set spell checker spellcheck according to user selection."""
|
"""Set spell checker option according to user selection."""
|
||||||
self.spellcheck.set_active_spellcheck(spellcheck)
|
self.spellcheck.set_spellcheck_state(spellcheck)
|
||||||
|
|
||||||
def _open_url_cb(self, menuitem, url, flavor):
|
def _open_url_cb(self, menuitem, url, flavor):
|
||||||
"""Open the URL in a browser."""
|
"""Open the URL in a browser."""
|
||||||
|
Loading…
Reference in New Issue
Block a user