Пример #1
0
    def update_tree(self, ed, lexer):
        getter = self.get_getter(lexer)
        if not getter: return

        filename = ed.get_filename()
        lines = ed.get_text_all().split("\n")
        heads = list(getter(filename, lines))

        ed.set_prop(app.PROP_CODETREE, False)
        app.tree_proc(self.h_tree, app.TREE_LOCK)
        app.tree_proc(self.h_tree, app.TREE_ITEM_DELETE, 0)
        last_levels = {0: 0}
        for index, data in enumerate(heads):
            pos = data[0]
            level = data[1]
            header = data[2]
            icon_index = data[3] if len(data) > 3 else -1

            for test_level in reversed(range(level)):
                parent = last_levels.get(test_level)
                if parent is None:
                    continue
                identity = app.tree_proc(self.h_tree,
                                         app.TREE_ITEM_ADD,
                                         parent,
                                         index=-1,
                                         text=header,
                                         image_index=icon_index)
                # when adding level K, forget all levels > K
                last_levels = {
                    k: v
                    for k, v in last_levels.items() if k <= level
                }
                last_levels[level] = identity

                if type(pos) == int:
                    if index == len(heads) - 1:
                        end_y = len(lines) - 1
                        s = ed.get_text_line(end_y)
                        if s is None:
                            end_x = 0
                        else:
                            end_x = len(s)
                    else:
                        end_y = heads[index +
                                      1][0]  # line_index of next header
                        end_x = 0
                    rng = (0, pos, end_x, end_y)
                else:
                    rng = pos

                app.tree_proc(self.h_tree,
                              app.TREE_ITEM_SET_RANGE,
                              identity,
                              index=-1,
                              text=rng)
                break

        app.tree_proc(self.h_tree, app.TREE_UNLOCK)
Пример #2
0
    def run(self, mcr_id, times=1, waits=0, while_chngs=False, till_endln=False):
        ''' Main (and single) way to run any macro
        '''
        pass;                   LOG and log('mcr_id, times, waits, while_chngs, till_endln={}',(mcr_id, times, waits, while_chngs, till_endln))
        mcr     = self.mcr4id.get(str(mcr_id))
        if mcr is None:
            pass;               LOG and log('no id',)
            return app.msg_status(_('No macros: {}').format(mcr_id))
        cmds4eval   = ';'.join(mcr['evl'])
        pass;                   LOG and log('nm, cmds4eval={}',(mcr['nm'], cmds4eval))
        how_t       = 'wait'
        rp_ctrl     = self.tm_ctrl.get('rp_ctrl', 1000)                     # testing one of 1000 execution
        tm_wait     = waits if waits>0 else self.tm_ctrl.get('tm_wait', 10) # sec
        start_t     = datetime.datetime.now()
        pre_body    = '' if not while_chngs else ed.get_text_all()
        for rp in range(times if times>0 else 0xffffffff):
            exec(cmds4eval)
            if till_endln and ed.get_carets()[0][1] == ed.get_line_count()-1:
                pass;           LOG and log('break endln',)
                break   #for rp
            if while_chngs:
                new_body    = ed.get_text_all()
                if pre_body == new_body:    
                    pass;       LOG and log('break no change',)
                    break   #for rp
                pre_body    = new_body
            if  (how_t=='wait'
            and (rp_ctrl-1) == rp % rp_ctrl
            and tm_wait < (datetime.datetime.now()-start_t).seconds):
                cnts    = ([
  dict(              tp='lb'    ,t=GAP          ,l=GAP  ,w=400   ,cap=_('Macro "{}" playback time is too long'.format(mcr['nm'])))
 ,dict(cid='wait'   ,tp='bt'    ,t=GAP*2+25*1   ,l=GAP  ,w=400   ,cap=_('Wait &another {} sec').format(tm_wait)  ,props='1'      )   # default
 ,dict(cid='cont'   ,tp='bt'    ,t=GAP*3+25*2   ,l=GAP  ,w=400   ,cap=_('Continue &without control')                             )
 ,dict(cid='stop'   ,tp='bt'    ,t=GAP*6+25*3   ,l=GAP  ,w=300   ,cap=_('&Cancel playback [ESC]')                                )
                        ])
                btn,vals,chds= dlg_wrapper(_('Playback macro'), GAP*2+400, GAP*7+4*25, cnts, {})
                if btn is None or btn=='stop':
                    pass;       LOG and log('break by user',)
                    app.msg_status(_('Cancel playback macro: {}'.format(mcr['nm'])))
                    break   #for rp
                if btn=='cont': #ans=='cont':
                    how_t   = 'work'
                if btn=='wait': #ans=='wait':
                    start_t = datetime.datetime.now()
           #for rp
        self.last_mcr_id = mcr_id
