Example #1
0
class ConsoleGUI:
    def __init__(self, interpreter):
        self.interpreter = interpreter
        self.history_objects = []

        skin = LUIDefaultSkin()
        skin.load()

        region = LUIRegion.make("LUI", base.win)
        handler = LUIInputHandler()
        base.mouseWatcher.attach_new_node(handler)
        region.set_input_handler(handler)

        self.console_frame = LUIFrame(
            parent=region.root,
            pos=(0, 0),
            width=base.win.get_x_size() - 10,
            height=base.win.get_y_size() * 0.75,
            style=LUIFrame.FS_raised,
            #style = LUIFrame.FS_sunken,
            margin=(5, 5, 5, 5),
        )
        console = LUIVerticalLayout(parent=self.console_frame, spacing=3)
        #console.use_dividers = True
        console.margin = (0, 0, 0, 0)
        console.width = self.console_frame.width

        self.history_region = LUIScrollableRegion(margin=0,
                                                  width=console.width - 10)
        console.add(self.history_region)
        self.history = LUIVerticalLayout(
            parent=self.history_region.content_node, spacing=2)
        self.history.margin = (0, 0, 0, 0)
        self.history.width = self.history_region.width

        self.command_line = LUIInputField(width=console.width - 10)
        console.add(self.command_line)
        self.command_line.bind("tab", self.tab)
        self.command_line.bind("enter", self.enter)
        self.command_line.bind("control-c", self.copy)
        self.command_line.bind("control-v", self.paste)
        self.command_line.bind("control-x", self.cut)
        self.command_line.bind("control-u", self.kill_to_start)
        self.command_line.bind("control-k", self.kill_to_end)
        self.command_line.bind("control-l", self.kill_line)

    def set_visible(self, state):
        if state:
            self.console_frame.show()
            self.command_line.request_focus()
        else:
            self.console_frame.hide()
            # FIXME: Un-focus

    def write(self, text, color="font_color_entry"):
        self.history_objects.append(
            ConsoleHistoryItem(self.history, text, color=color))
        #self.history_region.scroll_to_bottom()

    def enter(self, event):
        print("text was entered. " + str(event))
        should_continue = self.interpreter.command(
            self.command_line.get_value() + "\n")
        if not should_continue:
            self.command_line.set_value("")

    def tab(self, event):
        # FIXME: Implement
        print("tab!")
        self.copy(event)

    def copy(self, event):
        # FIXME: If text is selected, limit to that.
        tk_window = tk.Tk()
        tk_window.withdraw()
        tk_window.clipboard_clear()
        tk_window.clipboard_append(self.command_line.get_value())
        print(tk_window, self.command_line.get_value(),
              tk_window.clipboard_get())
        tk_window.destroy()

    def cut(self, event):
        # FIXME: If text is selected, limit to that.
        self.copy(event)
        self.command_line.set_value("")

    def paste(self, event):
        # FIXME: Add text at cursor position.
        tk_window = tk.Tk()
        tk_window.withdraw()
        print(tk_window.clipboard_get())
        tk_window.destroy()

    def kill_to_start(self):
        # FIXME: Implement
        print("kill_to_start")

    def kill_to_end(self):
        # FIXME: Implement
        print("kill_to_end")

    def kill_line(self):
        # FIXME: Implement
        print("kill_line")
Example #2
0
class ConsoleGUI:
    def __init__(self, interpreter):
        self.interpreter = interpreter
        self.history_objects = []
        
        skin = LUIDefaultSkin()
        skin.load()

        region = LUIRegion.make("LUI", base.win)
        handler = LUIInputHandler()
        base.mouseWatcher.attach_new_node(handler)
        region.set_input_handler(handler)

        self.console_frame = LUIFrame(parent = region.root,
                                      pos = (0, 0),
                                      width = base.win.get_x_size() - 10,
                                      height = base.win.get_y_size() * 0.75,
                                      style = LUIFrame.FS_raised,
                                      #style = LUIFrame.FS_sunken,
                                      margin = (5, 5, 5, 5),
                                      )
        console = LUIVerticalLayout(parent = self.console_frame, spacing = 3)
        #console.use_dividers = True
        console.margin = (0, 0, 0, 0)
        console.width = self.console_frame.width
        
        self.history_region = LUIScrollableRegion(margin = 0, width = console.width - 10)
        console.add(self.history_region)
        self.history = LUIVerticalLayout(parent = self.history_region.content_node,
                                         spacing = 2)
        self.history.margin = (0, 0, 0, 0)
        self.history.width = self.history_region.width

        self.command_line = LUIInputField(width = console.width - 10)
        console.add(self.command_line)
        self.command_line.bind("tab", self.tab)
        self.command_line.bind("enter", self.enter)
        self.command_line.bind("control-c", self.copy)
        self.command_line.bind("control-v", self.paste)
        self.command_line.bind("control-x", self.cut)
        self.command_line.bind("control-u", self.kill_to_start)
        self.command_line.bind("control-k", self.kill_to_end)
        self.command_line.bind("control-l", self.kill_line)

    def set_visible(self, state):
        if state:
            self.console_frame.show()
            self.command_line.request_focus()
        else:
            self.console_frame.hide()
            # FIXME: Un-focus
        
    def write(self, text, color = "font_color_entry"):
        self.history_objects.append(ConsoleHistoryItem(self.history,
                                                       text,
                                                       color = color))
        #self.history_region.scroll_to_bottom()

    def enter(self, event):
        print("text was entered. " + str(event))
        should_continue = self.interpreter.command(self.command_line.get_value()+"\n")
        if not should_continue:
            self.command_line.set_value("")

    def tab(self, event):
        # FIXME: Implement
        print("tab!")
        self.copy(event)

    def copy(self, event):
        # FIXME: If text is selected, limit to that.
        tk_window = tk.Tk()
        tk_window.withdraw()
        tk_window.clipboard_clear()
        tk_window.clipboard_append(self.command_line.get_value())
        print(tk_window, self.command_line.get_value(), tk_window.clipboard_get())
        tk_window.destroy()

    def cut(self, event):
        # FIXME: If text is selected, limit to that.
        self.copy(event)
        self.command_line.set_value("")

    def paste(self, event):
        # FIXME: Add text at cursor position.
        tk_window = tk.Tk()
        tk_window.withdraw()
        print(tk_window.clipboard_get())
        tk_window.destroy()

    def kill_to_start(self):
        # FIXME: Implement
        print("kill_to_start")

    def kill_to_end(self):
        # FIXME: Implement
        print("kill_to_end")

    def kill_line(self):
        # FIXME: Implement
        print("kill_line")