本文整理汇总了Python中enchant.checker.SpellChecker.next方法的典型用法代码示例。如果您正苦于以下问题:Python SpellChecker.next方法的具体用法?Python SpellChecker.next怎么用?Python SpellChecker.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类enchant.checker.SpellChecker
的用法示例。
在下文中一共展示了SpellChecker.next方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: spellChecker
# 需要导入模块: from enchant.checker import SpellChecker [as 别名]
# 或者: from enchant.checker.SpellChecker import next [as 别名]
class spellChecker(object):
def __init__(self, text, dictionary):
super(spellChecker, self).__init__()
log.debug("Creating the SpellChecker object. Dictionary: %s" % (dictionary,))
self.active = True
try:
if config.app["app-settings"]["language"] == "system":
log.debug("Using the system language")
self.checker = SpellChecker(languageHandler.curLang, filters=[tokenize.EmailFilter, tokenize.URLFilter])
else:
log.debug("Using language: %s" % (languageHandler.getLanguage(),))
self.checker = SpellChecker(languageHandler.curLang, filters=[tokenize.EmailFilter, tokenize.URLFilter])
self.checker.set_text(text)
except DictNotFoundError:
print "no dict"
log.exception("Dictionary for language %s not found." % (dictionary,))
wx_ui.dict_not_found_error()
self.active = False
if self.active == True:
log.debug("Creating dialog...")
self.dialog = wx_ui.spellCheckerDialog()
widgetUtils.connect_event(self.dialog.ignore, widgetUtils.BUTTON_PRESSED, self.ignore)
widgetUtils.connect_event(self.dialog.ignoreAll, widgetUtils.BUTTON_PRESSED, self.ignoreAll)
widgetUtils.connect_event(self.dialog.replace, widgetUtils.BUTTON_PRESSED, self.replace)
widgetUtils.connect_event(self.dialog.replaceAll, widgetUtils.BUTTON_PRESSED, self.replaceAll)
self.check()
self.dialog.get_response()
self.fixed_text = self.checker.get_text()
def check(self):
try:
self.checker.next()
textToSay = _(u"Misspelled word: %s") % (self.checker.word,)
context = u"... %s %s %s" % (self.checker.leading_context(10), self.checker.word, self.checker.trailing_context(10))
self.dialog.set_title(textToSay)
output.speak(textToSay)
self.dialog.set_word_and_suggestions(word=self.checker.word, context=context, suggestions=self.checker.suggest())
except StopIteration:
log.debug("Process finished.")
wx_ui.finished()
self.dialog.Destroy()
def ignore(self, ev):
self.check()
def ignoreAll(self, ev):
self.checker.ignore_always(word=self.checker.word)
self.check()
def replace(self, ev):
self.checker.replace(self.dialog.get_selected_suggestion())
self.check()
def replaceAll(self, ev):
self.checker.replace_always(self.dialog.get_selected_suggestion())
self.check()
def clean(self):
if hasattr(self, "dialog"):
self.dialog.Destroy()
示例2: SpellCheck
# 需要导入模块: from enchant.checker import SpellChecker [as 别名]
# 或者: from enchant.checker.SpellChecker import next [as 别名]
class SpellCheck(wx.Panel):
def __init__(self, parent):
self.parent = parent
wx.Panel.__init__(self, parent, -1)
self.pref = Globals.pref
self.sizer = sizer = ui.VBox(padding=0, namebinding='widget').create(self).auto_layout()
h = sizer.add(ui.HBox)
h.add(ui.Label(tr("Replace with") + ':'))
h.add(ui.Text('', size=(150, -1)), name='text')
h.add(ui.Button(tr('Start')), name='btnRun').bind('click', self.OnRun)
h.add(ui.Button(tr('Replace')), name='btnReplace').bind('click', self.OnReplace)
h.add(ui.Button(tr('Replace All')), name='btnReplaceAll').bind('click', self.OnReplaceAll)
h.add(ui.Button(tr('Ignore')), name='btnIgnore').bind('click', self.OnIgnore)
h.add(ui.Button(tr('Ignore All')), name='btnIgnoreAll').bind('click', self.OnIgnoreAll)
h.add(ui.Button(tr('Add')), name='btnAdd').bind('click', self.OnAdd)
h = sizer.add(ui.HBox, proportion=1)
h.add(ui.Label(tr("Suggest") + ':'))
h.add(ui.ListBox(size=(250, -1)), name='list').binds(
(wx.EVT_LISTBOX, self._OnReplSelect),
(wx.EVT_LISTBOX_DCLICK, self.OnReplace),
)
h.add(ui.Label(tr("Available Dict") + ':'))
h.add(ui.ListBox(size=(100, -1), choices=enchant.list_languages()), name='dict_list').bind(
wx.EVT_LISTBOX, self.OnDictSelect
)
sizer.auto_fit(0)
self.init()
self._DisableButtons()
def init(self):
defLoc = locale.getdefaultlocale()[0]
if self.pref.default_spellcheck_dict:
defLoc = self.pref.default_spellcheck_dict
index = self.dict_list.FindString(defLoc)
if index > -1:
self.dict_list.SetSelection(index)
else:
defLoc = 'en_US'
self.pref.default_spellcheck_dict = defLoc
self.pref.save()
#todo add multi dict support
self.chkr = SpellChecker(defLoc)
self.mainframe = Globals.mainframe
self._buttonsEnabled = True
self.running = False
def OnRun(self, event):
if self.running:
self.running = False
self._DisableButtons()
else:
self.running = True
self.document = self.mainframe.document
if self.document.edittype != 'edit':
common.showerror(self, tr("This document can't be spell checked"))
return
self.begin_line = 0
self.begin_pos = 0
self.last_line_pos = 0
self.last_col = 0
self.ignore_list = []
self.new = True
self._Advance()
def _Advance(self):
"""Advance to the next error.
This method advances the SpellChecker to the next error, if
any. It then displays the error and some surrounding context,
and well as listing the suggested replacements.
"""
# Advance to next error, disable if not available
while 1:
try:
if self.new:
self.begin_pos = self.document.PositionFromLine(self.begin_line)
line = self.document.getLineText(self.begin_line)
line_len = self.document.GetLineEndPosition(self.begin_line) - self.begin_pos
new = False
if self.last_line_pos < line_len:
self.chkr.set_text(line[self.last_col:])
self.chkr.next()
# while self.chkr.word in self.ignore_list:
# self.chkr.next()
# pass
self.last_col += self.chkr.wordpos
self.last_line_pos = len(line[:self.last_col].encode('utf-8'))
break
except StopIteration:
if self.begin_line < self.document.GetLineCount():
self.begin_line += 1
#.........这里部分代码省略.........
示例3: spellCheckerDialog
# 需要导入模块: from enchant.checker import SpellChecker [as 别名]
# 或者: from enchant.checker.SpellChecker import next [as 别名]
class spellCheckerDialog(wx.Dialog):
def __init__(self, text, dictionary):
super(spellCheckerDialog, self).__init__(None, 1)
try:
if config.main["general"]["language"] == "system": self.checker = SpellChecker()
else: self.checker = SpellChecker(languageHandler.getLanguage())
self.checker.set_text(text)
except DictNotFoundError:
wx.MessageDialog(None, _(u"A bug has happened. There are no dictionaries available for the selected language in TW Blue"), _(u"Error"), wx.ICON_ERROR).ShowModal()
self.Destroy()
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
word = wx.StaticText(panel, -1, _(u"Mis-spelled word"))
self.word = wx.TextCtrl(panel, -1)
wordBox = wx.BoxSizer(wx.HORIZONTAL)
wordBox.Add(word)
wordBox.Add(self.word)
context = wx.StaticText(panel, -1, _(u"Context"))
self.context = wx.TextCtrl(panel, -1)
contextBox = wx.BoxSizer(wx.HORIZONTAL)
contextBox.Add(context)
contextBox.Add(self.context)
suggest = wx.StaticText(panel, -1, _(u"Suggestions"))
self.suggestions = wx.ListBox(panel, -1, choices=[], style=wx.LB_SINGLE)
suggestionsBox = wx.BoxSizer(wx.HORIZONTAL)
suggestionsBox.Add(suggest)
suggestionsBox.Add(self.suggestions)
ignore = wx.Button(panel, -1, _(u"Ignore"))
self.Bind(wx.EVT_BUTTON, self.onIgnore, ignore)
ignoreAll = wx.Button(panel, -1, _(u"Ignore all"))
self.Bind(wx.EVT_BUTTON, self.onIgnoreAll, ignoreAll)
replace = wx.Button(panel, -1, _(u"Replace"))
self.Bind(wx.EVT_BUTTON, self.onReplace, replace)
replaceAll = wx.Button(panel, -1, _(u"Replace all"))
self.Bind(wx.EVT_BUTTON, self.onReplaceAll, replaceAll)
close = wx.Button(panel, wx.ID_CANCEL)
btnBox = wx.BoxSizer(wx.HORIZONTAL)
btnBox.Add(ignore)
btnBox.Add(ignoreAll)
btnBox.Add(replace)
btnBox.Add(replaceAll)
btnBox.Add(close)
sizer.Add(wordBox)
sizer.Add(contextBox)
sizer.Add(suggestionsBox)
sizer.Add(btnBox)
panel.SetSizerAndFit(sizer)
self.check()
def check(self):
try:
self.checker.next()
textToSay = _(u"Mis-spelled word: %s") % (self.checker.word,)
context = u"... %s %s %s" % (self.checker.leading_context(10), self.checker.word, self.checker.trailing_context(10))
self.SetTitle(textToSay)
output.speak(textToSay)
self.word.SetValue(self.checker.word)
self.context.ChangeValue(context)
self.suggestions.Set(self.checker.suggest())
self.suggestions.SetFocus()
except StopIteration:
wx.MessageDialog(self, _(u"The spelling review has finished."), _("Finished"), style=wx.OK).ShowModal()
self.EndModal(wx.ID_OK)
except AttributeError:
pass
def onIgnore(self, ev):
self.check()
def onIgnoreAll(self, ev):
self.checker.ignore_always(word=self.checker.word)
self.check()
def onReplace(self, ev):
self.checker.replace(self.suggestions.GetStringSelection())
self.check()
def onReplaceAll(self, ev):
self.checker.replace_always(self.suggestions.GetStringSelection())
self.check()