예제 #1
0
파일: cmdline.py 프로젝트: anmitsu/pyful
 def __init__(self):
     TextBox.__init__(self, "Cmdline")
     self.mode = None
     self.history = History(self)
     self.clipboard = Clipboard(self)
     self.output = Output(self)
     self.completion = completion.Completion(self)
예제 #2
0
파일: filer.py 프로젝트: anmitsu/pyful
 def __init__(self, directory):
     TextBox.__init__(self)
     self.dir = directory
     self.results = []
     self.cache = []
     self.startfname = ""
     self.history = self.History()
     self.refresh()
예제 #3
0
파일: cmdline.py 프로젝트: anmitsu/pyful
 def __init__(self, cmdline):
     ListBox.__init__(self)
     self.title = "clipboard"
     self.cmdline = cmdline
     self.textbox = TextBox()
     self.textbox.prompt = " Clipboard: "
     self.textbox.edithook = self.start
예제 #4
0
파일: cmdline.py 프로젝트: anmitsu/pyful
class Clipboard(ListBox):
    maxsave = 100
    clip = []

    def __init__(self, cmdline):
        ListBox.__init__(self)
        self.title = "clipboard"
        self.cmdline = cmdline
        self.textbox = TextBox()
        self.textbox.prompt = " Clipboard: "
        self.textbox.edithook = self.start

    def refresh(self):
        self.textbox.refresh()
        super(self.__class__, self).refresh()

    def loadfile(self, path):
        path = os.path.expanduser(path)
        try:
            with open(path, "r") as f:
                for i, line in enumerate(f):
                    if self.maxsave <= i:
                        break
                    self.clip.append(line.strip(os.linesep))
        except IOError:
            return

    def savefile(self, path):
        path = os.path.expanduser(path)
        dirname = util.unix_dirname(path)
        try:
            os.makedirs(dirname)
        except OSError:
            pass
        try:
            with open(path, "w") as f:
                f.write("\n".join(self.clip))
        except IOError:
            return

    def insert(self):
        entry = self.cursor_entry()
        self.cmdline.insert(entry.text)
        self.finish()

    def delete(self):
        entry = self.cursor_entry()
        try:
            self.clip.remove(entry.text)
        except ValueError:
            return
        x = self.cursor
        self.start()
        self.setcursor(x)

    def yank(self, string):
        if not string:
            return
        try:
            self.clip.remove(string)
        except ValueError:
            pass
        if len(self.clip) >= self.maxsave:
            self.clip.pop(0)
        self.clip.append(string)

    def paste(self):
        if not self.clip:
            return
        pastetext = self.clip[-1]
        self.cmdline.insert(pastetext)
        self.finish()

    def draw(self):
        super(self.__class__, self).draw()
        self.textbox.draw()

    def input(self, key):
        if key in self.keymap:
            self.keymap[key]()
        elif key == "SPC":
            self.textbox.insert(" ")
        elif util.mbslen(key) == 1:
            self.textbox.insert(key)
        else:
            self.finish()
            self.cmdline.input(key)

    def start(self):
        if not self.clip:
            return
        text = self.textbox.text
        entries = [Entry(item) for item in self.clip if text in item]
        entries.reverse()
        self.cmdline.history.hide()
        self.show(entries)
        self.textbox.panel.show()

    def finish(self):
        self.hide()
        self.textbox.hide()
        self.cmdline.history.start()