コード例 #1
0
 def __init__(self, master):
     self.frame=frame=Tkinter.Frame(master)
     frame.pack()
     self.lines=["Hello"]
     self.RL=BaseReadline()
     self.RL.read_inputrc()
     self.prompt=">>>"
     self.readline_setup(self.prompt)
     self.textvar = Tkinter.StringVar()
     self._update_line()
     self.text=Tkinter.Label(frame, textvariable=self.textvar,width=50,height=40,justify=Tkinter.LEFT,anchor=Tkinter.NW)
     self.text.pack(side=Tkinter.LEFT)
     master.bind("<Key>",self.handler)
     self.locals={}
コード例 #2
0
ファイル: tk_gui.py プロジェクト: farisachugthai/pyreadline
class App:
    def __init__(self, master, frame=None, **kwargs):
        self.master = master
        self.frame = Tkinter.Frame(master)
        self.frame.pack()
        self.lines = ["Hello"]
        self.RL = BaseReadline(**kwargs)
        self.RL.read_inputrc()
        self.prompt = ">>>"
        self.readline_setup(self.prompt)
        self.textvar = Tkinter.StringVar()
        self._update_line()
        self.text = Tkinter.Label(
            frame,
            textvariable=self.textvar,
            width=50,
            height=40,
            justify=Tkinter.LEFT,
            anchor=Tkinter.NW,
        )
        self.text.pack(side=Tkinter.LEFT)
        master.bind("<Key>", self.handler)
        self.locals = {}

    def handler(self, event):
        keyevent = KeyPress_from_event(event)
        try:
            result = self.RL.process_keyevent(keyevent)
        except EOFError:
            self.frame.quit()
            return
        if result:
            self.lines.append(self.prompt + " " + self.RL.get_line_buffer())
            line = self.RL.get_line_buffer()
            if line.strip():
                try:
                    result = eval(line, globals(), self.locals)
                    self.lines.append(repr(result))
                except:
                    self.lines.append("ERROR")
            self.readline_setup(self.prompt)
        self._update_line()

    def readline_setup(self, prompt=""):
        self.RL.readline_setup(prompt)

    def _update_line(self):
        self.textvar.set(
            "\n".join(self.lines +
                      [self.prompt + " " + self.RL.get_line_buffer()]))
コード例 #3
0
ファイル: tk_gui.py プロジェクト: minersoft/miner
 def __init__(self, master):
     self.frame=frame=Tkinter.Frame(master)
     frame.pack()
     self.lines=["Hello"]
     self.RL=BaseReadline()
     self.RL.read_inputrc()
     self.prompt=">>>"
     self.readline_setup(self.prompt)
     self.textvar = Tkinter.StringVar()
     self._update_line()
     self.text=Tkinter.Label(frame, textvariable=self.textvar,width=50,height=40,justify=Tkinter.LEFT,anchor=Tkinter.NW)
     self.text.pack(side=Tkinter.LEFT)
     master.bind("<Key>",self.handler)
     self.locals={}
コード例 #4
0
ファイル: tk_gui.py プロジェクト: AshishNamdev/pyreadline
class App:
    def __init__(self, master):
        self.frame = frame = Tkinter.Frame(master)
        frame.pack()
        self.lines = ["Hello"]
        self.RL = BaseReadline()
        self.RL.read_inputrc()
        self.prompt = ">>>"
        self.readline_setup(self.prompt)
        self.textvar = Tkinter.StringVar()
        self._update_line()
        self.text = Tkinter.Label(
            frame, textvariable=self.textvar, width=50, height=40, justify=Tkinter.LEFT, anchor=Tkinter.NW
        )
        self.text.pack(side=Tkinter.LEFT)
        master.bind("<Key>", self.handler)
        self.locals = {}

    def handler(self, event):
        keyevent = KeyPress_from_event(event)
        try:
            result = self.RL.process_keyevent(keyevent)
        except EOFError:
            self.frame.quit()
            return
        if result:
            self.lines.append(self.prompt + " " + self.RL.get_line_buffer())
            line = self.RL.get_line_buffer()
            if line.strip():
                try:
                    result = eval(line, globals(), self.locals)
                    self.lines.append(repr(result))
                except:
                    self.lines.append("ERROR")
            self.readline_setup(self.prompt)
        self._update_line()

    def readline_setup(self, prompt=""):
        self.RL.readline_setup(prompt)

    def _update_line(self):
        self.textvar.set("\n".join(self.lines + [self.prompt + " " + self.RL.get_line_buffer()]))