Esempio n. 1
0
def top_plus_for_os(what_control, base_control='edit'):
    ''' Addition for what_top to align text with base.
        Params
            what_control    'check'/'label'/'edit'/'button'/'combo'/'combo_ro'
            base_control    'check'/'label'/'edit'/'button'/'combo'/'combo_ro'
    '''
    if what_control==base_control:
        return 0
    env = sys.platform
    if base_control=='edit': 
        if env=='win32':
            return apx.icase(what_control=='check',    1
                            ,what_control=='label',    3
                            ,what_control=='button',  -1
                            ,what_control=='combo_ro',-1
                            ,what_control=='combo',    0
                            ,True,                     0)
        if env=='linux':
            return apx.icase(what_control=='check',    1
                            ,what_control=='label',    5
                            ,what_control=='button',   1
                            ,what_control=='combo_ro', 0
                            ,what_control=='combo',   -1
                            ,True,                     0)
        if env=='darwin':
            return apx.icase(what_control=='check',    2
                            ,what_control=='label',    3
                            ,what_control=='button',   0
                            ,what_control=='combo_ro', 1
                            ,what_control=='combo',    0
                            ,True,                     0)
        return 0
       #if base_control=='edit'
    return top_plus_for_os(what_control, 'edit') - top_plus_for_os(base_control, 'edit')
    def open(self, ssnew=None):
        ''' Open new session from file ssnew or after user asking '''
        if not _checkAPI(): return
        #       in_dir      = app.app_path(app.APP_DIR_DATA)
        sscur = app.app_path(app.APP_FILE_SESSION)
        sscur_save = app.app_proc(app.PROC_SAVE_SESSION, sscur)
        pass
        #LOG and log('sscur_save={}',(sscur_save))
        if sscur_save == False:
            return
        if ssnew is None:
            ssnew = app.dlg_file(
                is_open=True,
                filters=DLG_ALL_FILTER,
                init_filename='!'  # '!' to disable check "filename exists"
                ,
                init_dir='')
        if ssnew is None: return
        if ssnew.endswith(SWSESS_EXT) and os.path.isfile(ssnew):
            # Import from Syn
            sssyn = ssnew
            sscud = ssnew[:-len(SWSESS_EXT)] + CDSESS_EXT
            if os.path.isfile(sscud):
                sscud = app.dlg_file(is_open=False,
                                     filters=DLG_CUD_FILTER,
                                     init_filename=os.path.basename(sscud),
                                     init_dir=os.path.dirname(sscud))
                if not sscud: return
            if not import_syn_sess(sssyn, sscud): return
            ssnew = sscud

        pass
        #LOG and log('ssnew={}',(ssnew))
        ssnew = apx.icase(False, '', ssnew.endswith(CDSESS_EXT), ssnew,
                          os.path.isfile(ssnew), ssnew, True,
                          ssnew + CDSESS_EXT)
        pass
        #LOG and log('ssnew={}',(ssnew))
        if os.path.isfile(ssnew):
            # Open
            #           app.app_proc(app.PROC_SAVE_SESSION, sscur)
            ssnew_load = app.app_proc(app.PROC_LOAD_SESSION, ssnew)
            pass
            #LOG and log('ssnew_load={}',(ssnew_load))
            if ssnew_load == False:
                return
            app.app_proc(app.PROC_SET_SESSION, ssnew)
            app.msg_status(OPENED.format(stem=juststem(ssnew)))
            self.top_sess(ssnew)
        else:
            # New
            if app.ID_NO == app.msg_box(
                    CREATE_ASK.format(stem=juststem(ssnew)), app.MB_YESNO):
                return
            #           app.app_proc(app.PROC_SAVE_SESSION, sscur)
            app.ed.cmd(cmds.cmd_FileCloseAll)
            app.app_proc(app.PROC_SET_SESSION, ssnew)
            app.app_proc(app.PROC_SAVE_SESSION, ssnew)
            app.msg_status(CREATED.format(stem=juststem(ssnew)))
            self.top_sess(ssnew)
 def saveAs(self):
     ''' Save cur session to new file '''
     if not _checkAPI(): return
     sscur = app.app_path(app.APP_FILE_SESSION)
     sscur_save = app.app_proc(app.PROC_SAVE_SESSION, sscur)
     if sscur_save == False:
         return
     pass
     app.msg_status(sscur)
     (ssdir, ssfname) = os.path.split(sscur)
     ssfname = ssfname.replace('.json', '')
     ssnew = app.dlg_file(is_open=False,
                          filters=DLG_CUD_FILTER,
                          init_filename=ssfname,
                          init_dir=ssdir)
     pass
     app.msg_status(str(ssnew))
     if ssnew is None: return
     ssnew = apx.icase(False, '', ssnew.endswith(CDSESS_EXT), ssnew,
                       os.path.isfile(ssnew), ssnew, True,
                       ssnew + CDSESS_EXT)
     if os.path.normpath(sscur) == os.path.normpath(ssnew): return
     #       app.app_proc(app.PROC_SAVE_SESSION, sscur)
     app.app_proc(app.PROC_SAVE_SESSION, ssnew)
     app.app_proc(app.PROC_SET_SESSION, ssnew)
     app.msg_status(SAVED.format(stem=juststem(ssnew)))
     self.top_sess(ssnew)
 def saveAs(self):
     ''' Save cur session to new file '''
     if not _checkAPI(): return
     sscur       = app.app_path(app.APP_FILE_SESSION)
     pass;                   app.msg_status(sscur)
     (ssdir
     ,ssfname)   = os.path.split(sscur)
     ssfname     = ssfname.replace('.json', '')
     ssnew       = app.dlg_file(is_open=False, filters=DLG_CUD_FILTER
                 , init_filename=ssfname
                 , init_dir=     ssdir
                 )
     pass;                   app.msg_status(str(ssnew))
     if ssnew is None:   return
     ssnew       = apx.icase(False,''
                 ,   ssnew.endswith(CDSESS_EXT)  , ssnew
                 ,   os.path.isfile(ssnew)       , ssnew
                 ,   True                        , ssnew+CDSESS_EXT
                 )
     if os.path.normpath(sscur)==os.path.normpath(ssnew): return
     app.app_proc(app.PROC_SAVE_SESSION, sscur)
     app.app_proc(app.PROC_SAVE_SESSION, ssnew)
     app.app_proc(app.PROC_SET_SESSION,  ssnew)
     app.msg_status(SAVED.format(stem=juststem(ssnew)))
     self.top_sess(ssnew)
    def open(self, ssnew=None):
        ''' Open new session from file ssnew or after user asking '''
        if not _checkAPI(): return
#       in_dir      = app.app_path(app.APP_DIR_DATA)
        sscur       = app.app_path(app.APP_FILE_SESSION)
        if ssnew is None:
            ssnew   = app.dlg_file(is_open=True, filters=DLG_ALL_FILTER
                    , init_filename='!'     # '!' to disable check "filename exists"
                    , init_dir=     ''
                    )
        if ssnew is None: return
        if ssnew.endswith(SWSESS_EXT) and os.path.isfile(ssnew):
            # Import from Syn
            sssyn   = ssnew
            sscud   = ssnew[:-len(SWSESS_EXT)]+CDSESS_EXT
            if os.path.isfile(sscud):
                sscud   = app.dlg_file(is_open=False, filters=DLG_CUD_FILTER
                        , init_filename=os.path.basename(sscud)
                        , init_dir=     os.path.dirname( sscud)
                        )
                if not sscud: return
            if not import_syn_sess(sssyn, sscud): return
            ssnew   = sscud
            
        ssnew       = apx.icase(False,''
                    ,   ssnew.endswith(CDSESS_EXT)  , ssnew
                    ,   os.path.isfile(ssnew)       , ssnew
                    ,   True                        , ssnew+CDSESS_EXT
                    )
        if os.path.isfile(ssnew):
            # Open
            app.app_proc(app.PROC_SAVE_SESSION, sscur)
            app.app_proc(app.PROC_LOAD_SESSION, ssnew)
            app.app_proc(app.PROC_SET_SESSION,  ssnew)
            app.msg_status(OPENED.format(stem=juststem(ssnew)))
            self.top_sess(ssnew)
        else:
            # New
            if app.ID_NO==app.msg_box(CREATE_ASK.format(stem=juststem(ssnew)), app.MB_YESNO):   return
            app.app_proc(app.PROC_SAVE_SESSION, sscur)
            app.ed.cmd(cmds.cmd_FileCloseAll)
            app.app_proc(app.PROC_SET_SESSION,  ssnew)
            app.app_proc(app.PROC_SAVE_SESSION, ssnew)
            app.msg_status(CREATED.format(stem=juststem(ssnew)))
            self.top_sess(ssnew)
    def get_cnts(self, what=''):
        m,M         = self,CfgKeysDlg
        open_src    = apx.get_opt('config_keys_with_open', False)
        sndt_b      = bool(sndt)
        def is_cond4snps(cond, sns_l):
            if not cond:    return  True
            if not sns_l:   return  False
            return any(map(lambda sn:fnmatch(sn, cond), sns_l))
        def test_cond(cnd_s, text, text2='', what='cmds'):
            if not cnd_s:       return True
            if not text+text2:  return False
            text    = text + ' ' + text2
            text    = text.upper()
            if '_' in cnd_s:
                text    = '·' + M.reND.sub('·', text)    + '·'
                cnd_s   = ' ' + cnd_s + ' '
                cnd_s   = cnd_s.replace(' _', ' ·').replace('_ ', '· ')
            pass;                  #LOG and log('cnd_s, text={}',(cnd_s, text))
            return all(map(lambda c:c in text, cnd_s.split()))
        def bmix(val1, bor12, val2, bor23, val3):
            val12   = val1  or val2     if bor12 else        val1  and val2
            return    val12 or val3     if bor23 else        val12 and val3