Пример #3
0
 def run(self, mcr_id, times=1, waits=0, while_chngs=False, till_endln=False):
     ''' Main (and single) way to run any macro
     '''
     pass;                   LOG and log('mcr_id, times, waits, while_chngs, till_endln={}',(mcr_id, times, waits, while_chngs, till_endln))
     mcr     = self.mcr4id.get(str(mcr_id))
     if mcr is None:
         pass;               LOG and log('no id',)
         return app.msg_status('No macros: {}'.format(mcr_id))
     cmds4eval   = ';'.join(mcr['evl'])
     pass;                   LOG and log('nm, cmds4eval={}',(mcr['nm'], cmds4eval))
     how_t       = 'wait'
     rp_ctrl     = self.tm_ctrl.get('rp_ctrl', 1000)                     # testing one of 1000 execution
     tm_wait     = waits if waits>0 else self.tm_ctrl.get('tm_wait', 10) # sec
     start_t     = datetime.datetime.now()
     pre_body    = '' if not while_chngs else ed.get_text_all()
     for rp in range(times if times>0 else 0xffffffff):
         exec(cmds4eval)
         if till_endln and ed.get_carets()[0][1] == ed.get_line_count()-1:
             pass;           LOG and log('break endln',)
             break   #for rp
         if while_chngs:
             new_body    = ed.get_text_all()
             if pre_body == new_body:    
                 pass;       LOG and log('break no change',)
                 break   #for rp
             pre_body    = new_body
         if  (how_t=='wait'
         and (rp_ctrl-1) == rp % rp_ctrl
         and tm_wait < (datetime.datetime.now()-start_t).seconds):
             WD_BTN  = 220
             ans = app.dlg_custom(  'Playback macro', GAP*2+WD_BTN, GAP*7+4*25,  '\n'.join([]
                 +[C1.join(['type=label'     ,POS_FMT(l=GAP,  t=GAP*1+25*0+3,   r=GAP+WD_BTN, b=0)
                           ,'cap=Macro playback time is too long'
                           ] # i=0
                  )]
                 +[C1.join(['type=button'    ,POS_FMT(l=GAP,  t=GAP*2+25*1,    r=GAP+WD_BTN, b=0)
                           ,'cap=Wait &another {} sec'.format(tm_wait)
                           ] # i=1
                  )]
                 +[C1.join(['type=button'    ,POS_FMT(l=GAP,  t=GAP*3+25*2,    r=GAP+WD_BTN, b=0)
                           ,'cap=Continue &without control'
                           ] # i=2
                  )]
                 +[C1.join(['type=button'    ,POS_FMT(l=GAP,  t=GAP*6+25*3,    r=GAP+WD_BTN, b=0)
                           ,'cap=&Cancel playback [ESC]'
                           ] # i=3
                  )]
                 ), 1)    # start focus
             pass;          #LOG and log('ans={}',ans)
             ans     =('break'   if ans is None  else
                       'break'   if ans[0]==3    else
                       'wait'    if ans[0]==1    else
                       'cont'    if ans[0]==2    else 'break')
             if ans=='cont':
                 how_t   = 'work'
             if ans=='wait':
                 start_t = datetime.datetime.now()
             if ans=='break':
                 pass;       LOG and log('break by user',)
                 break   #for rp
        #for rp
     self.last_mcr_id = mcr_id
Пример #4
0
 def lineops_trim_right(self):
     ed.set_text_all("\n".join(
         map(lambda x: x.rstrip(),
             ed.get_text_all().split("\n"))))
