def dlg_import_choose_mcrs(self): l,lt = '\n', '\n ' while True: imp_file= app.dlg_file(True, '', '', 'Cuda macros|*.cuda-macros|All file|*.*') if imp_file is None: return (None, None) vers_mcrs = apx._json_loads(open(imp_file).read()) if vers_mcrs is None: if app.ID_OK != app.msg_box('No macros in file\n '+imp_file+'\n\nChoose another file?' ,app.MB_OKCANCEL): return (None, None) continue #while vers = vers_mcrs.get('vers', {}) if (app.app_api_version() < vers.get('ver-api', app.app_api_version()) and app.ID_OK != app.msg_box( 'Macros from' +lt+imp_file +l+ 'are recorded in CudaText with version' +lt+ '"{}"' +l+ 'Your CudaText has older version' +lt+ '"{}"' +l+ '' +l+ 'No guarantee of correct working!' +l+ '' +l+ 'Continue import?'.format(vers['ver-app'], app.app_exe_version()) , app.MB_OKCANCEL)): return (None, None) mcrs = vers_mcrs.get('macros', []) if 0!=len(mcrs): break #while if app.ID_OK != app.msg_box('No macros in file\n '+imp_file+'\n\nChoose another file?' ,app.MB_OKCANCEL): return (None, None) #while True: return (imp_file, mcrs)
def check_cudatext(): fn = os.path.join(tempfile.gettempdir(), 'cudatext_download.html') app.msg_status('Downloading: '+DOWNLOAD_PAGE, True) get_url(DOWNLOAD_PAGE, fn, True) app.msg_status('') if not os.path.isfile(fn): app.msg_status('Cannot download: '+DOWNLOAD_PAGE) return text = open(fn, encoding='utf8').read() items = re.findall(DOWNLOAD_REGEX, text) if not items: app.msg_status('Cannot find download links') return items = sorted(items, key=lambda i:i[REGEX_GROUP_VER], reverse=True) print('Found links:') for i in items: print(' '+i[0]) url = items[0][0] ver_inet = items[0][REGEX_GROUP_VER] ver_local = app.app_exe_version() if versions_ordered(ver_inet, ver_local): app.msg_box('Latest CudaText is already here.\nHere: %s\nInternet: %s' %(ver_local, ver_inet), app.MB_OK+app.MB_ICONINFO) return if app.msg_box('Newer CudaText is available.\nHere: %s\nInternet: %s\n\nOpen download URL in browser?' %(ver_local, ver_inet), app.MB_YESNO+app.MB_ICONINFO) == app.ID_YES: webbrowser.open_new_tab(url) print('Opened download URL')
def check_cudatext(): fn = os.path.join(tempfile.gettempdir(), 'cudatext_download.html') app.msg_status('Downloading: '+DOWNLOAD_PAGE, True) get_url(DOWNLOAD_PAGE, fn, True) app.msg_status('') if not os.path.isfile(fn): app.msg_status('Cannot download: '+DOWNLOAD_PAGE) return text = open(fn, encoding='utf8', errors='replace').read() items = re.findall(FILE_RE, text) if not items: app.msg_status('Cannot find download links') return items = sorted(items, reverse=True) print('Found links:') for i in items: print(' '+i[0]) url = items[0][0] ver_inet = items[0][REGEX_GROUP_VER] ver_local = app.app_exe_version() if versions_ordered(ver_inet, ver_local): app.msg_box('Latest CudaText is already here.\nLocal: %s\nInternet: %s' %(ver_local, ver_inet), app.MB_OK+app.MB_ICONINFO) return if app.msg_box('CudaText update is available.\nLocal: %s\nInternet: %s\n\nOpen download URL in browser?' %(ver_local, ver_inet), app.MB_YESNO+app.MB_ICONINFO) == app.ID_YES: webbrowser.open_new_tab(url) print('Opened download URL')
def dlg_import_choose_mcrs(self): l, lt = '\n', '\n ' while True: imp_file = app.dlg_file(True, '', '', 'Cuda macros|*.cuda-macros|All file|*.*') if imp_file is None: return (None, None) vers_mcrs = apx._json_loads(open(imp_file).read()) if vers_mcrs is None: if app.ID_OK != app.msg_box( 'No macros in file\n ' + imp_file + '\n\nChoose another file?', app.MB_OKCANCEL): return (None, None) continue #while vers = vers_mcrs.get('vers', {}) if (app.app_api_version() < vers.get('ver-api', app.app_api_version()) and app.ID_OK != app.msg_box( 'Macros from' + lt + imp_file + l + 'are recorded in CudaText with version' + lt + '"{}"' + l + 'Your CudaText has older version' + lt + '"{}"' + l + '' + l + 'No guarantee of correct working!' + l + '' + l + 'Continue import?'.format( vers['ver-app'], app.app_exe_version()), app.MB_OKCANCEL)): return (None, None) mcrs = vers_mcrs.get('macros', []) if 0 != len(mcrs): break #while if app.ID_OK != app.msg_box( 'No macros in file\n ' + imp_file + '\n\nChoose another file?', app.MB_OKCANCEL): return (None, None) #while True: return (imp_file, mcrs)
def export_to_file(self, exp_file, mcrs): pass; LOG and log('exp_file, mcrs={}',(exp_file, mcrs)) open(exp_file, 'w').write(json.dumps( { 'vers':{ 'ver-mcr':JSON_FORMAT_VER , 'ver-app':app.app_exe_version() , 'ver-api':app.app_api_version() } , 'macros':[{ 'nm': mcr['nm'] , 'evl': mcr['evl'] } for mcr in mcrs] } , indent=4))
def adapt_menu(self,id_menu=0): ''' Add or change top-level menu Macros Param id_menu points to exist menu item (ie by ConfigMenu) for filling ''' pass; LOG and log('id_menu={}',id_menu) PLUG_HINT = '_'+'cuda_macros:adapt_menu' # "_" is sign for ConfigMenu. ":" is subst for "," to avoid call "import ..." if id_menu!=0: # Use this id app.app_proc(app.PROC_MENU_CLEAR, str(id_menu)) else: top_nms = app.app_proc(app.PROC_MENU_ENUM, 'top') if PLUG_HINT in top_nms: # Reuse id from 'top' inf = [inf for inf in top_nms.splitlines() if PLUG_HINT in inf][0] ##?? id_menu = inf.split('|')[2] app.app_proc(app.PROC_MENU_CLEAR, id_menu) else: # Create BEFORE Plugins top_nms = top_nms.splitlines() pass; #LOG and log('top_nms={}',top_nms) if app.app_exe_version() >= '1.0.131': plg_ind = [i for (i,nm) in enumerate(top_nms) if '|plugins' in nm][0] else: # old, pre i18n plg_ind = top_nms.index('&Plugins|') ##?? id_menu = app.app_proc( app.PROC_MENU_ADD, '{};{};{};{}'.format('top', PLUG_HINT, _('&Macros'), plg_ind)) # Fill def hotkeys_desc(cmd_id): hk_s= get_hotkeys_desc(cmd_id) hk_s= '\t\t'+hk_s if hk_s else hk_s return hk_s hk_s = hotkeys_desc( 'cuda_macros,dlg_config') app.app_proc(app.PROC_MENU_ADD, '{};{};{}'.format(id_menu, 'cuda_macros,dlg_config',_('&Macros...')+hk_s)) app.app_proc(app.PROC_MENU_ADD, '{};;-'.format( id_menu)) hk_s = hotkeys_desc( cmds.cmd_MacroStart) app.app_proc(app.PROC_MENU_ADD, '{};{};{}'.format(id_menu, cmds.cmd_MacroStart, _('&Start record')+hk_s)) hk_s = hotkeys_desc( cmds.cmd_MacroStop) app.app_proc(app.PROC_MENU_ADD, '{};{};{}'.format(id_menu, cmds.cmd_MacroStop, _('St&op record')+hk_s)) hk_s = hotkeys_desc( cmds.cmd_MacroCancel) app.app_proc(app.PROC_MENU_ADD, '{};{};{}'.format(id_menu, cmds.cmd_MacroCancel, _('&Cancel record')+hk_s)) app.app_proc(app.PROC_MENU_ADD, '{};;-'.format( id_menu)) hk_s = hotkeys_desc( 'cuda_macros,dlg_export') app.app_proc(app.PROC_MENU_ADD, '{};{};{}'.format(id_menu, 'cuda_macros,dlg_export',_('&Export...')+hk_s)) hk_s = hotkeys_desc( 'cuda_macros,dlg_import') app.app_proc(app.PROC_MENU_ADD, '{};{};{}'.format(id_menu, 'cuda_macros,dlg_import',_('&Import...')+hk_s)) if 0==len(self.macros): return app.app_proc(app.PROC_MENU_ADD, '{};;-'.format( id_menu)) id_sub = app.app_proc(app.PROC_MENU_ADD, '{};{};{}'.format(id_menu, 0, _('&Run'))) for mcr in self.macros: hk_s= hotkeys_desc( f('cuda_macros,run,{}',mcr['id'])) app.app_proc(app.PROC_MENU_ADD, '{};{}{};{}'.format(id_sub, 'cuda_macros,run,' ,mcr['id'], mcr['nm']+hk_s))
def export_to_file(self, exp_file, mcrs): pass LOG and log('exp_file, mcrs={}', (exp_file, mcrs)) open(exp_file, 'w').write( json.dumps( { 'vers': { 'ver-mcr': JSON_FORMAT_VER, 'ver-app': app.app_exe_version(), 'ver-api': app.app_api_version() }, 'macros': [{ 'nm': mcr['nm'], 'evl': mcr['evl'] } for mcr in mcrs] }, indent=4))
def check_cudatext(): fn = os.path.join(tempfile.gettempdir(), 'cudatext_download.html') app.msg_status('Downloading: ' + DOWNLOAD_PAGE, True) get_url(DOWNLOAD_PAGE, fn, True) app.msg_status('') if not os.path.isfile(fn): app.msg_status('Cannot download: ' + DOWNLOAD_PAGE) return text = open(fn, encoding='utf8').read() items = re.findall(DOWNLOAD_REGEX, text) if not items: app.msg_status('Cannot find download links') return items = sorted(items, key=lambda i: i[1], reverse=True) print('Found links:') for i in items: print(' ' + i[0]) url = items[0][0] ver_inet = items[0][1] ver_local = app.app_exe_version() #ver_inet = '1.10.0.2' #test #ver_local = '0' #test if versions_ordered(ver_inet, ver_local): app.msg_box( 'Latest CudaText is already here\nHere: %s\nInternet: %s' % (ver_local, ver_inet), app.MB_OK + app.MB_ICONINFO) return text = '\n'.join([ 'type=label\1pos=6,20,500,0\1cap=CudaText newer version is available at this URL:', 'type=linklabel\1pos=6,45,800,0\1cap=' + url + '\1props=' + url + '\1font_size=9', 'type=button\1pos=300,100,400,0\1cap=OK\1props=1' ]) app.dlg_custom('CudaText update', 700, 132, text)