def reorder(self): if len(self.blocks) > 1: pos = -1 for i in range(len(self.blocks)): if self.blocks[i].type_ == 'dic': pos = i break if pos >= 0: self.blocks.append(self.blocks[pos]) del self.blocks[pos] pos = -1 for i in range(len(self.blocks)): if self.blocks[i].type_ == 'comment': pos = i break if pos >= 0: self.blocks.append(self.blocks[pos]) del self.blocks[pos] if sh.Text(self.pattern).has_cyrillic(): for i in range(len(self.blocks)): if self.blocks[i-1].type_ == 'term' \ and self.blocks[i].type_ == 'term' \ and self.blocks[i-1].lang != 2 \ and self.blocks[i].lang == 2: self.blocks[ i - 1], self.blocks[i] = self.blocks[i], self.blocks[i - 1]
def swap_dics(self): for i in range(len(self.blocks)): if self.is_dic(self.blocks[i]): Condition = False if i > 0: if sh.Text(text=self.blocks[i]).has_cyrillic() \ and sh.Text(text=self.blocks[i-1]).has_latin(): Condition = True elif sh.Text(text=self.blocks[i]).has_latin() \ and sh.Text(text=self.blocks[i-1]).has_cyrillic(): Condition = True if Condition: self.blocks[ i - 1], self.blocks[i] = self.blocks[i], self.blocks[i - 1] return self.blocks
def get_priorities(self): f = '[MClient] logic.Lists.get_priorities' if self.Success: text = sh.ReadTextFile(self.priorlst,True).get() text = sh.Text(text,True).text return text.splitlines() else: sh.com.cancel(f)
def run(self): f = '[MClient] plugins.dsl.cleanup.CleanUp.run' if self.text: self.delete_trash() self.text = sh.Text(self.text).delete_unsupported() return self.text else: sh.com.rep_empty(f) return ''
def run(self): f = '[MClient] plugins.stardict.cleanup.Common.run' if self.text: self.decode_entities() self.delete_trash() self.text = sh.Text(self.text).delete_unsupported() return self.text else: sh.com.rep_empty(f) return ''
def pretty(self): f = '[Samurai] samurai.Parse.pretty' timer = sh.Timer(f) #TODO: del timer.start() #TODO: del if self.text: text = sh.Text(text=self.text) text.convert_line_breaks() text.strip_lines() text.tabs2spaces() text.replace_x() text.delete_duplicate_spaces() self.text = text.text # Allow only 2 consequent line breaks while '\n\n\n' in self.text: self.text = self.text.replace('\n\n\n','\n\n') else: sh.com.rep_empty(f) timer.end() #TODO: del
def gen_poses(self): ''' We generate positions here according to the text produced by TkinterHtml's 'widget.text()' command. Peculiarities of the retrieved text: - TkinterHtml adds some empty lines from the top and the bottom; - The number of these lines varies each time (and we don't know the rule according to which they are generated) - Each cell occupies a single line - Blocks within a cell are spaced with a single space (except for the blocks having such text as '(') - Each line is stripped - Pos2 of the previous cell and pos1 of the next cell are sometimes equal; this corresponds to the position system used by Tkinter - Duplicate spaces are removed ''' f = '[MClient] cells.Pos.gen_poses' last = 0 not_found = [] for block in self.blocks: text = sh.Text(block.text.strip()).delete_duplicate_spaces() if text: search = sh.Search(text=self.rawtext, pattern=text) search.i = last result = sh.Input(f, search.get_next()).get_integer() if result >= last: block.first = result else: block.first = last not_found.append(text) else: block.first = last block.last = block.first + len(text) last = block.last ''' This may be caused by the following: a) Missing types in db.DB.types b) Defective HTML generation algorithm ''' if not_found: not_found = ['"' + item + '"' for item in not_found] not_found = '\n' + '\n'.join(not_found) mes = _('Unable to find: {}').format(not_found) sh.objs.get_mes(f, mes).show_error()
def run(self): f = '[MClient] plugins.multitrancom.cleanup.CleanUp.run' if self.text: self.delete_trash_tags() self.fix_href() self.fix_tags() self.run_common() ''' #TODO: do we really need this heaviest operation (takes ~0.53s for 'set' (EN-RU) on AMD E-300, whereas the entire module takes ~0.58s, since we have already deleted unicode control codes? ''' # Delete a non-breaking space before a user name self.text = self.text.replace(' ',' ') self.text = sh.Text(self.text).delete_unsupported() return self.text else: sh.com.rep_empty(f) return ''
def check(self): f = '[shared] spelling.Spelling.check' ''' We do not warn about empty input/output since this happens quite often. Moreover, we return True in such cases since this is actually not a spelling error. ''' if self.word: self.word = self.word.strip() itext = sh.Text(self.word) self.word = itext.delete_punctuation() if self.word and not itext.has_digits(): if len(self.word) == 1: return True elif itext.has_cyrillic(): return self.ru.check(self.word) elif itext.has_latin(): return self.gb.check(self.word) \ or self.us.check(self.word) else: # Ignore an empty input and words with digits return True else: return True
def _break_word(self, word): lst = sh.Text(word).split_by_len(self.max_word_len) return ' '.join(lst)