Пример #5
0
 def lineops_remove_dup_all(self):
     ed.set_text_all("\n".join(list(set(ed.get_text_all().split("\n")))))
Пример #6
0
 def lineops_sort_desc(self):
     ed.set_text_all("\n".join(
         sorted(ed.get_text_all().split("\n"), reverse=True)))
Пример #7
0
 def lineops_sort_asc(self):
     ed.set_text_all("\n".join(sorted(ed.get_text_all().split("\n"))))
Пример #8
0
 def lineops_remove_empty(self):
     ed.set_text_all("\n".join(
         list(filter(None,
                     ed.get_text_all().split("\n")))))
Пример #9
0
 def run(self,
         mcr_id,
         times=1,
         waits=0,
         while_chngs=False,
         till_endln=False):
     ''' Main (and single) way to run any macro
     '''
     pass
     LOG and log('mcr_id, times, waits, while_chngs, till_endln={}',
                 (mcr_id, times, waits, while_chngs, till_endln))
     mcr = self.mcr4id.get(str(mcr_id))
     if mcr is None:
         pass
         LOG and log('no id', )
         return app.msg_status('No macros: {}'.format(mcr_id))
     cmds4eval = ';'.join(mcr['evl'])
     pass
     LOG and log('nm, cmds4eval={}', (mcr['nm'], cmds4eval))
     how_t = 'wait'
     rp_ctrl = self.tm_ctrl.get('rp_ctrl',
                                1000)  # testing one of 1000 execution
     tm_wait = waits if waits > 0 else self.tm_ctrl.get('tm_wait',
                                                        10)  # sec
     start_t = datetime.datetime.now()
     pre_body = '' if not while_chngs else ed.get_text_all()
     for rp in range(times if times > 0 else 0xffffffff):
         exec(cmds4eval)
         if till_endln and ed.get_carets()[0][1] == ed.get_line_count() - 1:
             pass
             LOG and log('break endln', )
             break  #for rp
         if while_chngs:
             new_body = ed.get_text_all()
             if pre_body == new_body:
                 pass
                 LOG and log('break no change', )
                 break  #for rp
             pre_body = new_body
         if (how_t == 'wait' and (rp_ctrl - 1) == rp % rp_ctrl and tm_wait <
             (datetime.datetime.now() - start_t).seconds):
             WD_BTN = 220
             ans = app.dlg_custom(
                 'Playback macro',
                 GAP * 2 + WD_BTN,
                 GAP * 7 + 4 * 25,
                 '\n'.join([] + [
                     C1.join([
                         'type=label',
                         POS_FMT(l=GAP,
                                 t=GAP * 1 + 25 * 0 + 3,
                                 r=GAP + WD_BTN,
                                 b=0), 'cap=Macro playback time is too long'
                     ]  # i=0
                             )
                 ] + [
                     C1.join([
                         'type=button',
                         POS_FMT(
                             l=GAP, t=GAP * 2 + 25 * 1, r=GAP + WD_BTN, b=0
                         ), 'cap=Wait &another {} sec'.format(tm_wait)
                     ]  # i=1
                             )
                 ] + [
                     C1.join([
                         'type=button',
                         POS_FMT(
                             l=GAP, t=GAP * 3 + 25 * 2, r=GAP +
                             WD_BTN, b=0), 'cap=Continue &without control'
                     ]  # i=2
                             )
                 ] + [
                     C1.join([
                         'type=button',
                         POS_FMT(
                             l=GAP, t=GAP * 6 + 25 * 3, r=GAP +
                             WD_BTN, b=0), 'cap=&Cancel playback [ESC]'
                     ]  # i=3
                             )
                 ]),
                 1)  # start focus
             pass
             #LOG and log('ans={}',ans)
             ans = ('break'
                    if ans is None else 'break' if ans[0] == 3 else 'wait'
                    if ans[0] == 1 else 'cont' if ans[0] == 2 else 'break')
             if ans == 'cont':
                 how_t = 'work'
             if ans == 'wait':
                 start_t = datetime.datetime.now()
             if ans == 'break':
                 pass
                 LOG and log('break by user', )
                 break  #for rp
     #for rp
     self.last_mcr_id = mcr_id