Class STCSpellCheckMixin
object --+
|
STCSpellCheckMixin
Spell checking mixin for use with wx.StyledTextControl.
This mixin shows spelling errors using the styling indicators (e.g.
the red squiggly underline) of the styled text control; I find this much
more convenient than a dialog-box that makes you click through each
mistake.
The eventual goal of the module is to provide on-the-fly spell
checking that will display errors as you type, and also will highlight
errors during idle time or in a background thread.
This mixin provides spell checking using the pyenchant module.
Without pyenchant, this mixin won't do anything useful, but it is still
safe to be mixed in. It wraps all calls to pyenchant with try/except
blocks to catch import errors, and any calls to the spell checking
functions will return immediately.
In your code that uses this mixin, be sure to call the mixin's
constructor with code like:
class MySTC(STCSpellCheckMixin, wx.stc.StyledTextCtrl):
def __init__(self, *args, **kwargs):
wx.stc.StyledTextCtrl.__init__(self, *args, **kwargs)
STCSpellingMixin.__init__(self)
To use the spelling check, use one of the methods spellCheckAll, spellCheckCurrentPage, or spellCheckSelection. Clear the spelling indicators with
spellClearAll.
|
|
__init__(self,
*args,
**kwargs)
Mixin must be initialized using this constructor. |
|
|
|
|
spellSetIndicator(self,
indicator=None,
color=None,
style=None)
Set the indicator styling for misspelled words. |
|
|
|
|
|
|
|
|
|
|
|
|
|
spellClearAll(self)
Clear the stc of all spelling indicators. |
|
|
|
|
spellCheckRange(self,
start,
end)
Perform a spell check over a range of text in the document. |
|
|
|
|
spellCheckAll(self)
Perform a spell check on the entire document. |
|
|
|
|
spellCheckSelection(self)
Perform a spell check on the currently selected region. |
|
|
|
|
spellCheckCurrentPage(self)
Perform a spell check on the currently visible lines. |
|
|
|
|
|
|
Inherited from object:
__delattr__,
__getattribute__,
__hash__,
__new__,
__reduce__,
__reduce_ex__,
__repr__,
__setattr__,
__str__
|
|
Inherited from object:
__class__
|
__init__(self,
*args,
**kwargs)
(Constructor)
|
|
Mixin must be initialized using this constructor.
Keyword arguments are also available instead of calling the
convenience functions. For spellSetIndicator, use indicator,
indicator_color, and {indicator_style}; for spellSetLanguage, use language; and for spellSetMinimumWordSize, use min_word_size.
See the descriptions of those methods for more info.
- Overrides:
object.__init__
|
spellSetIndicator(self,
indicator=None,
color=None,
style=None)
|
|
Set the indicator styling for misspelled words.
Set the indicator index to use, its color, and the visual style.
- Parameters:
indicator - indicator number (usually 0, 1, or 2, but may be fewer depending
on the number of style bits you've chosen for the stc.)
color - string indicating the color of the indicator (e.g.
"#FF0000" for red)
style - stc indicator style; one of the wx.stc.STC_INDIC_* constants
(currently wx.stc.STC_INDIC_PLAIN, wx.stc.STC_INDIC_SQUIGGLE,
wx.stc.STC_INDIC_TT, wx.stc.STC_INDIC_DIAGONAL,
wx.stc.STC_INDIC_STRIKE, wx.stc.STC_INDIC_HIDDEN,
wx.stc.STC_INDIC_BOX, wx.stc.STC_INDIC_ROUNDBOX)
|
spellGetAvailableLanguages(cls)
Class Method
|
|
Return a list of supported languages.
Pyenchant supplies a list of its supported languages, so this is just
a simple wrapper around its list_languages function. Each
item in the list is a text string indicating the locale name, e.g.
en_US, ru, ru_RU, eo, es_ES, etc.
- Returns:
- a list of text strings indicating the supported languages
|
spellSetLanguage(self,
lang)
|
|
Set the language for spelling check.
The string should be in language locale format, e.g. en_US, ru,
ru_RU, eo, es_ES, etc. See spellGetAvailableLanguages.
- Parameters:
lang - text string indicating the language
|
spellSetMinimumWordSize(self,
size)
|
|
Set the minimum word size that will be looked up in the
dictionary.
Words smaller than this size won't be spell checked.
|
|
Get a dictionary.
Using the language specified in spellSetLanguage, return a pyenchant dictionary instance
that can be used to check spelling.
Currently, no caching is used -- it returns a new dictionary object
every time this method is called.
- Returns:
- pyenchant dictionary if a valid one was found for the current
language, or None if there is no dictionary for the language.
|
spellCheckRange(self,
start,
end)
|
|
Perform a spell check over a range of text in the document.
This is the main spell checking routine -- it loops over the range of
text using the spellFindNextWord method to break the text into words to
check. Misspelled words are highlighted using the current indicator.
- Parameters:
start - starting position
end - last position to check
|
spellFindNextWord(self,
utext,
index,
length)
|
|
Find the next valid word to check.
Designed to be overridden in subclasses, this method takes a starting
position in an array of text and returns a tuple indicating the next
valid word in the string.
- Parameters:
utext - array of unicode chars
i - starting index within the array to search
length - length of the text
- Returns:
- tuple indicating the word start and end indexes, or (-1, -1)
indicating that the end of the array was reached and no word was
found
|