#       def bmix(bor12, bor23, val1, val2, val3):
#           val12   = val1  or val2     if bor12 else        val1  and val2
#           return    val12 or val3     if bor23 else        val12 and val3

        ccnd_u  = m.ccnd.upper()
        kcnd_u  = m.kcnd.upper()
        pass;                  #LOG and log('ccnd_u, kcnd_u, scnd={}',(ccnd_u, kcnd_u, m.scnd))
        nkkis_l = [    (nm, k1, k2, id, sndt.get_snips(id) if sndt else [])
                   for (nm, k1, k2, id)   in m.nkki_l]
        pass;                  #LOG and log('nkkis_l={}',(pf(nkkis_l)))
        fl_NKKISs=[    (nm, k1, k2, id, sns)
                   for (nm, k1, k2, id, sns)   in nkkis_l
                   if  bmix( (not ccnd_u or               test_cond(ccnd_u, nm))
                                ,m.orcn and (ccnd_u and kcnd_u)
                            ,(not kcnd_u or               test_cond(kcnd_u, k1, k2, 'keys'))
                                ,m.orsn and (m.scnd)
                            ,(not m.scnd or not sndt   or is_cond4snps(m.scnd, sns)) 
                            )
                  ]
#                  if  bmix(m.orcn, m.orsn
#                                 ,(not ccnd_u or               test_cond(ccnd_u, nm))
#                                 ,(not kcnd_u or               test_cond(kcnd_u, k1, k2, 'keys'))
#                                 ,(not m.scnd or not sndt   or is_cond4snps(m.scnd, sns)) )]
        sort_n  = apx.icase(m.sort[0]=='nm',0, m.sort[0]=='k1',1, m.sort[0]=='k2',2, m.sort[0]=='sn',4, 0)   # index in item of fl_NKKISs
        sort_c  = '' if not m.sort[0] else ' ▲' if m.sort[1] else ' ▼'
        if m.sort[0]: 
            fl_NKKISs   = sorted(fl_NKKISs, key=lambda mkkis:('_' if not mkkis[sort_n] and not m.sort[1] else mkkis[sort_n]), reverse=m.sort[1])
#           fl_NKKISs   = sorted(fl_NKKISs, key=lambda mkkis:mkkis[sort_n], reverse=m.sort[1])
        stat_c  = f(' ({}/{})',len(fl_NKKISs), len(nkkis_l))                                + (sort_c if m.sort[0]=='nm' else '')
        stat_k1 = f(' ({}/{})',sum(1 if k1  else 0 for (nm, k1, k2, id, sns) in fl_NKKISs)  
                              ,sum(1 if k1  else 0 for (nm, k1, k2, id, sns) in nkkis_l))   + (sort_c if m.sort[0]=='k1' else '')
        stat_k2 = f(' ({}/{})',sum(1 if k2  else 0 for (nm, k1, k2, id, sns) in fl_NKKISs)
                              ,sum(1 if k2  else 0 for (nm, k1, k2, id, sns) in nkkis_l))   + (sort_c if m.sort[0]=='k2' else '')
        stat_s  = f(' ({}/{})',sum(1 if sns else 0 for (nm, k1, k2, id, sns) in fl_NKKISs)
                              ,sum(1 if sns else 0 for (nm, k1, k2, id, sns) in nkkis_l))   + (sort_c if m.sort[0]=='sn' else '')
        m.fl_Is = [id         for (nm, k1, k2, id, sn) in fl_NKKISs ]   ##!!
        itms    = (list(zip([_('Command')+stat_c, _('Hotkey-1')+stat_k1, _('Hotkey-2')+stat_k2, _('Snips')+stat_s], map(str, M.COL_WS)))
                  ,         [ (nm,                 k1,             k2,          ', '.join(sns)) 
                                for  (nm, k1, k2, id, sns) in fl_NKKISs ]
                  )
        if what=='lwks':
            return [('lwks',dict(items=itms))]

        cnts    =[
  ('fltr',dict(tp='bt'  ,t=5+40+10      ,l=M.lrpt   ,w=100  ,cap=_('&Filter')           ,props='1'                  ,call=m.do_fltr )) # &f  default
 ,('drop',dict(tp='bt'  ,t=5+70+10      ,l=M.lrpt   ,w=100  ,cap=_('&All')                                          ,call=m.do_fltr )) # &a
 ,('orcn',dict(tp='ch'  ,t=5            ,l=M.lfk1-50,w=40   ,cap=_('&OR')                                           ,call=m.do_fltr )) # &o
 ,('orsn',dict(tp='ch'  ,t=5            ,l=M.lfsn-50,w=40   ,cap=_('O&R')                               ,vis=sndt_b ,call=m.do_fltr )) # &r
 ,('ccn_',dict(tp='lb'  ,tid='orcn'     ,l=5+5      ,w=90   ,cap=_('In &Command:')      ,hint=M.ccnd_h                              )) # &c
 ,('ccnd',dict(tp='ed'  ,t=5+20         ,l=5+5      ,w=150                                                                          )) #
 ,('kcn_',dict(tp='lb'  ,tid='orcn'     ,l=M.lfk1   ,w=50   ,cap=_('In &Hotkeys:')      ,hint=M.kcnd_h                              )) # &h
 ,('kcnd',dict(tp='ed'  ,t=5+20         ,l=M.lfk1   ,w=120                                                                          )) #
                                                                                                                            
 ,('scn_',dict(tp='lb'  ,tid='orsn'     ,l=M.lfsn   ,w=50   ,cap=_('In &Snips:')        ,hint=M.scnd_h  ,vis=sndt_b                 )) # &s
 ,('shlp',dict(tp='bt'  ,tid='orsn'     ,l=M.lfsn+80,w=20   ,cap=_('&?')                                ,vis=sndt_b ,call=m.do_shlp )) # &?
 ,('scnd',dict(tp='ed'  ,t=5+20         ,l=M.lfsn   ,w=100                                              ,vis=sndt_b                 )) #
                                                                                                                                    
#,('srt0',dict(tp='bt'  ,t  =0          ,l=1000     ,w=0    ,cap=_('&1')    ,sto=F                                  ,call=m.do_sort ))# &1
#,('srt1',dict(tp='bt'  ,t  =0          ,l=1000     ,w=0    ,cap=_('&2')    ,sto=F                                  ,call=m.do_sort ))# &2
#,('srt2',dict(tp='bt'  ,t  =0          ,l=1000     ,w=0    ,cap=_('&3')    ,sto=F                                  ,call=m.do_sort ))# &3
#,('srt3',dict(tp='bt'  ,t  =0          ,l=1000     ,w=0    ,cap=_('&4')    ,sto=F                      ,vis=sndt_b ,call=m.do_sort ))# &4
 ,('lwks',dict(tp='lvw' ,t=5+50         ,l=5        ,w=M.LST_W,h=M.LST_H    ,items=itms ,props='1'      ,a='tB'                     
                                                                ,on_click_header=lambda idd, idc, data:m.wn_sort(data)              )) #     grid
                                                                                                                                    
 ,('cpnm',dict(tp='bt'  ,t=M.DLG_H-60   ,l=5+5      ,w=110  ,cap=_('Copy &name')        ,hint=M.cpnm_h  ,a='TB'     ,call=m.do_code )) # &n
 ,('open',dict(tp='bt'  ,t=M.DLG_H-30   ,l=5+5      ,w=110  ,cap=_('Open code &#')      ,hint=M.open_h  ,a='TB'     ,call=m.do_code )) # &#
 ,('hrpt',dict(tp='bt'  ,t=M.DLG_H-60   ,l=130      ,w=150  ,cap=_('Report to HT&ML')   ,hint=M.hrpt_h  ,a='TB'     ,call=m.do_rprt )) # &m
 ,('trpt',dict(tp='bt'  ,t=M.DLG_H-30   ,l=130      ,w=150  ,cap=_('Report to new &Tab'),hint=M.trpt_h  ,a='TB'     ,call=m.do_rprt )) # &t
 ,('add1',dict(tp='bt'  ,t=M.DLG_H-60   ,l=M.lfk1   ,w=150  ,cap=_('Set/Add Hotkey-&1') ,hint=M.addk_h  ,a='TB'     ,call=m.do_work )) # &1
 ,('del1',dict(tp='bt'  ,t=M.DLG_H-30   ,l=M.lfk1   ,w=150  ,cap=_('Remove Hotkey-1 &!')                ,a='TB'     ,call=m.do_work )) # &!
 ,('add2',dict(tp='bt'  ,t=M.DLG_H-60   ,l=M.lfk2   ,w=150  ,cap=_('Set/Add Hotkey-&2') ,hint=M.addk_h  ,a='TB'     ,call=m.do_work )) # &2
 ,('del2',dict(tp='bt'  ,t=M.DLG_H-30   ,l=M.lfk2   ,w=150  ,cap=_('Remove Hotkey-2 &@')                ,a='TB'     ,call=m.do_work )) # &@
 ,('asnp',dict(tp='bt'  ,t=M.DLG_H-60   ,l=M.lfsn   ,w=150  ,cap=_('Set/A&dd Snip')     ,vis=sndt_b     ,a='TB'     ,call=m.do_work )) # &d
 ,('rsnp',dict(tp='bt'  ,t=M.DLG_H-30   ,l=M.lfsn   ,w=150  ,cap=_('R&emove Snip(s)')   ,vis=sndt_b     ,a='TB'     ,call=m.do_work )) # &e
 ,('help',dict(tp='bt'  ,t=M.DLG_H-60   ,l=M.lrpt   ,w=100  ,cap=_('Hel&p')                             ,a='TB'     ,call=m.do_shlp )) # &p 
                ]
        return cnts
Esempio n. 7
0
    def get_cnts(self, what=''):
        m,M         = self,self.__class__
        open_src    = apx.get_opt('config_keys_with_open', False)
        sndt_b      = bool(sndt)
        def is_cond4snps(cond, sns_l):
            if not cond:    return  True
            if not sns_l:   return  False
            return any(map(lambda sn:fnmatch(sn, cond), sns_l))
        def test_cond(cnd_s, text, text2='', what='cmds'):
            if not cnd_s:       return True
            if not text+text2:  return False
            text    = text + ' ' + text2
            text    = text.upper()
            if '_' in cnd_s:
                text    = '·' + M.reND.sub('·', text)    + '·'
                cnd_s   = ' ' + cnd_s + ' '
                cnd_s   = cnd_s.replace(' _', ' ·').replace('_ ', '· ')
            pass;                  #LOG and log('cnd_s, text={}',(cnd_s, text))
            return all(map(lambda c:c in text, cnd_s.split()))
        def bmix(val1, bor12, val2, bor23, val3):
            val12   = val1  or val2     if bor12 else        val1  and val2
            return    val12 or val3     if bor23 else        val12 and val3
