def set_meter(self): self.btn_prv = sh.Button (parent = self.frm ,hint = _('Go to the preceding record') ,inactive = self.prev_inactive ,active = self.prev_active ,text = '←' ,hdir = 'bottom' ,side = 'left' ,bindings = '<Alt-Left>' ) # Show the current record #/total records ratio self.lbl_mtr = sh.Label (parent = self.frm ,text = '0 / 0' ,expand = False ,side = 'left' ) sh.ToolTip (obj = self.lbl_mtr ,text = _('Album ID') ,hdir = 'bottom' ) self.btn_nxt = sh.Button (parent = self.frm ,hint = _('Go to the following record') ,inactive = self.next_inactive ,active = self.next_active ,text = '→' ,hdir = 'bottom' ,side = 'left' ,bindings = '<Alt-Right>' )
def check_titles(self): # Do after 'self.check_tabs' f = '[MClient] plugins.multitrancom.utils.subjects.fix.Fix.check_titles' if self.Success: mes = [] for i in range(len(self.lst)): for j in range(len(self.lst[i])): ''' The presence of a dot is not enough, e.g., 'SAP.tech.' -> 'SAP tech.' ''' if (j + 1) % 2 == 0 \ and self.lst[i][j] == self.lst[i][j-1] \ and '.' in self.lst[i][j]: sub = _('Line #{}, column #{}: "{}"') sub = sub.format(i+1,j+1,self.lst[i][j]) mes.append(sub) if mes: self.Success = False sub = _('Errors in total: {}').format(len(mes)) mes.insert(0,sub) mes.insert(1,_('Abbreviations instead of titles:')) mes = '\n'.join(mes) sh.objs.get_mes(f,mes).show_warning() else: sh.com.cancel(f)
def _read_header(self): # This method is internal and should be wrapped with try-except self.obj.seek(0) # Check header parameters header = self.obj.read(10) #TODO: fail on error if header[:2] != b'\x1f\x8b': message = _('GZIP signature is expected, but found "{}"!') message = message.format(header[:2]) raise ValueError(message) if header[2] != 8: raise ValueError(_('Only DEFLATE archives are supported!')) flags = header[3] if not flags & (1 << 2): raise ValueError(_('An extra dictzip field is expected!')) # Read dictzip data XLEN, SI1, SI2, LEN = struct.unpack('<H2cH', self.obj.read(6)) if SI1 + SI2 != b'RA': raise ValueError(_('An RA signature is expected!')) data = self.obj.read(LEN) VER, CHLEN, CHCNT = struct.unpack('<3H', data[:6]) sizes = struct.unpack('<' + str(CHCNT) + 'H', data[6:]) # Skip filename if present if flags & (1 << 3): while self.obj.read(1) != b'\x00': pass # Transform sizes into start offsets of chunks ofs = [self.obj.tell()] for s in sizes[:-1]: ofs.append(ofs[-1] + s) return CHLEN, sizes, ofs
def set_suggested(self): # Takes ~0.005s for 'set' (EN-RU) on AMD E-300 f = '[MClient] plugins.multitrancom.elems.Elems.set_suggested' count = 0 i = self.get_suggested() if i is None: sh.com.rep_lazy(f) else: rowno = self.blocks[i].rowno self.blocks[i].type_ = 'dic' self.blocks[i].text = _('Suggestions') self.blocks[i].dic = _('Suggestions') self.blocks[i].dicf = _('Suggestions') self.blocks[i].same = 0 count += 1 i += 1 while i < len(self.blocks): if self.blocks[i].rowno == rowno: if self.blocks[i].text != '; ': self.blocks[i].type_ = 'term' self.blocks[i].same = 0 count += 1 else: break i += 1 sh.com.rep_matches(f, count)
def get(self, search): f = '[MClient] plugins.stardict.get.AllDics.get' if self.Success: if search: dics = [dic for dic in self.dics if not dic.Block] lst = [] for dic in dics: ind = dic.search(search, True) # Returns True if ind >= 0 if str(ind).isdigit(): result = dic.get_dict_data(ind) if result: # Set offline dictionary title lst.append('<dic>{}</dic>{}'.format( dic.title, result)) mes = _('"{}" has matches for "{}"') mes = mes.format(dic.title, search) sh.objs.get_mes(f, mes, True).show_debug() else: mes = _('No matches for "{}"!') mes = mes.format(dic.title) sh.objs.get_mes(f, mes, True).show_info() return '\n'.join(lst) else: sh.com.rep_empty(f) else: sh.com.cancel(f)
def set_timeout(self): f = '[MClient] tests.Commands.set_timeout' import plugins.multitrancom.get as mc import plugins.stardict.get as sd self._set_timeout(module=sd, source=_('Offline'), timeout=1) self._set_timeout(module=mc, source=_('Multitran'), timeout=2) self._set_timeout(module=mc, source='multitran.com', timeout=3)
def set_values(self): self.blocks = [] self.htm = '' self.text = '' self.search = '' self.langint = ('English', 'Russian') self.langloc = (_('English'), _('Russian'))
def convert_ged(self): ''' - Reassign a subject title for blocks from the Great encyclopedic dictionary. - It's not enough just to get CELLNO of the Great encyclopedic dictionary and change DIC and DICF since DIC and DICF will be reassigned at 'self.fill'. - Takes ~0.0014s for 'set' (EN-RU) on AMD E-300 ''' f = '[MClient] plugins.multitrancom.elems.Elems.convert_ged' count = 0 geds = self._get_ged() for ged in geds: block = self._get_first_dic(ged.rowno) if block: block.dic = block.text = _('GED') block.dicf = _('Great Encyclopedic Dictionary') count += 1 else: sh.com.rep_empty(f) ''' The dictionary will be renamed, we do not need the comment duplicating it. ''' self.blocks.remove(ged) sh.com.rep_matches(f, count) sh.com.rep_deleted(f, len(geds))
def _debug_wanted(self): f = '[MClient] plugins.multitrancom.utils.subjects.compile.Missing._debug_wanted' nos = [i + 1 for i in range(len(self.lst_wanted))] headers = (_('#'), _('TEXT')) iterable = [nos, self.lst_wanted] mes = sh.FastTable(headers=headers, iterable=iterable, maxrow=50).run() return f + ':\n' + mes
def report(self): f = '[CompressMedia] tests.Compression.report' if self.Success: nos = [i + 1 for i in range(len(self.ifiles))] ''' old_sizes = [sh.com.get_human_size(ifile.old_size) \ for ifile in self.ifiles ] ''' new_sizes = [sh.com.get_human_size(ifile.new_size) \ for ifile in self.ifiles ] compression = ['{}%'.format(ifile.compression) \ for ifile in self.ifiles ] files = [ifile.file for ifile in self.ifiles] filesw = [ifile.filew for ifile in self.ifiles] iterable = [nos,files,filesw,new_sizes,compression] headers = (_('#'),_('INPUT FILE'),_('OUTPUT FILE') ,_('NEW SIZE'),_('COMPRESSION') ) mes = sh.FastTable (iterable = iterable ,headers = headers ).run() sh.com.run_fast_debug(f,mes) else: sh.com.cancel(f)
def save(self): f = '[unmusic] utils.Image.save' if self.Success: if self.path: if os.path.exists(self.path): mes = _('File "{}" already exists.') mes = mes.format(self.path) sh.objs.get_mes(f, mes, True).show_debug() self.Present = True elif self.bytes: mes = _('Save "{}"').format(self.path) sh.objs.get_mes(f, mes, True).show_info() iimage = im.Image() iimage.bytes_ = self.bytes iimage.get_loader() iimage.convert2rgb() iimage.save(self.path, 'JPEG') self.Processed = iimage.Success else: mes = _('Album {} has no cover!') mes = mes.format(self.albumid) sh.objs.get_mes(f, mes, True).show_debug() self.Skipped = True else: sh.com.rep_empty(f) else: sh.com.cancel(f)
def set_present(self): self.cbx_loc = sh.CheckBox (parent = self.frm_prs ,side = 'left' ) self.lbl_loc = sh.Label (parent = self.frm_prs ,text = _('local collection') ,side = 'left' ) self.cbx_ext = sh.CheckBox (parent = self.frm_prs ,side = 'left' ) self.lbl_ext = sh.Label (parent = self.frm_prs ,text = _('external collection') ,side = 'left' ) self.cbx_mob = sh.CheckBox (parent = self.frm_prs ,side = 'left' ) self.lbl_mob = sh.Label (parent = self.frm_prs ,text = _('mobile collection') ,side = 'left' ) ''' We can call 'cbx_loc.widget.config(state="disabled")' but this makes the checkbox indistinguishable. ''' self.cbx_loc.reset(action=self.cbx_loc.toggle) self.cbx_ext.reset(action=self.cbx_ext.toggle) self.cbx_mob.reset(action=self.cbx_mob.toggle)
def try_sources(self): f = '[MClient] logic.Welcome.try_sources' old = objs.get_plugins().source dics = objs.plugins.get_online_sources() if dics: for dic in dics: objs.plugins.set(dic) source = Source() source.title = dic if objs.plugins.is_accessible(): source.status = _('running') source.color = 'green' self.sources.append(source) else: sh.com.rep_empty(f) # Try Stardict objs.plugins.set(_('Stardict')) self.sdstat = objs.get_plugins().is_accessible() if self.sdstat: self.sdcolor = 'green' # Try local Multitran objs.plugins.set(_('Local MT')) self.mtbstat = objs.plugins.is_accessible() if self.mtbstat: self.mtbcolor = 'green' # Try DSL objs.plugins.set('Lingvo (DSL)') self.lgstat = objs.plugins.is_accessible() if self.lgstat: self.lgcolor = 'green' objs.plugins.set(old)
def replace(self): f = '[MClient] plugins.dsl.cleanup.TagLike.replace' if self.Success: if self.start: count = 0 self.code = list(self.code) i = len(self.start) - 1 while i >= 0: if self.start[i] < self.end[i] < len(self.code): ''' That should be fine except when tag-like structures are embedded in each other (that should never happen though). ''' count += 1 pos1 = self.end[i] - 1 pos2 = self.end[i] + 1 self.code[pos1:pos2] = ')' pos1 = self.start[i] pos2 = self.start[i] + 2 self.code[pos1:pos2] = '(' else: sub = '{} < {} < {}'.format(self.start[i], self.end[i], len(self.code)) mes = _('The condition "{}" is not observed!') mes = mes.format(sub) sh.objs.get_mes(f, mes).show_error() i -= 1 self.code = ''.join(self.code) if count: mes = _('{} matches').format(count) sh.objs.get_mes(f, mes, True).show_debug() else: sh.com.rep_lazy(f) else: sh.com.cancel(f)
def prioritize(self): f = '[MClient] logic.SpeechPrior.prioritize' if self.Success: lst = [i + 1 for i in range(len(self.abbr))] for i in range(len(self.order)): try: ind = self.full.index(self.order[i]) self.prior[ind] = lst[i] except ValueError: mes = _('Wrong input data: "{}"!') mes = mes.format(self.order[i]) sh.objs.get_mes(f,mes,True).show_warning() lst = lst[len(self.order):] try: ind = self.full.index(_('Phrase')) self.prior[ind] = 1000 lst = lst[:-1] except ValueError: pass j = 0 for i in range(len(self.prior)): if self.prior[i] == -1: self.prior[i] = lst[j] j += 1 else: sh.com.cancel(f)
def get(self): f = '[MClient] plugins.multitrancom.get.Get.get' if self.Success: while not self.text: try: mes = _('Get online: "{}"').format(self.pattern) sh.objs.get_mes(f,mes,True).show_info() ''' - If the page is loaded using "page=urllib.request.urlopen(my_url)", we get HTTPResponse as a result, which is useful only to remove JavaScript tags. Thus, if we remove all excessive tags manually, then we need a string as output. - If 'self.url' is empty, then an error is thrown. ''' self.text = urllib.request.urlopen (self.url ,None ,TIMEOUT ).read() mes = _('[OK]: "{}"').format(self.pattern) sh.objs.get_mes(f,mes,True).show_info() # Too many possible exceptions except Exception as e: mes = _('[FAILED]: "{}"').format(self.pattern) sh.objs.get_mes(f,mes,True).show_error() # For some reason, 'break' does not work here mes = _('Unable to get the webpage. Do you want to try again?\n\nDetails: {}') mes = mes.format(e) if not sh.objs.get_mes(f,mes).show_question(): return else: sh.com.cancel(f)
def _debug_rows(self): f = '[MClient] plugins.multitrancom.utils.subjects.extract.EndPage._debug_rows' # 'self.rows' contains blocks of certain types count = 0 for row in self.rows: for block in row: count += 1 nos = [i + 1 for i in range(count)] rownos = [] types = [] texts = [] dic = [] dicf = [] for row in self.rows: for block in row: rownos.append(block.rowno) types.append(block.type_) texts.append(block.text) dic.append(block.dic) dicf.append(block.dicf) headers = (_('#'), _('ROW #'), 'DIC', 'DICF', _('TYPE'), _('TEXT')) iterable = [nos, rownos, dic, dicf, types, texts] # 10'' screen: 30 symbols mes = sh.FastTable(headers=headers, iterable=iterable, maxrow=30).run() return f + ':\n' + mes
def set_buttons(self): self.btn1 = sh.Button(parent=self.parent, text=_('Word Guesser'), side='top') self.btn2 = sh.Button(parent=self.parent, text=_('Word Scrambler'), side='top') self.btn1.focus()
def reset(self,event=None): self.opt_gnr.set(_('All')) self.opt_yer.set(_('Not set')) self.opt_src.set(_('external collection')) self.opt_trg.set(_('mobile collection')) self.ent_yer.reset() self.ent_lim.reset() self.ent_lim.insert(100) self.btn_str.focus()
def set_buttons(self): self.btn_can = sh.Button (parent = self.frm_btm ,text = _('Cancel') ,side = 'left' ) self.btn_ok1 = sh.Button (parent = self.frm_btm ,text = _('OK') ,side = 'right' )
def get_pages(self): f = '[MClient] plugins.multitrandem.tests.Binary.get_pages' self.get_block_size() if self.Success: if not self.pages: limits = self.get_page_limit() if limits: ''' These limits are based on the binary size, so we can read it without fearing an empty input. 'if limit' skips 'M' area (page 0). ''' limits = [limit * self.bsize \ for limit in range(limits) \ if limit ] for limit in limits: node = self.read(limit, limit + 1) if node == b'U': self.upages.append(limit) elif node == b'L': self.lpages.append(limit) elif node == b'Z': self.zpages.append(limit) else: sub = sh.com.set_figure_commas(limit) messages = [] mes = _('Position: {}').format(sub) messages.append(mes) mes = _('Wrong input data: "{}"!') mes = mes.format(node) messages.append(mes) mes = '\n'.join(messages) sh.objs.get_mes(f, mes).show_warning() break upages = [sh.com.set_figure_commas(item) \ for item in self.upages ] lpages = [sh.com.set_figure_commas(item) \ for item in self.lpages ] zpages = [sh.com.set_figure_commas(item) \ for item in self.zpages ] mes = _('U pages: {}').format(upages) sh.objs.get_mes(f, mes, True).show_debug() mes = _('L pages: {}').format(lpages) sh.objs.get_mes(f, mes, True).show_debug() mes = _('Z pages: {}').format(zpages) sh.objs.get_mes(f, mes, True).show_debug() self.pages = self.upages + self.lpages + self.zpages self.pages.sort() else: sh.com.rep_empty(f) else: sh.com.cancel(f) return self.pages
def set_buttons(self): self.btn1 = sh.Button(parent=self.frm4, side='left', text=_('Close'), hint=_('Close this window'), action=self.close) self.btn2 = sh.Button(parent=self.frm4, side='right', text=_('Guess'), hint=_('Guess missing characters in the word'))
def __init__(self): self.type = 'SaveArticle' self.items = [ _('Save the current view as a web-page (*.htm)'), _('Save the original article as a web-page (*.htm)'), _('Save the article as plain text in UTF-8 (*.txt)'), _('Copy the code of the article to clipboard'), _('Copy the text of the article to clipboard') ] self.set_gui()
def set_gui(self): self.parent = sh.Top (icon = ICON ,title = _('Image:') ) self.lbl = sh.Label (parent = self.parent ,text = _('Image:') ,expand = True ,fill = 'both' ) self.set_bindings()
def _debug_tags(self): nos = [i + 1 for i in range(len(self.tags))] closes = ['{}'.format(tag.Close) for tag in self.tags] names = ['"{}"'.format(tag.name) for tag in self.tags] types = ['"{}"'.format(tag.type_) for tag in self.tags] texts = ['"{}"'.format(tag.text) for tag in self.tags] urls = ['"{}"'.format(tag.url) for tag in self.tags] dicfs = ['"{}"'.format(tag.dicf) for tag in self.tags] rownos = ['{}'.format(tag.rowno) for tag in self.tags] cellnos = ['{}'.format(tag.cellno) for tag in self.tags] inherent = [] for tag in self.tags: subtags = [] for subtag in tag.inherent: subtags.append(subtag.name) subtags = ', '.join(subtags) inherent.append(subtags) iterable = [ nos, closes, names, types, texts, urls, dicfs, inherent, rownos, cellnos ] headers = (_('#'), _('CLOSING'), _('NAME'), _('TYPE'), _('TEXT'), 'URL', 'DICF', _('OPEN'), _('ROW'), _('CELL')) # 10'' monitor: 13 symbols per a column # 23'' monitor: 30 symbols per a column mes = sh.FastTable(iterable=iterable, headers=headers, maxrow=13, maxrows=self.maxrows).run() return _('Tags:') + '\n' + mes
def set_buttons(self): sh.Button(parent=self.frm_btn, action=self.reset, hint=_('Reset settings'), text=_('Reset'), side='left') self.btn_apl = sh.Button(parent=self.frm_btn, hint=_('Apply settings'), text=_('Apply'), side='right')
def _debug_blocks(self): nos = [i + 1 for i in range(len(self.blocks))] texts = [block.text for block in self.blocks] types = [block.type_ for block in self.blocks] iterable = [nos, types, texts] headers = (_('#'), _('TYPES'), _('TEXT')) mes = sh.FastTable(iterable=iterable, headers=headers, maxrow=50, maxrows=self.maxrows).run() return _('Blocks:') + '\n' + mes
def _debug_tagged(self): nos = [i + 1 for i in range(len(self.tagged))] texts = [item.text for item in self.tagged] tags = [', '.join(item.tags) for item in self.tagged] iterable = [nos, tags, texts] headers = (_('#'), _('TAGS'), _('TEXT')) mes = sh.FastTable(iterable=iterable, headers=headers, maxrow=50, maxrows=self.maxrows).run() return _('Tags:') + '\n' + mes
def _debug_abbr2full(self): f = '[MClient] logic.SpeechPrior._debug_abbr2full' abbr2full = self.get_abbr2full() if abbr2full: abbr = sorted(abbr2full.keys()) full = [abbr2full.get(item) for item in abbr] headers = (_('ABBREVIATION'),_('NAME')) iterable = [abbr,full] mes = sh.FastTable(iterable,headers).run() sh.com.run_fast_debug(f,mes) else: sh.com.rep_empty(f)
def _debug_full2abbr(self): f = '[MClient] logic.SpeechPrior._debug_full2abbr' full2abbr = self.get_full2abbr() if full2abbr: full = sorted(full2abbr.keys()) abbr = [full2abbr.get(item) for item in full] headers = (_('NAME'),_('ABBREVIATION')) iterable = [full,abbr] mes = sh.FastTable(iterable,headers).run() sh.com.run_fast_debug(f,mes) else: sh.com.rep_empty(f)