def general_menu(tab): cmd = wcall.menu_general() if cmd == -1: return tab.pane.app.display() cmd = cmd[0] if cmd == '/': findgrep(tab) elif cmd == 'g': goto_dir(tab) elif cmd == '#': show_dirs_size(tab) elif cmd == 's': sort(tab) elif cmd == 't': tree(tab) elif cmd == 'f': show_fs_info() elif cmd == 'o': #command_line(tab) open_shell(tab) elif cmd == 'c': __view_edit(tab.app, utils.insert_backslash(tab.app.prefs.file), 0, True) tab.app.prefs.load() elif cmd == 'd': tab.app.prefs.check_progs() tab.app.prefs.save() tab.app.prefs.load() wcall.msg_default_settings()
def __cygwin_convert_path(path): try: path = utils.insert_backslash( os.popen('cygpath.exe -w %s' % path).readlines()[0]) except: return None return path
def findgrep(tab): fs, pat = wcall.dentry_findgrep(tab.path) if fs == None or fs == '': return path = os.path.dirname(fs) fs = os.path.basename(fs) if path in [None, '']: path = tab.path if path[0] != os.sep: path = os.path.join(tab.path, path) tab.app.display() #clear screen from previos dialog st, m = wcall.win_searching(tab.pane.app, path, fs, pat) if st ==-1: return par = '' while 1: cmd, par = wcall.win_search_list(m, par) f, line = '', 0 if par: if pat: try: line = int(par.split(':')[0]) except ValueError: f = os.path.join(path, par) else: f = os.path.join(path, par[par.find(':')+1:]) else: f = os.path.join(path, par) if cmd == 0: # goto file __goto(f, tab) break elif cmd == 1: # panelize __panelize(tab, path, m) break elif cmd == 2: # view __view_edit(tab.app, utils.insert_backslash(f), line, 0) elif cmd == 3: # edit __view_edit(tab.app, utils.insert_backslash(f), line, 1) elif cmd == 4: cmd2 = wcall.entry_dosmthing(tab.path) __cmd_file(tab, cmd2, f) else: break
def findgrep(tab): fs, pat = wcall.dentry_findgrep(tab.path) if fs == None or fs == '': return path = os.path.dirname(fs) fs = os.path.basename(fs) if path in [None, '']: path = tab.path if path[0] != os.sep: path = os.path.join(tab.path, path) tab.app.display() #clear screen from previos dialog st, m = wcall.win_searching(tab.pane.app, path, fs, pat) if st == -1: return par = '' while 1: cmd, par = wcall.win_search_list(m, par) f, line = '', 0 if par: if pat: try: line = int(par.split(':')[0]) except ValueError: f = os.path.join(path, par) else: f = os.path.join(path, par[par.find(':') + 1:]) else: f = os.path.join(path, par) if cmd == 0: # goto file __goto(f, tab) break elif cmd == 1: # panelize __panelize(tab, path, m) break elif cmd == 2: # view __view_edit(tab.app, utils.insert_backslash(f), line, 0) elif cmd == 3: # edit __view_edit(tab.app, utils.insert_backslash(f), line, 1) elif cmd == 4: cmd2 = wcall.entry_dosmthing(tab.path) __cmd_file(tab, cmd2, f) else: break
def __init__(self, app, path, files, pattern, ignorecase=0): self.pattern, self.path = pattern, path pattern_esc = utils.insert_backslash(pattern) pathescape = utils.insert_backslash(path) ign = '' if ignorecase: ign = 'i' if pattern: cmd = 'find %s -name \"%s\" -exec grep -EHn%s \"%s\" {} \\;' % \ (pathescape, files, ign, pattern_esc) text = 'Searching for \"%s\" in \"%s\" files' % (pattern, files) else: cmd = 'find %s -name \"%s\" -print' % (pathescape, files) text = 'Searching for \"%s\" files' % files args = cmd, path, True ProcessFunc.__init__(self, app, 'Search', text, utils.run_shell, *args)
def __init__(self, app, path, files, pattern, ignorecase = 0): self.pattern, self.path = pattern, path pattern_esc = utils.insert_backslash(pattern) pathescape = utils.insert_backslash(path) ign = '' if ignorecase: ign = 'i' if pattern: cmd = 'find %s -name \"%s\" -exec grep -EHn%s \"%s\" {} \\;' % \ (pathescape, files, ign, pattern_esc) text = 'Searching for \"%s\" in \"%s\" files' % (pattern, files) else: cmd = 'find %s -name \"%s\" -print' % (pathescape, files) text = 'Searching for \"%s\" files' % files args = cmd, path, True ProcessFunc.__init__(self, app, 'Search', text, utils.run_shell, *args)
def quit_program(self,icode): """save settings and prepare to quit""" import utils if self.prefs.options['save_conf_at_exit']: self.prefs.save() for tab in self.lpane.tabs + self.rpane.tabs: if tab.Vfs: tab.Vfs.exit() #have to call explicitly to delete tmpdir #close avfs mount os.system('fusermount -uz %s' %os.path.expanduser('~/.avfs')) return utils.insert_backslash(self.act_pane.act_tab.path)
def autocomplete(self, exe_comp, pth_comp): text = self.text inp_text = text[:self.pos].lstrip() inp_stings = inp_text.split() l = len(inp_stings) edit = '' if l: edit = inp_stings[l - 1] for i in range(l): if inp_stings[l - i - 2].endswith('\\'): edit = inp_stings[l - i - 2].replace('\\', ' ') + edit else: break search = enc_str(edit) if os.sep in edit: #completing path if (pth_comp): entries = self.complete(os.path.expanduser(search), self.panelpath) else: #completing command if (exe_comp): entries = self.complete_exe(search) if not entries: return elif len(entries) == 1: selected = entries.pop() else: y, x = self.entry.getbegyx() if y == app.maxh - 1: #for command line y -= (min(len(entries) + 4, app.maxh - 1)) cursor_hide() # selected = ListBox(entries, y+1 , x+self.pos ).run() selected = ListBox(app, entries, '', y + 1, x + self.pos).run() cursor_show() app.act_pane.display() app.noact_pane.display() if selected != -1: selected = insert_backslash(dec_str(selected)) if os.sep in edit: text_l = self.join(text[:self.pos], selected) else: text_l = ''.join([text[:self.pos - len(edit)], selected]) self.text = (text_l + text[self.pos:]) self.pos = len(text_l)
def autocomplete(self, exe_comp, pth_comp): text = self.text inp_text = text[:self.pos].lstrip() inp_stings = inp_text.split() l = len(inp_stings) edit='' if l: edit=inp_stings[l-1] for i in range (l): if inp_stings[l-i-2].endswith('\\'): edit = inp_stings[l-i-2].replace('\\',' ')+edit else: break search = enc_str(edit) if os.sep in edit: #completing path if(pth_comp): entries = self.complete(os.path.expanduser(search), self.panelpath) else: #completing command if(exe_comp): entries = self.complete_exe(search) if not entries: return elif len(entries) == 1: selected = entries.pop() else: y, x = self.entry.getbegyx() if y == app.maxh - 1: #for command line y -= (min(len(entries)+4, app.maxh-1)) cursor_hide() # selected = ListBox(entries, y+1 , x+self.pos ).run() selected = ListBox(app,entries,'', y + 1 , x+self.pos ).run() cursor_show() app.act_pane.display() app.noact_pane.display() if selected != -1: selected = insert_backslash(dec_str(selected)) if os.sep in edit: text_l = self.join(text[:self.pos], selected) else: text_l = ''.join([text[:self.pos-len(edit)], selected]) self.text = (text_l+ text[self.pos:]) self.pos = len(text_l)
def command_line(tab): app = tab.pane.app app.cmdrunning = True com = wcmd.CommandEntry(app,1,1,tab.path).run() app.cmdrunning = False if com: curses.endwin() path = utils.insert_backslash(tab.path) strln = (max(app.maxw/2 - len(com)-2, 0))*"-" os.system("%s --login -i -c\ \"echo -e '\E[32mCommand: \E[31m%s \E[32m%s';\ tput sgr0; cd %s; %s\""\ % (app.prefs.progs['shell'], com, strln ,path, com)) curses.curs_set(0) return 10
def command_line(tab): app = tab.pane.app app.cmdrunning = True com = wcmd.CommandEntry(app, 1, 1, tab.path).run() app.cmdrunning = False if com: curses.endwin() path = utils.insert_backslash(tab.path) strln = (max(app.maxw / 2 - len(com) - 2, 0)) * "-" os.system("%s --login -i -c\ \"echo -e '\E[32mCommand: \E[31m%s \E[32m%s';\ tput sgr0; cd %s; %s\""\ % (app.prefs.progs['shell'], com, strln ,path, com)) curses.curs_set(0) return 10
def edit_file(tab): path = os.path.join(tab.path, tab.sorted[tab.file_i]) __view_edit(tab.app, utils.insert_backslash(path), 0, True) #edit
def open_shell(tab): curses.endwin() path = utils.insert_backslash(tab.path) os.system('cd \"%s\"; %s ' % (tab.path, tab.pane.app.prefs.progs['shell']))
def __cygwin_convert_path(path): try: path = utils.insert_backslash(os.popen('cygpath.exe -w %s' %path).readlines()[0]) except: return None return path