#       def bmix(bor12, bor23, val1, val2, val3):
#           val12   = val1  or val2     if bor12 else        val1  and val2
#           return    val12 or val3     if bor23 else        val12 and val3

        ccnd_u  = m.ccnd.upper()
        kcnd_u  = m.kcnd.upper()
        pass;                  #LOG and log('ccnd_u, kcnd_u, scnd={}',(ccnd_u, kcnd_u, m.scnd))
        nkkis_l = [    (nm, k1, k2, id, sndt.get_snips(id) if sndt else [])
                   for (nm, k1, k2, id)   in m.nkki_l]
        pass;                  #LOG and log('nkkis_l={}',(pf(nkkis_l)))
        fl_NKKISs=[    (nm, k1, k2, id, sns)
                   for (nm, k1, k2, id, sns)   in nkkis_l
                   if  bmix( (not ccnd_u or               test_cond(ccnd_u, nm))
                                ,m.orcn and (ccnd_u and kcnd_u)
                            ,(not kcnd_u or               test_cond(kcnd_u, k1, k2, 'keys'))
                                ,m.orsn and (m.scnd)
                            ,(not m.scnd or not sndt   or is_cond4snps(m.scnd, sns)) 
                            )
                  ]
#                  if  bmix(m.orcn, m.orsn
#                                 ,(not ccnd_u or               test_cond(ccnd_u, nm))
#                                 ,(not kcnd_u or               test_cond(kcnd_u, k1, k2, 'keys'))
#                                 ,(not m.scnd or not sndt   or is_cond4snps(m.scnd, sns)) )]
        sort_n  = apx.icase(m.sort[0]=='nm',0, m.sort[0]=='k1',1, m.sort[0]=='k2',2, m.sort[0]=='sn',4, 0)   # index in item of fl_NKKISs
        sort_c  = '' if not m.sort[0] else ' ▲' if m.sort[1] else ' ▼'
        if m.sort[0]: 
            fl_NKKISs   = sorted(fl_NKKISs, key=lambda mkkis:('_' if not mkkis[sort_n] and not m.sort[1] else mkkis[sort_n]), reverse=m.sort[1])
#           fl_NKKISs   = sorted(fl_NKKISs, key=lambda mkkis:mkkis[sort_n], reverse=m.sort[1])
        stat_c  = f(' ({}/{})',len(fl_NKKISs), len(nkkis_l))                                + (sort_c if m.sort[0]=='nm' else '')
        stat_k1 = f(' ({}/{})',sum(1 if k1  else 0 for (nm, k1, k2, id, sns) in fl_NKKISs)  
                              ,sum(1 if k1  else 0 for (nm, k1, k2, id, sns) in nkkis_l))   + (sort_c if m.sort[0]=='k1' else '')
        stat_k2 = f(' ({}/{})',sum(1 if k2  else 0 for (nm, k1, k2, id, sns) in fl_NKKISs)
                              ,sum(1 if k2  else 0 for (nm, k1, k2, id, sns) in nkkis_l))   + (sort_c if m.sort[0]=='k2' else '')
        stat_s  = f(' ({}/{})',sum(1 if sns else 0 for (nm, k1, k2, id, sns) in fl_NKKISs)
                              ,sum(1 if sns else 0 for (nm, k1, k2, id, sns) in nkkis_l))   + (sort_c if m.sort[0]=='sn' else '')
        m.fl_Is = [id         for (nm, k1, k2, id, sn) in fl_NKKISs ]   ##!!
        itms    = (list(zip([_('Command')+stat_c, _('Hotkey-1')+stat_k1, _('Hotkey-2')+stat_k2, _('Snips')+stat_s], map(str, M.COL_WS)))
                  ,         [ (nm,                 k1,             k2,          ', '.join(sns)) 
                                for  (nm, k1, k2, id, sns) in fl_NKKISs ]
                  )
        if what=='lwks':
            return [('lwks',dict(items=itms))]

        cnts    =[
  ('fltr',dict(tp='bt'  ,t=5+40+10      ,l=M.lrpt   ,w=100  ,cap=_('&Filter')           ,ex0='1'                    ,call=m.do_fltr )) # &f  default
 ,('drop',dict(tp='bt'  ,t=5+70+10      ,l=M.lrpt   ,w=100  ,cap=_('&All')                                          ,call=m.do_fltr )) # &a
 ,('orcn',dict(tp='ch'  ,t=5            ,l=M.lfk1-60,w=40   ,cap=_('&OR')                                           ,call=m.do_fltr )) # &o
 ,('orsn',dict(tp='ch'  ,t=5            ,l=M.lfsn-60,w=40   ,cap=_('O&R')                               ,vis=sndt_b ,call=m.do_fltr )) # &r
 ,('ccn_',dict(tp='lb'  ,tid='orcn'     ,l=5+5      ,w=90   ,cap=_('In &Command:')      ,hint=M.ccnd_h                              )) # &c
 ,('ccnd',dict(tp='ed'  ,t=5+20         ,l=5+5      ,w=150                                                                          )) #
 ,('kcn_',dict(tp='lb'  ,tid='orcn'     ,l=M.lfk1   ,w=50   ,cap=_('In &Hotkeys:')      ,hint=M.kcnd_h                              )) # &h
 ,('kcnd',dict(tp='ed'  ,t=5+20         ,l=M.lfk1   ,w=120                                                                          )) #
                                                                                                                            
 ,('scn_',dict(tp='lb'  ,tid='orsn'     ,l=M.lfsn   ,w=50   ,cap=_('In &Snip(s):')        ,hint=M.scnd_h  ,vis=sndt_b                 )) # &s
 ,('shlp',dict(tp='bt'  ,tid='orsn'     ,l=M.lfsn+80,w=20   ,cap=_('&?')                                ,vis=sndt_b ,call=m.do_shlp )) # &?
 ,('scnd',dict(tp='ed'  ,t=5+20         ,l=M.lfsn   ,w=100                                              ,vis=sndt_b                 )) #
                                                                                                                                    
#,('srt0',dict(tp='bt'  ,t  =0          ,l=1000     ,w=0    ,cap=_('&1')    ,sto=F                                  ,call=m.do_sort ))# &1
#,('srt1',dict(tp='bt'  ,t  =0          ,l=1000     ,w=0    ,cap=_('&2')    ,sto=F                                  ,call=m.do_sort ))# &2
#,('srt2',dict(tp='bt'  ,t  =0          ,l=1000     ,w=0    ,cap=_('&3')    ,sto=F                                  ,call=m.do_sort ))# &3
#,('srt3',dict(tp='bt'  ,t  =0          ,l=1000     ,w=0    ,cap=_('&4')    ,sto=F                      ,vis=sndt_b ,call=m.do_sort ))# &4
 ,('lwks',dict(tp='lvw' ,t=5+50         ,l=5        ,w=M.LST_W,h=M.LST_H    ,items=itms ,ex0='1'        ,a='tB'                     
                                                                ,on_click_header=lambda idd, idc, data:m.wn_sort(data)              )) #     grid
                                                                                                                                    
 ,('cpnm',dict(tp='bt'  ,t=M.DLG_H-60   ,l=5+5      ,w=110  ,cap=_('Copy &name')        ,hint=M.cpnm_h  ,a='TB'     ,call=m.do_code )) # &n
 ,('open',dict(tp='bt'  ,t=M.DLG_H-30   ,l=5+5      ,w=110  ,cap=_('Open code &#')      ,hint=M.open_h  ,a='TB'     ,call=m.do_code )) # &#
 ,('hrpt',dict(tp='bt'  ,t=M.DLG_H-60   ,l=130      ,w=150  ,cap=_('Report to HT&ML')   ,hint=M.hrpt_h  ,a='TB'     ,call=m.do_rprt )) # &m
 ,('trpt',dict(tp='bt'  ,t=M.DLG_H-30   ,l=130      ,w=150  ,cap=_('Report to new &Tab'),hint=M.trpt_h  ,a='TB'     ,call=m.do_rprt )) # &t
 ,('add1',dict(tp='bt'  ,t=M.DLG_H-60   ,l=M.lfk1   ,w=150  ,cap=_('Set/Add Hotkey-&1') ,hint=M.addk_h  ,a='TB'     ,call=m.do_work )) # &1
 ,('del1',dict(tp='bt'  ,t=M.DLG_H-30   ,l=M.lfk1   ,w=150  ,cap=_('Remove Hotkey-1 &!')                ,a='TB'     ,call=m.do_work )) # &!
 ,('add2',dict(tp='bt'  ,t=M.DLG_H-60   ,l=M.lfk2   ,w=150  ,cap=_('Set/Add Hotkey-&2') ,hint=M.addk_h  ,a='TB'     ,call=m.do_work )) # &2
 ,('del2',dict(tp='bt'  ,t=M.DLG_H-30   ,l=M.lfk2   ,w=150  ,cap=_('Remove Hotkey-2 &@')                ,a='TB'     ,call=m.do_work )) # &@
 ,('asnp',dict(tp='bt'  ,t=M.DLG_H-60   ,l=M.lfsn   ,w=150  ,cap=_('Set/A&dd Snip')     ,vis=sndt_b     ,a='TB'     ,call=m.do_work )) # &d
 ,('rsnp',dict(tp='bt'  ,t=M.DLG_H-30   ,l=M.lfsn   ,w=150  ,cap=_('R&emove Snip(s)')   ,vis=sndt_b     ,a='TB'     ,call=m.do_work )) # &e
 ,('help',dict(tp='bt'  ,t=M.DLG_H-60   ,l=M.lrpt   ,w=100  ,cap=_('Hel&p')                             ,a='TB'     ,call=m.do_shlp )) # &p 
                ]
        return cnts
