def on_translation(self, old, new): # Check for new output. for a in reversed(new): if a.text and not a.text.isspace(): break else: return # Get previous words equal to the maximum possible search result count. with self._engine: last_translations = self._engine.translator_state.translations retro_formatter = RetroFormatter(last_translations) split_words = retro_formatter.last_words(self._word_limit, rx=self.WORD_RX) suggestion_list = [] for phrase in self.tails(split_words): phrase = ''.join(phrase) suggestion_list.extend(self._engine.get_suggestions(phrase)) if not suggestion_list and split_words: suggestion_list = [Suggestion(split_words[-1], [])] if suggestion_list and suggestion_list != self._last_suggestions: self._last_suggestions = suggestion_list self._show_suggestions(suggestion_list)
def on_translation(self, old, new): for action in old: remove = len(action.text) if remove > 0: self._words = self._words[:-remove] self._words = self._words + action.replace for action in new: remove = len(action.replace) if remove > 0: self._words = self._words[:-remove] self._words = self._words + action.text # Limit phrasing memory to 100 characters, because most phrases probably # don't exceed this length self._words = self._words[-100:] suggestion_list = [] split_words = self.WORDS_RX.findall(self._words) for phrase in self.tails(split_words): phrase = u' '.join(phrase) suggestion_list.extend(self._engine.get_suggestions(phrase)) if not suggestion_list and split_words: suggestion_list = [Suggestion(split_words[-1], [])] if suggestion_list and suggestion_list != self._last_suggestions: self._last_suggestions = suggestion_list self._show_suggestions(suggestion_list)
def show_stroke(self, old, new): for action in old: remove = len(action.text) self.words = self.words[:-remove] self.words = self.words + action.replace for action in new: remove = len(action.replace) if remove > 0: self.words = self.words[:-remove] self.words = self.words + action.text # Limit phrasing memory to 100 characters, because most phrases probably # don't exceed this length self.words = self.words[-100:] suggestion_list = [] split_words = PAT.findall(self.words) for phrase in SuggestionsDisplayDialog.tails(split_words): phrase = u' '.join(phrase) suggestion_list.extend(self.engine.get_suggestions(phrase)) if not suggestion_list and split_words: suggestion_list = [Suggestion(split_words[-1], [])] if suggestion_list: self.show_suggestions(suggestion_list)