Esempio n. 8
0
 def find_cb_string(self, updn, bgn_crt_fin='crt'):
     ''' Find clipboard value in text.
         Params
             updn            'up'|'dn' - direction
             bgn_crt_fin     'bgn'|'crt'|'fin' - start point
     '''
     clip    = app.app_proc(app.PROC_GET_CLIP, '')
     if ''==clip:    return
     clip    = clip.replace('\r\n', '\n').replace('\r', '\n')
     pass;                  #LOG and log('clip={}',repr(clip))
     crts    = ed.get_carets()
     if len(crts)>1:
         return app.msg_status(ONLY_SINGLE_CRT.format('Command'))
     # Prepare bgn-, crt-, fin-point
     (cBgn, rBgn)    = (0, 0)
     (cCrt, rCrt
     ,cEnd, rEnd)    = crts[0]
     lst_line_ind    = ed.get_line_count()-1
     lst_line        = ed.get_text_line(lst_line_ind)
     (cFin, rFin)    = (max(0, len(lst_line)-1), lst_line_ind)
     if bgn_crt_fin=='crt':
         # Some cases for natural (not wrap) find
         if updn=='dn' and (cFin, rFin) == (cCrt, rCrt):
             # Caret at finish - immediately find from start
             return self.find_cb_string(updn, bgn_crt_fin='bgn')
         if updn=='up' and (cBgn, rBgn) == (cCrt, rCrt):
             # Caret at start - immediately find from finish
             return self.find_cb_string(updn, bgn_crt_fin='fin')
         if updn=='dn' and (cBgn, rBgn) == (cCrt, rCrt):
             # Caret already at start - switch wrap off
             bgn_crt_fin = 'bgn'
         if updn=='up' and (cFin, rFin) == (cCrt, rCrt):
             # Caret already at finish - switch wrap off
             bgn_crt_fin = 'fin'
     (cPnt, rPnt
     ,cEnd, rEnd)    = apx.icase(False,0
                         ,bgn_crt_fin=='bgn', (cBgn, rBgn, cBgn, rBgn)
                         ,bgn_crt_fin=='crt', (cCrt, rCrt, cEnd, rEnd)
                         ,bgn_crt_fin=='fin', (cFin, rFin, cFin, rFin)
                         )
     # Main part
     if '\n' not in clip:
         # 1) Find inside each line
         row     = rPnt
         line    = ed.get_text_line(row)
         pos     = line.find(clip, cPnt) if updn=='dn' else line.rfind(clip, 0, cPnt)
         while -1==pos:
             row     = apx.icase(updn=='dn', row+1,   updn=='up', row-1,   -1)
             if row<0 or row==ed.get_line_count():
                 break #while
             line    = ed.get_text_line(row)
             pos     = line.find(clip) if updn=='dn' else line.rfind(clip)
         if False:pass
         elif -1==pos  and bgn_crt_fin!='crt':
             return app.msg_status(FIND_FAIL_FOR_STR.format(clip))
         elif -1==pos:#and bgn_crt_fin=='crt'
             # Wrap!
             return self.find_cb_string(updn, bgn_crt_fin=apx.icase(updn=='dn', 'bgn', 'fin'))
         elif updn=='dn':
             ed.set_caret(pos+len(clip), row, pos, row)
         elif updn=='up':
             ed.set_caret(pos, row, pos+len(clip), row)
         return
     # 2) Find m-line
     pass;                  #LOG and log('')
     clpls   = clip.split('\n')
     pass;                  #LOG and log('clpls={}',(clpls))
     clip    = repr(clip)
     if False:pass
     elif updn=='dn':
         found   = False
         row     = max(rPnt, rEnd if rEnd!=-1 else rPnt)
         if row+len(clpls) < ed.get_line_count():
             txtls   = [ed.get_text_line(r) for r in range(row, row+len(clpls))]
             pass;          #LOG and log('txtls={}',(txtls))
             while True:
                 if self._find_cb_string_included_mlines(txtls, clpls):
                     # Found!
                     found   = True
                     break #while
                 row     = row+1
                 pass;          #LOG and log('row={}',(row))
                 if row+len(clpls) >= ed.get_line_count():
                     pass;  #LOG and log('nfnd12',)
                     break #while
                 txtls   = txtls[1:]+[ed.get_text_line(row+len(clpls)-1)]
                 pass;      #LOG and log('txtls={}',(txtls))
                #while
         if False:pass
         elif not found  and bgn_crt_fin!='crt':
             return app.msg_status(FIND_FAIL_FOR_STR.format(clip))
         elif not found:#and bgn_crt_fin=='crt'
             # Wrap!
             return self.find_cb_string(updn, bgn_crt_fin=apx.icase(updn=='dn', 'bgn', 'fin'))
         ed.set_caret(len(clpls[-1]), row+len(clpls)-1, len(txtls[0])-len(clpls[0]), row)
     elif updn=='up':
         found   = False
         row     = min(rPnt, rEnd if rEnd!=-1 else rPnt)
         if row-len(clpls)+1 >= 0:
             txtls   = [ed.get_text_line(r) for r in range(row-len(clpls)+1, row+1)]
             pass;          #LOG and log('txtls={}',(txtls))
             while True:
                 if self._find_cb_string_included_mlines(txtls, clpls):
                     # Found!
                     found   = True
                     break #while
                 row     = row-1
                 pass;          #LOG and log('row={}',(row))
                 if row-len(clpls)+1 < 0:
                     break #while
                 txtls   = [ed.get_text_line(row-len(clpls)+1)]+txtls[:-1]
                 pass;          #LOG and log('txtls={}',(txtls))
                #while
         if False:pass
         elif not found  and bgn_crt_fin!='crt':
             return app.msg_status(FIND_FAIL_FOR_STR.format(clip))
         elif not found:#and bgn_crt_fin=='crt'
             # Wrap!
             return self.find_cb_string(updn, bgn_crt_fin=apx.icase(updn=='dn', 'bgn', 'fin'))
         ed.set_caret(len(clpls[-1]), row, len(txtls[0])-len(clpls[0]), row-len(clpls)+1)
Esempio n. 9
0
 def dlg_export(self):
     ''' Show dlg for export some macros.
     '''
     if app.app_api_version()<FROM_API_VERSION:  return app.msg_status('Need update CudaText')
     if 0==len(self.macros):                     return app.msg_status('No macros for export')
     exp_file= app.dlg_file(False, '', '', 'Cuda macros|*.cuda-macros')
     exp_file= '' if exp_file is None else exp_file
     exp_file= exp_file+('' if ''==exp_file or exp_file.endswith('.cuda-macros') else '.cuda-macros')
     (WD_LST
     ,HT_LST)= (500
               ,500)
     
     lmcrs   = len(self.macros)
     crt,sels= '0', ['0'] * lmcrs
     while True:
         pass;               LOG and log('sels={}',sels)
         ans = app.dlg_custom('Export macros'   ,GAP+WD_LST+GAP, GAP*5+HT_LST+25*2, '\n'.join([]
         +[C1.join(['type=label'         ,POS_FMT(l=GAP,             t=GAP+3,            r=GAP+70,     b=0)
                   ,'cap=Export &to'
                   ] # i=0
          )]
         +[C1.join(['type=edit'         ,POS_FMT(l=GAP+70,           t=GAP,              r=GAP+WD_LST-35,b=0)
                   ,'val={}'.format(exp_file)
                   ] # i=1
          )]
         +[C1.join(['type=button'        ,POS_FMT(l=GAP+HT_LST-35,   t=GAP-2,            r=GAP+WD_LST,   b=0)
                   ,'cap=&...'
                   ] # i=2
          )]
         +[C1.join(['type=checklistbox' ,POS_FMT(l=GAP,             t=GAP*2+30,          r=GAP+WD_LST,   b=GAP+25+HT_LST)
                   ,'items=' +'\t'.join([mcr['nm'] for mcr in self.macros])
                   ,'val='   + crt+';'+','.join(sels)
                   ] # i=3
          )]
         +[C1.join(['type=button'        ,POS_FMT(l=GAP*1,           t=GAP*3+25+HT_LST,  r=GAP*1+80*1,   b=0)
                   ,'cap=Check &all'
                   ] # i=4
          )]
         +[C1.join(['type=button'        ,POS_FMT(l=GAP*2+80,        t=GAP*3+25+HT_LST,  r=GAP*2+80*2,   b=0)
                   ,'cap=U&ncheck all'
                   ] # i=5
          )]
         +[C1.join(['type=button'        ,POS_FMT(l=    WD_LST-60*2, t=GAP*3+25+HT_LST,  r=    WD_LST-60*1,   b=0)
                   ,'cap=&Export'
                   ] # i=6
          )]
         +[C1.join(['type=button'        ,POS_FMT(l=GAP+WD_LST-60*1, t=GAP*3+25+HT_LST,  r=GAP+WD_LST-60*0,   b=0)
                   ,'cap=&Close'
                   ] # i=7
          )]
         ), 3)    # start focus
         pass;               LOG and log('ans={}',ans)
         if ans is None:  break #while
         (ans_i
         ,vals)  = ans
         ans_s   = apx.icase(False,''
                    ,ans_i==2, 'file'
                    ,ans_i==4, 'all'
                    ,ans_i==5, 'no'
                    ,ans_i==6, 'exp'
                    ,ans_i==7, 'close'
                    )
         if ans_s=='close':  break #while
         v_3     = vals.splitlines()[3]
         crt,sels= v_3.split(';')
         sels    = sels.strip(',').split(',')
         pass;               LOG and log('sels={}',sels)
         if False:pass
         elif ans_s=='file':
             new_exp_file= app.dlg_file(False, '', '', 'Cuda macros|*.cuda-macros')
             if new_exp_file is not None:
                 exp_file    = new_exp_file
                 exp_file    = exp_file+('' if ''==exp_file or exp_file.endswith('.cuda-macros') else '.cuda-macros')
         elif ans_s=='all':
             sels    = ['1'] * lmcrs
         elif ans_s=='no':
             sels    = ['0'] * lmcrs
         elif ans_s=='exp':
             if '1' not in sels:
                 app.msg_box('Select some names', app.MB_OK)
                 continue
             self.export_to_file(exp_file, [mcr for (ind, mcr) in enumerate(self.macros) if sels[ind]=='1'])
             return
Esempio n. 10
0
    def dlg_config(self):
        ''' Show dlg for change macros list.
        '''
        if app.app_api_version()<FROM_API_VERSION:  return app.msg_status('Need update CudaText')
        keys_json   = app.app_path(app.APP_DIR_SETTINGS)+os.sep+'keys.json'
        keys        = apx._json_loads(open(keys_json).read()) if os.path.exists(keys_json) else {}
        GAP     = 5
        
        ids     = [mcr['id'] for mcr in self.macros]
        mcr_ind = ids.index(self.last_mcr_id) if self.last_mcr_id in ids else -1
        pass;                   LOG and log('self.last_mcr_id, mcr_ind={}',(self.last_mcr_id,mcr_ind))
        times   = 1
        waits   = 5
        chngs   = '0'
        endln   = '0'
        while True:
            (WD_LST
            ,HT_LST)= (self.dlg_prs.get('w_list', 300)
                      ,self.dlg_prs.get('h_list', 500))
            (WD_ACTS
            ,HT_ACTS)=(self.dlg_prs.get('w_acts', 300)
                      ,self.dlg_prs.get('h_acts', 500))
            (WD_BTN
            ,HT_BTN)= (self.dlg_prs.get('w_btn', 150), 24)
            l_btn   = GAP+WD_LST+GAP
            
            vw_acts = (WD_ACTS>0)
            WD_ACTS = max(0, WD_ACTS)
            rec_on  = ed.get_prop(app.PROP_MACRO_REC)
            lmcrs   = len(self.macros)
            pass;               LOG and log('mcr_ind,vw_acts,rec_on={}',(mcr_ind,vw_acts,rec_on))

            nmkys   = []
            for mcr in self.macros:
                mcr_cid = 'cuda_macros,run,{}'.format(mcr['id'])
                mcr_keys= keys.get(mcr_cid, {})
                kys     = '/'.join([' * '.join(mcr_keys.get('s1', []))
                                   ,' * '.join(mcr_keys.get('s2', []))
                                   ]).strip('/')
                nmkys  += [mcr['nm'] + (' ['+kys+']' if kys else '')]

            mcr_acts= ''
            if vw_acts and mcr_ind in range(lmcrs):
                mcr     = self.macros[mcr_ind]
                mcr_acts= '\t'.join(['# '+nmkys[mcr_ind]] + mcr['evl'])

            ans = app.dlg_custom('Macros'   ,GAP+WD_LST+GAP+WD_BTN+GAP+WD_ACTS+GAP,GAP+HT_LST+GAP, '\n'.join([]
            +[C1.join(['type=listbox'   ,POS_FMT(l=GAP,    t=GAP,           r=GAP+WD_LST,   b=GAP+HT_LST)
                      ,'items=' +'\t'.join(nmkys)
                      ,'val='   +str(mcr_ind)  # start sel
                      ,'en='    +str(0 if rec_on else 1)        # enabled
                      ] # i=0
             )]
            +([C1.join(['type=button'    ,POS_FMT(l=l_btn,  t=GAP*1+HT_BTN*0,    r=l_btn+WD_BTN, b=0)
                      ,'cap=&View actions...'
                      ,'props=' +str(0 if    rec_on or 0==lmcrs else 1)    # default
                      ,'en='    +str(0 if    rec_on or 0==lmcrs else 1)    # enabled
                      ] # i=1
             )] if vw_acts else [])
            +[C1.join(['type=button'    ,POS_FMT(l=l_btn,  t=GAP*2+HT_BTN*1,    r=l_btn+WD_BTN, b=0)
                      ,'cap=Hot&keys...'
                      ,'en='    +str(0 if    rec_on or 0==lmcrs else 1)     # enabled
                      ] # i=2 if vw_acts else i=1
             )]
            +[C1.join(['type=button'    ,POS_FMT(l=l_btn,  t=GAP*3+HT_BTN*2,    r=l_btn+WD_BTN, b=0)
                      ,'cap=Re&name...'
                      ,'en='    +str(0 if    rec_on or 0==lmcrs else 1)     # enabled
                      ] # i=3 if vw_acts else i=2
             )]
            +[C1.join(['type=button'    ,POS_FMT(l=l_btn,  t=GAP*4+HT_BTN*3,    r=l_btn+WD_BTN, b=0)
                      ,'cap=&Delete...'
                      ,'en='    +str(0 if    rec_on or 0==lmcrs else 1)     # enabled
                      ] # i=4 if vw_acts else i=3
             )]

            +[C1.join(['type=button'    ,POS_FMT(l=l_btn,                   t=GAP*6+HT_BTN*5,    r=l_btn+WD_BTN, b=0)
                      ,'cap=&Run!'
                      ,'props=' +str(1 if not vw_acts and not rec_on else 0)     # default
                      ,'en='    +str(0 if    rec_on or 0==lmcrs else 1)     # enabled
                      ] # i=5 if vw_acts else i=4
             )]
            +[C1.join(['type=label'     ,POS_FMT(l=l_btn,                   t=GAP*7+HT_BTN*6+3, r=l_btn+int(WD_BTN/3),b=0)
                      ,'cap=&Times'
                      ] # i=6 if vw_acts else i=5
             )]
            +[C1.join(['type=spinedit'  ,POS_FMT(l=l_btn+int(WD_BTN/3)+GAP, t=GAP*7+HT_BTN*6,   r=l_btn+WD_BTN, b=0)
                      ,'val='   +str(times)
                      ,'props=0,{},1'.format(self.dlg_prs.get('times',  1000))
                      ,'en='    +str(0 if    rec_on else 1)     # enabled
                      ] # i=7 if vw_acts else i=6
             )]
            +[C1.join(['type=label'     ,POS_FMT(l=l_btn,                   t=GAP*8+HT_BTN*7+3, r=l_btn+int(WD_BTN/3),b=0)
                      ,'cap=&Wait'
                      ] # i=8 if vw_acts else i=7
             )]
            +[C1.join(['type=spinedit'  ,POS_FMT(l=l_btn+int(WD_BTN/3)+GAP, t=GAP*8+HT_BTN*7,   r=l_btn+WD_BTN-40, b=0)
                      ,'val='   +str(waits)
                      ,'props=1,3600,1'
                      ,'en='    +str(0 if    rec_on else 1)     # enabled
                      ] # i=9 if vw_acts else i=8
             )]
            +[C1.join(['type=label'     ,POS_FMT(l=l_btn+WD_BTN-40+GAP,     t=GAP*8+HT_BTN*7+3, r=l_btn+WD_BTN,b=0)
                      ,'cap=sec'
                      ] # i=10 if vw_acts else i=9
             )]
            +[C1.join(['type=check'     ,POS_FMT(l=l_btn,                   t=GAP*9+HT_BTN*8, r=l_btn+WD_BTN,b=0)
                      ,'cap=While text c&hanges'
                      ,'val='   +chngs
                      ] # i=11 if vw_acts else i=10
             )]
            +[C1.join(['type=check'     ,POS_FMT(l=l_btn,                   t=GAP*10+HT_BTN*9, r=l_btn+WD_BTN,b=0)
                      ,'cap=Until c&aret on last line'
                      ,'val='   +endln
                      ] # i=12 if vw_acts else i=11
             )]

            +[C1.join(['type=button'    ,POS_FMT(l=l_btn,  t=GAP*12+HT_BTN*11,    r=l_btn+WD_BTN, b=0)
                      ,'cap={}'.format('&Stop record' if rec_on else '&Start record')
                      ,'props=' +str(1 if    rec_on or 0==lmcrs else 0)     # default
                      ] # i=13 if vw_acts else i=12
             )]
            +[C1.join(['type=button'    ,POS_FMT(l=l_btn,  t=GAP*13+HT_BTN*12,    r=l_btn+WD_BTN, b=0)
                      ,'cap=Canc&el record'
                      ,'en='    +str(1 if    rec_on else 0)     # enabled
                      ] # i=14 if vw_acts else i=13
             )]

            +[C1.join(['type=button'    ,POS_FMT(l=l_btn,  t=    HT_LST-HT_BTN*2, r=l_btn+WD_BTN, b=0)
                      ,'cap=C&ustom...'
                      ,'en='    +str(0 if    rec_on else 1)     # enabled
                      ] # i=15 if vw_acts else i=14
             )]
            +[C1.join(['type=button'    ,POS_FMT(l=l_btn,  t=GAP+HT_LST-HT_BTN*1, r=l_btn+WD_BTN, b=0)
                      ,'cap=&Close'
                      ] # i=16 if vw_acts else i=15
             )]
            +([C1.join(['type=memo'      ,POS_FMT(l=GAP+WD_LST+GAP+WD_BTN+GAP,   t=GAP,  r=GAP+WD_LST+GAP+WD_BTN+GAP+WD_ACTS, b=GAP+HT_ACTS)
                      ,'val='+mcr_acts
                      ,'props=1,1,1'    # ro,mono,border
                      ] # i=17
             )] if vw_acts else [])
            ), apx.icase(    vw_acts and not rec_on, 0  # View
                        ,not vw_acts and not rec_on, 0  # View
                        ,    vw_acts and     rec_on, 11
                        ,not vw_acts and     rec_on, 10
                        ))    # start focus
            pass;               LOG and log('ans={}',ans)
            if ans is None:  break #while
            (ans_i
            ,vals)  = ans
            ans_s   = apx.icase(False,''
                       ,vw_acts and ans_i==1, 'view'
                       ,vw_acts and ans_i==2, 'hotkeys' ,not vw_acts and ans_i==1, 'hotkeys'
                       ,vw_acts and ans_i==3, 'rename'  ,not vw_acts and ans_i==2, 'rename' 
                       ,vw_acts and ans_i==4, 'delete'  ,not vw_acts and ans_i==3, 'delete' 
                       ,vw_acts and ans_i==5, 'run'     ,not vw_acts and ans_i==4, 'run'    
                       ,vw_acts and ans_i==12,'rec'     ,not vw_acts and ans_i==7, 'rec'    
                       ,vw_acts and ans_i==14,'cancel'  ,not vw_acts and ans_i==13,'cancel' 
                       ,vw_acts and ans_i==15,'custom'  ,not vw_acts and ans_i==14,'custom' 
                       ,vw_acts and ans_i==16,'close'   ,not vw_acts and ans_i==15,'close'  
                       ,'?')
            mcr_ind = int(vals.splitlines()[0])
            times   = int(vals.splitlines()[ 7 if vw_acts else  6])
            waits   = int(vals.splitlines()[ 9 if vw_acts else  8])
            chngs   =     vals.splitlines()[11 if vw_acts else 10]
            endln   =     vals.splitlines()[12 if vw_acts else 11]
            pass;               LOG and log('mcr_ind,times,waits,chngs,endln={}',(mcr_ind,times,waits,chngs,endln))

            if 0!=lmcrs and mcr_ind in range(lmcrs):
                mcr     = self.macros[mcr_ind]
                self.last_mcr_id = mcr['id']
            
            if ans_s=='close':  break #while
            if ans_s=='custom': #Custom
                custs   = app.dlg_input_ex(5, 'Custom dialog Macros'
                    , 'Height of macro list (min 450)'          , str(self.dlg_prs.get('h_list', 400))
                    , 'Width of macro list (min 200)'           , str(self.dlg_prs.get('w_list', 500))
                    , 'Width of action list (min 200, <=0-hide)', str(self.dlg_prs.get('w_acts', 500))
                    , 'Width of buttons (min 150)'              , str(self.dlg_prs.get('w_btn',  150))
                    , 'Max run times (min 100)'                 , str(self.dlg_prs.get('times',  1000))
                    )
                if custs is not None:
                    self.dlg_prs['h_list']  = max(450, int(custs[0]));  self.dlg_prs['h_acts'] = self.dlg_prs['h_list']
                    self.dlg_prs['w_list']  = max(200, int(custs[1]))
                    self.dlg_prs['w_acts']  = max(200, int(custs[2])) if int(custs[2])>0 else int(custs[2])
                    self.dlg_prs['w_btn']   = max(150, int(custs[3]))
                    self.dlg_prs['times']   = max(100, int(custs[4]))
                    open(MACROS_JSON, 'w').write(json.dumps({'ver':JSON_FORMAT_VER, 'list':self.macros, 'dlg_prs':self.dlg_prs}, indent=4))
                continue #while
            
            if mcr_ind not in range(lmcrs):
                app.msg_box('Select macro', app.MB_OK)
                continue #while
            
            what    = ''
            changed = False
            if False:pass
                
            elif ans_s=='view': #View
                continue #while

            elif ans_s=='rename': #Rename
                mcr_nm      = app.dlg_input('New name for: {}'.format(nmkys[mcr_ind])
                                           ,mcr['nm'])
                if mcr_nm is None or mcr_nm==mcr['nm']:     continue #while
                while mcr_nm in [mcr['nm'] for mcr in self.macros]:
                    app.msg_box('Select other name.\nMacro names now are:\n\n'+'\n'.join(nmkys), app.MB_OK)
                    mcr_nm  = app.dlg_input('New name for: {}'.format(nmkys[mcr_ind])
                                           ,mcr_nm)
                    if mcr_nm is None or mcr_nm==mcr['nm']: break #while mcr_nm
                if mcr_nm is None or mcr_nm==mcr['nm']:     continue #while
                what        = 'rename'
                mcr['nm']   = mcr_nm
                changed = True
                
            elif ans_s=='delete': #Del
                if app.msg_box( 'Delete macro\n    {}'.format(nmkys[mcr_ind])
                              , app.MB_YESNO)!=app.ID_YES:  continue #while
                what    = 'delete:'+str(mcr['id'])
                del self.macros[mcr_ind]
                mcr_ind = min(mcr_ind, len(self.macros)-1)
                changed = True
                
            elif ans_s=='hotkeys': #Hotkeys
                app.dlg_hotkeys('cuda_macros,run,'+str(mcr['id']))
                keys    = apx._json_loads(open(keys_json).read()) if os.path.exists(keys_json) else {}
                changed = True

            elif ans_s=='run': #Run
                if (times==0 
                and waits==0
                and chngs=='0'
                and endln=='0'):
                    app.msg_box('Select stop condition', app.MB_OK)
                    continue
                self.run(mcr['id'], max(0, times), max(0, waits), chngs=='1', endln=='1')
                return

            elif ans_s=='rec'    and not rec_on: #Start record
                return ed.cmd(cmds.cmd_MacroStart)
            elif ans_s=='rec'    and     rec_on: #Stop record
                self.need_dlg = True
                return ed.cmd(cmds.cmd_MacroStop)       # Return for clear rec-mode in StatusBar, will recall from on_macro
            elif ans_s=='cancel' and     rec_on: #Cancel record
                return ed.cmd(cmds.cmd_MacroCancel)     # Return for clear rec-mode in StatusBar
                
            if changed:
                self._do_acts(what)
Esempio n. 11
0
 def dlg_import(self):
     ''' Show dlg for import some macros.
     '''
     if app.app_api_version()<FROM_API_VERSION:  return app.msg_status('Need update CudaText')
     (imp_file
     ,mcrs)  = self.dlg_import_choose_mcrs()
     if imp_file is None:    return
     lmcrs   = len(mcrs)
     
     GAP     = 5
     (WD_LST
     ,HT_LST)= (500
               ,500)
     crt,sels= '0', ['1'] * lmcrs
     while True:
         ans = app.dlg_custom('Import macros'   ,GAP+WD_LST+GAP, GAP*5+HT_LST+25*2, '\n'.join([]
         +[C1.join(['type=label'         ,POS_FMT(l=GAP,             t=GAP+3,            r=GAP+85,     b=0)
                   ,'cap=Import &from'
                   ] # i=0
          )]
         +[C1.join(['type=edit'         ,POS_FMT(l=GAP+85,           t=GAP,              r=GAP+WD_LST-35,b=0)
                   ,'val={}'.format(imp_file)
                   ] # i=1
          )]
         +[C1.join(['type=button'        ,POS_FMT(l=GAP+HT_LST-35,   t=GAP-2,            r=GAP+WD_LST,   b=0)
                   ,'cap=&...'
                   ] # i=2
          )]
         +[C1.join(['type=checklistbox' ,POS_FMT(l=GAP,             t=GAP*2+30,          r=GAP+WD_LST,   b=GAP+25+HT_LST)
                   ,'items=' +'\t'.join([mcr['nm'] for mcr in mcrs])
                   ,'val='   + crt+';'+','.join(sels)
                   ] # i=3
          )]
         +[C1.join(['type=button'        ,POS_FMT(l=GAP*1,           t=GAP*3+25+HT_LST,  r=GAP*1+80*1,   b=0)
                   ,'cap=Check &all'
                   ] # i=4
          )]
         +[C1.join(['type=button'        ,POS_FMT(l=GAP*2+80,        t=GAP*3+25+HT_LST,  r=GAP*2+80*2,   b=0)
                   ,'cap=U&ncheck all'
                   ] # i=5
          )]
         +[C1.join(['type=button'        ,POS_FMT(l=    WD_LST-60*2, t=GAP*3+25+HT_LST,  r=    WD_LST-60*1,   b=0)
                   ,'cap=&Import'
                   ] # i=6
          )]
         +[C1.join(['type=button'        ,POS_FMT(l=GAP+WD_LST-60*1, t=GAP*3+25+HT_LST,  r=GAP+WD_LST-60*0,   b=0)
                   ,'cap=&Close'
                   ] # i=7
          )]
         ), 3)    # start focus
         pass;               LOG and log('ans={}',ans)
         if ans is None:  break #while
         (ans_i
         ,vals)  = ans
         ans_s   = apx.icase(False,''
                    ,ans_i==2, 'file'
                    ,ans_i==4, 'all'
                    ,ans_i==5, 'no'
                    ,ans_i==6, 'imp'
                    ,ans_i==7, 'close'
                    )
         if ans_s=='close':  break #while
         v_3     = vals.splitlines()[3]
         crt,sels= v_3.split(';')
         sels    = sels.strip(',').split(',')
         pass;               LOG and log('sels={}',sels)
         if False:pass
         elif ans_s=='file':
             (new_imp_file
             ,new_mcrs)  = self.dlg_import_choose_mcrs()
             if new_imp_file is None:    continue #while
             imp_file    = new_imp_file
             mcrs        = new_mcrs
             lmcrs       = len(mcrs)
             crt,sels    = '0', ['1'] * lmcrs
         elif ans_s=='all':
             sels    = ['1'] * lmcrs
         elif ans_s=='no':
             sels    = ['0'] * lmcrs
         elif ans_s=='imp':
             if '1' not in sels:
                 app.msg_box('Select some names', app.MB_OK)
                 continue
             (good_nms
             ,fail_nms) = self.import_from_list([mcr for (ind, mcr) in enumerate(mcrs) if sels[ind]=='1'])
             l,lt    = '\n', '\n      '
             app.msg_box(   'Import macros:'     +lt+lt.join(good_nms)
                         +l+''
                         +l+'Skip duplicates:'   +lt+lt.join(fail_nms)
                        ,app.MB_OK)
Esempio n. 12
0
    def dlg_config(self):
        ''' Show dlg for change macros list.
        '''
        if app.app_api_version() < FROM_API_VERSION:
            return app.msg_status('Need update CudaText')
        keys_json = app.app_path(app.APP_DIR_SETTINGS) + os.sep + 'keys.json'
        keys = apx._json_loads(
            open(keys_json).read()) if os.path.exists(keys_json) else {}
        GAP = 5

        ids = [mcr['id'] for mcr in self.macros]
        mcr_ind = ids.index(
            self.last_mcr_id) if self.last_mcr_id in ids else -1
        pass
        LOG and log('self.last_mcr_id, mcr_ind={}',
                    (self.last_mcr_id, mcr_ind))
        times = 1
        waits = 5
        chngs = '0'
        endln = '0'
        while True:
            (WD_LST, HT_LST) = (self.dlg_prs.get('w_list', 300),
                                self.dlg_prs.get('h_list', 500))
            (WD_ACTS, HT_ACTS) = (self.dlg_prs.get('w_acts', 300),
                                  self.dlg_prs.get('h_acts', 500))
            (WD_BTN, HT_BTN) = (self.dlg_prs.get('w_btn', 150), 24)
            l_btn = GAP + WD_LST + GAP

            vw_acts = (WD_ACTS > 0)
            WD_ACTS = max(0, WD_ACTS)
            rec_on = ed.get_prop(app.PROP_MACRO_REC)
            lmcrs = len(self.macros)
            pass
            LOG and log('mcr_ind,vw_acts,rec_on={}',
                        (mcr_ind, vw_acts, rec_on))

            nmkys = []
            for mcr in self.macros:
                mcr_cid = 'cuda_macros,run,{}'.format(mcr['id'])
                mcr_keys = keys.get(mcr_cid, {})
                kys = '/'.join([
                    ' * '.join(mcr_keys.get('s1', [])),
                    ' * '.join(mcr_keys.get('s2', []))
                ]).strip('/')
                nmkys += [mcr['nm'] + (' [' + kys + ']' if kys else '')]

            mcr_acts = ''
            if vw_acts and mcr_ind in range(lmcrs):
                mcr = self.macros[mcr_ind]
                mcr_acts = '\t'.join(['# ' + nmkys[mcr_ind]] + mcr['evl'])

            ans = app.dlg_custom(
                'Macros',
                GAP + WD_LST + GAP + WD_BTN + GAP + WD_ACTS + GAP,
                GAP + HT_LST + GAP,
                '\n'.join([] + [
                    C1.join([
                        'type=listbox',
                        POS_FMT(l=GAP, t=GAP, r=GAP + WD_LST, b=GAP + HT_LST),
                        'items=' + '\t'.join(nmkys),
                        'val=' + str(mcr_ind)  # start sel
                        ,
                        'en=' + str(0 if rec_on else 1)  # enabled
                    ]  # i=0
                            )
                ] + ([
                    C1.join([
                        'type=button',
                        POS_FMT(l=l_btn,
                                t=GAP * 1 + HT_BTN * 0,
                                r=l_btn + WD_BTN,
                                b=0),
                        'cap=&View actions...',
                        'props=' +
                        str(0 if rec_on or 0 == lmcrs else 1)  # default
                        ,
                        'en=' +
                        str(0 if rec_on or 0 == lmcrs else 1)  # enabled
                    ]  # i=1
                            )
                ] if vw_acts else []) + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=l_btn,
                                t=GAP * 2 + HT_BTN * 1,
                                r=l_btn + WD_BTN,
                                b=0),
                        'cap=Hot&keys...',
                        'en=' +
                        str(0 if rec_on or 0 == lmcrs else 1)  # enabled
                    ]  # i=2 if vw_acts else i=1
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=l_btn,
                                t=GAP * 3 + HT_BTN * 2,
                                r=l_btn + WD_BTN,
                                b=0),
                        'cap=Re&name...',
                        'en=' +
                        str(0 if rec_on or 0 == lmcrs else 1)  # enabled
                    ]  # i=3 if vw_acts else i=2
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=l_btn,
                                t=GAP * 4 + HT_BTN * 3,
                                r=l_btn + WD_BTN,
                                b=0),
                        'cap=&Delete...',
                        'en=' +
                        str(0 if rec_on or 0 == lmcrs else 1)  # enabled
                    ]  # i=4 if vw_acts else i=3
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=l_btn,
                                t=GAP * 6 + HT_BTN * 5,
                                r=l_btn + WD_BTN,
                                b=0),
                        'cap=&Run!',
                        'props=' +
                        str(1 if not vw_acts and not rec_on else 0)  # default
                        ,
                        'en=' +
                        str(0 if rec_on or 0 == lmcrs else 1)  # enabled
                    ]  # i=5 if vw_acts else i=4
                            )
                ] + [
                    C1.join([
                        'type=label',
                        POS_FMT(l=l_btn,
                                t=GAP * 7 + HT_BTN * 6 + 3,
                                r=l_btn + int(WD_BTN / 3),
                                b=0), 'cap=&Times'
                    ]  # i=6 if vw_acts else i=5
                            )
                ] + [
                    C1.join([
                        'type=spinedit',
                        POS_FMT(l=l_btn + int(WD_BTN / 3) + GAP,
                                t=GAP * 7 + HT_BTN * 6,
                                r=l_btn + WD_BTN,
                                b=0),
                        'val=' + str(times),
                        'props=0,{},1'.format(self.dlg_prs.get('times', 1000)),
                        'en=' + str(0 if rec_on else 1)  # enabled
                    ]  # i=7 if vw_acts else i=6
                            )
                ] + [
                    C1.join([
                        'type=label',
                        POS_FMT(l=l_btn,
                                t=GAP * 8 + HT_BTN * 7 + 3,
                                r=l_btn + int(WD_BTN / 3),
                                b=0), 'cap=&Wait'
                    ]  # i=8 if vw_acts else i=7
                            )
                ] + [
                    C1.join([
                        'type=spinedit',
                        POS_FMT(l=l_btn + int(WD_BTN / 3) + GAP,
                                t=GAP * 8 + HT_BTN * 7,
                                r=l_btn + WD_BTN - 40,
                                b=0),
                        'val=' + str(waits),
                        'props=1,3600,1',
                        'en=' + str(0 if rec_on else 1)  # enabled
                    ]  # i=9 if vw_acts else i=8
                            )
                ] + [
                    C1.join([
                        'type=label',
                        POS_FMT(l=l_btn + WD_BTN - 40 + GAP,
                                t=GAP * 8 + HT_BTN * 7 + 3,
                                r=l_btn + WD_BTN,
                                b=0), 'cap=sec'
                    ]  # i=10 if vw_acts else i=9
                            )
                ] + [
                    C1.join([
                        'type=check',
                        POS_FMT(l=l_btn,
                                t=GAP * 9 + HT_BTN * 8,
                                r=l_btn + WD_BTN,
                                b=0), 'cap=While text c&hanges', 'val=' + chngs
                    ]  # i=11 if vw_acts else i=10
                            )
                ] + [
                    C1.join([
                        'type=check',
                        POS_FMT(l=l_btn,
                                t=GAP * 10 + HT_BTN * 9,
                                r=l_btn + WD_BTN,
                                b=0), 'cap=Until c&aret on last line', 'val=' +
                        endln
                    ]  # i=12 if vw_acts else i=11
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=l_btn,
                                t=GAP * 12 + HT_BTN * 11,
                                r=l_btn + WD_BTN,
                                b=0),
                        'cap={}'.format(
                            '&Stop record' if rec_on else '&Start record'),
                        'props=' +
                        str(1 if rec_on or 0 == lmcrs else 0)  # default
                    ]  # i=13 if vw_acts else i=12
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=l_btn,
                                t=GAP * 13 + HT_BTN * 12,
                                r=l_btn + WD_BTN,
                                b=0),
                        'cap=Canc&el record',
                        'en=' + str(1 if rec_on else 0)  # enabled
                    ]  # i=14 if vw_acts else i=13
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=l_btn,
                                t=HT_LST - HT_BTN * 2,
                                r=l_btn + WD_BTN,
                                b=0),
                        'cap=C&ustom...',
                        'en=' + str(0 if rec_on else 1)  # enabled
                    ]  # i=15 if vw_acts else i=14
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=l_btn,
                                t=GAP + HT_LST - HT_BTN * 1,
                                r=l_btn + WD_BTN,
                                b=0), 'cap=&Close'
                    ]  # i=16 if vw_acts else i=15
                            )
                ] + ([
                    C1.join([
                        'type=memo',
                        POS_FMT(l=GAP + WD_LST + GAP + WD_BTN + GAP,
                                t=GAP,
                                r=GAP + WD_LST + GAP + WD_BTN + GAP + WD_ACTS,
                                b=GAP + HT_ACTS),
                        'val=' + mcr_acts,
                        'props=1,1,1'  # ro,mono,border
                    ]  # i=17
                            )
                ] if vw_acts else [])),
                apx.icase(
                    vw_acts and not rec_on,
                    0  # View
                    ,
                    not vw_acts and not rec_on,
                    0  # View
                    ,
                    vw_acts and rec_on,
                    11,
                    not vw_acts and rec_on,
                    10))  # start focus
            pass
            LOG and log('ans={}', ans)
            if ans is None: break  #while
            (ans_i, vals) = ans
            ans_s = apx.icase(
                False, '', vw_acts and ans_i == 1, 'view', vw_acts
                and ans_i == 2, 'hotkeys', not vw_acts and ans_i == 1,
                'hotkeys', vw_acts and ans_i == 3, 'rename', not vw_acts
                and ans_i == 2, 'rename', vw_acts and ans_i == 4, 'delete',
                not vw_acts and ans_i == 3, 'delete', vw_acts and ans_i == 5,
                'run', not vw_acts and ans_i == 4, 'run', vw_acts
                and ans_i == 12, 'rec', not vw_acts and ans_i == 7, 'rec',
                vw_acts and ans_i == 14, 'cancel', not vw_acts and ans_i == 13,
                'cancel', vw_acts and ans_i == 15, 'custom', not vw_acts
                and ans_i == 14, 'custom', vw_acts and ans_i == 16, 'close',
                not vw_acts and ans_i == 15, 'close', '?')
            mcr_ind = int(vals.splitlines()[0])
            times = int(vals.splitlines()[7 if vw_acts else 6])
            waits = int(vals.splitlines()[9 if vw_acts else 8])
            chngs = vals.splitlines()[11 if vw_acts else 10]
            endln = vals.splitlines()[12 if vw_acts else 11]
            pass
            LOG and log('mcr_ind,times,waits,chngs,endln={}',
                        (mcr_ind, times, waits, chngs, endln))

            if 0 != lmcrs and mcr_ind in range(lmcrs):
                mcr = self.macros[mcr_ind]
                self.last_mcr_id = mcr['id']

            if ans_s == 'close': break  #while
            if ans_s == 'custom':  #Custom
                custs = app.dlg_input_ex(
                    5, 'Custom dialog Macros',
                    'Height of macro list (min 450)',
                    str(self.dlg_prs.get('h_list', 400)),
                    'Width of macro list (min 200)',
                    str(self.dlg_prs.get('w_list', 500)),
                    'Width of action list (min 200, <=0-hide)',
                    str(self.dlg_prs.get('w_acts',
                                         500)), 'Width of buttons (min 150)',
                    str(self.dlg_prs.get('w_btn',
                                         150)), 'Max run times (min 100)',
                    str(self.dlg_prs.get('times', 1000)))
                if custs is not None:
                    self.dlg_prs['h_list'] = max(450, int(custs[0]))
                    self.dlg_prs['h_acts'] = self.dlg_prs['h_list']
                    self.dlg_prs['w_list'] = max(200, int(custs[1]))
                    self.dlg_prs['w_acts'] = max(200, int(
                        custs[2])) if int(custs[2]) > 0 else int(custs[2])
                    self.dlg_prs['w_btn'] = max(150, int(custs[3]))
                    self.dlg_prs['times'] = max(100, int(custs[4]))
                    open(MACROS_JSON, 'w').write(
                        json.dumps(
                            {
                                'ver': JSON_FORMAT_VER,
                                'list': self.macros,
                                'dlg_prs': self.dlg_prs
                            },
                            indent=4))
                continue  #while

            if mcr_ind not in range(lmcrs):
                app.msg_box('Select macro', app.MB_OK)
                continue  #while

            what = ''
            changed = False
            if False: pass

            elif ans_s == 'view':  #View
                continue  #while

            elif ans_s == 'rename':  #Rename
                mcr_nm = app.dlg_input(
                    'New name for: {}'.format(nmkys[mcr_ind]), mcr['nm'])
                if mcr_nm is None or mcr_nm == mcr['nm']: continue  #while
                while mcr_nm in [mcr['nm'] for mcr in self.macros]:
                    app.msg_box(
                        'Select other name.\nMacro names now are:\n\n' +
                        '\n'.join(nmkys), app.MB_OK)
                    mcr_nm = app.dlg_input(
                        'New name for: {}'.format(nmkys[mcr_ind]), mcr_nm)
                    if mcr_nm is None or mcr_nm == mcr['nm']:
                        break  #while mcr_nm
                if mcr_nm is None or mcr_nm == mcr['nm']: continue  #while
                what = 'rename'
                mcr['nm'] = mcr_nm
                changed = True

            elif ans_s == 'delete':  #Del
                if app.msg_box('Delete macro\n    {}'.format(nmkys[mcr_ind]),
                               app.MB_YESNO) != app.ID_YES:
                    continue  #while
                what = 'delete:' + str(mcr['id'])
                del self.macros[mcr_ind]
                mcr_ind = min(mcr_ind, len(self.macros) - 1)
                changed = True

            elif ans_s == 'hotkeys':  #Hotkeys
                app.dlg_hotkeys('cuda_macros,run,' + str(mcr['id']))
                keys = apx._json_loads(open(
                    keys_json).read()) if os.path.exists(keys_json) else {}
                changed = True

            elif ans_s == 'run':  #Run
                if (times == 0 and waits == 0 and chngs == '0'
                        and endln == '0'):
                    app.msg_box('Select stop condition', app.MB_OK)
                    continue
                self.run(mcr['id'], max(0, times), max(0, waits), chngs == '1',
                         endln == '1')
                return

            elif ans_s == 'rec' and not rec_on:  #Start record
                return ed.cmd(cmds.cmd_MacroStart)
            elif ans_s == 'rec' and rec_on:  #Stop record
                self.need_dlg = True
                return ed.cmd(
                    cmds.cmd_MacroStop
                )  # Return for clear rec-mode in StatusBar, will recall from on_macro
            elif ans_s == 'cancel' and rec_on:  #Cancel record
                return ed.cmd(cmds.cmd_MacroCancel
                              )  # Return for clear rec-mode in StatusBar

            if changed:
                self._do_acts(what)
Esempio n. 13
0
    def dlg_import(self):
        ''' Show dlg for import some macros.
        '''
        if app.app_api_version() < FROM_API_VERSION:
            return app.msg_status('Need update CudaText')
        (imp_file, mcrs) = self.dlg_import_choose_mcrs()
        if imp_file is None: return
        lmcrs = len(mcrs)

        GAP = 5
        (WD_LST, HT_LST) = (500, 500)
        crt, sels = '0', ['1'] * lmcrs
        while True:
            ans = app.dlg_custom(
                'Import macros',
                GAP + WD_LST + GAP,
                GAP * 5 + HT_LST + 25 * 2,
                '\n'.join([] + [
                    C1.join([
                        'type=label',
                        POS_FMT(l=GAP, t=GAP + 3, r=GAP +
                                85, b=0), 'cap=Import &from'
                    ]  # i=0
                            )
                ] + [
                    C1.join([
                        'type=edit',
                        POS_FMT(l=GAP + 85, t=GAP, r=GAP + WD_LST -
                                35, b=0), 'val={}'.format(imp_file)
                    ]  # i=1
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=GAP + HT_LST - 35,
                                t=GAP - 2,
                                r=GAP + WD_LST,
                                b=0), 'cap=&...'
                    ]  # i=2
                            )
                ] + [
                    C1.join([
                        'type=checklistbox',
                        POS_FMT(l=GAP,
                                t=GAP * 2 + 30,
                                r=GAP + WD_LST,
                                b=GAP + 25 + HT_LST), 'items=' +
                        '\t'.join([mcr['nm'] for mcr in mcrs]), 'val=' + crt +
                        ';' + ','.join(sels)
                    ]  # i=3
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=GAP * 1,
                                t=GAP * 3 + 25 + HT_LST,
                                r=GAP * 1 + 80 * 1,
                                b=0), 'cap=Check &all'
                    ]  # i=4
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=GAP * 2 + 80,
                                t=GAP * 3 + 25 + HT_LST,
                                r=GAP * 2 + 80 * 2,
                                b=0), 'cap=U&ncheck all'
                    ]  # i=5
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=WD_LST - 60 * 2,
                                t=GAP * 3 + 25 + HT_LST,
                                r=WD_LST - 60 * 1,
                                b=0), 'cap=&Import'
                    ]  # i=6
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=GAP + WD_LST - 60 * 1,
                                t=GAP * 3 + 25 + HT_LST,
                                r=GAP + WD_LST - 60 * 0,
                                b=0), 'cap=&Close'
                    ]  # i=7
                            )
                ]),
                3)  # start focus
            pass
            LOG and log('ans={}', ans)
            if ans is None: break  #while
            (ans_i, vals) = ans
            ans_s = apx.icase(False, '', ans_i == 2, 'file', ans_i == 4, 'all',
                              ans_i == 5, 'no', ans_i == 6, 'imp', ans_i == 7,
                              'close')
            if ans_s == 'close': break  #while
            v_3 = vals.splitlines()[3]
            crt, sels = v_3.split(';')
            sels = sels.strip(',').split(',')
            pass
            LOG and log('sels={}', sels)
            if False: pass
            elif ans_s == 'file':
                (new_imp_file, new_mcrs) = self.dlg_import_choose_mcrs()
                if new_imp_file is None: continue  #while
                imp_file = new_imp_file
                mcrs = new_mcrs
                lmcrs = len(mcrs)
                crt, sels = '0', ['1'] * lmcrs
            elif ans_s == 'all':
                sels = ['1'] * lmcrs
            elif ans_s == 'no':
                sels = ['0'] * lmcrs
            elif ans_s == 'imp':
                if '1' not in sels:
                    app.msg_box('Select some names', app.MB_OK)
                    continue
                (good_nms, fail_nms) = self.import_from_list([
                    mcr for (ind, mcr) in enumerate(mcrs) if sels[ind] == '1'
                ])
                l, lt = '\n', '\n      '
                app.msg_box(
                    'Import macros:' + lt + lt.join(good_nms) + l + '' + l +
                    'Skip duplicates:' + lt + lt.join(fail_nms), app.MB_OK)
Esempio n. 14
0
    def dlg_export(self):
        ''' Show dlg for export some macros.
        '''
        if app.app_api_version() < FROM_API_VERSION:
            return app.msg_status('Need update CudaText')
        if 0 == len(self.macros): return app.msg_status('No macros for export')
        exp_file = app.dlg_file(False, '', '', 'Cuda macros|*.cuda-macros')
        exp_file = '' if exp_file is None else exp_file
        exp_file = exp_file + ('' if '' == exp_file
                               or exp_file.endswith('.cuda-macros') else
                               '.cuda-macros')
        (WD_LST, HT_LST) = (500, 500)

        lmcrs = len(self.macros)
        crt, sels = '0', ['0'] * lmcrs
        while True:
            pass
            LOG and log('sels={}', sels)
            ans = app.dlg_custom(
                'Export macros',
                GAP + WD_LST + GAP,
                GAP * 5 + HT_LST + 25 * 2,
                '\n'.join([] + [
                    C1.join([
                        'type=label',
                        POS_FMT(l=GAP, t=GAP + 3, r=GAP +
                                70, b=0), 'cap=Export &to'
                    ]  # i=0
                            )
                ] + [
                    C1.join([
                        'type=edit',
                        POS_FMT(l=GAP + 70, t=GAP, r=GAP + WD_LST -
                                35, b=0), 'val={}'.format(exp_file)
                    ]  # i=1
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=GAP + HT_LST - 35,
                                t=GAP - 2,
                                r=GAP + WD_LST,
                                b=0), 'cap=&...'
                    ]  # i=2
                            )
                ] + [
                    C1.join([
                        'type=checklistbox',
                        POS_FMT(l=GAP,
                                t=GAP * 2 + 30,
                                r=GAP + WD_LST,
                                b=GAP + 25 + HT_LST), 'items=' +
                        '\t'.join([mcr['nm'] for mcr in self.macros]), 'val=' +
                        crt + ';' + ','.join(sels)
                    ]  # i=3
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=GAP * 1,
                                t=GAP * 3 + 25 + HT_LST,
                                r=GAP * 1 + 80 * 1,
                                b=0), 'cap=Check &all'
                    ]  # i=4
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=GAP * 2 + 80,
                                t=GAP * 3 + 25 + HT_LST,
                                r=GAP * 2 + 80 * 2,
                                b=0), 'cap=U&ncheck all'
                    ]  # i=5
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=WD_LST - 60 * 2,
                                t=GAP * 3 + 25 + HT_LST,
                                r=WD_LST - 60 * 1,
                                b=0), 'cap=&Export'
                    ]  # i=6
                            )
                ] + [
                    C1.join([
                        'type=button',
                        POS_FMT(l=GAP + WD_LST - 60 * 1,
                                t=GAP * 3 + 25 + HT_LST,
                                r=GAP + WD_LST - 60 * 0,
                                b=0), 'cap=&Close'
                    ]  # i=7
                            )
                ]),
                3)  # start focus
            pass
            LOG and log('ans={}', ans)
            if ans is None: break  #while
            (ans_i, vals) = ans
            ans_s = apx.icase(False, '', ans_i == 2, 'file', ans_i == 4, 'all',
                              ans_i == 5, 'no', ans_i == 6, 'exp', ans_i == 7,
                              'close')
            if ans_s == 'close': break  #while
            v_3 = vals.splitlines()[3]
            crt, sels = v_3.split(';')
            sels = sels.strip(',').split(',')
            pass
            LOG and log('sels={}', sels)
            if False: pass
            elif ans_s == 'file':
                new_exp_file = app.dlg_file(False, '', '',
                                            'Cuda macros|*.cuda-macros')
                if new_exp_file is not None:
                    exp_file = new_exp_file
                    exp_file = exp_file + ('' if '' == exp_file
                                           or exp_file.endswith('.cuda-macros')
                                           else '.cuda-macros')
            elif ans_s == 'all':
                sels = ['1'] * lmcrs
            elif ans_s == 'no':
                sels = ['0'] * lmcrs
            elif ans_s == 'exp':
                if '1' not in sels:
                    app.msg_box('Select some names', app.MB_OK)
                    continue
                self.export_to_file(exp_file, [
                    mcr for (ind, mcr) in enumerate(self.macros)
                    if sels[ind] == '1'
                ])
                return