예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
layout = LUIVerticalLayout(parent=text_container.content_node)

def send_command(event):
    """ Called when the user presses enter in the input field, submits the
    command and prints something on the console """
    label = LUIFormattedLabel()
    color = (0.9, 0.9, 0.9, 1.0)
    if event.message.startswith(u"/"):
        color = (0.35, 0.65, 0.24, 1.0)
    label.add(text=">>>  ", color=(0.35, 0.65, 0.24, 1.0))
    label.add(text=event.message, color=color)
    layout.add(label)

    result = LUIFormattedLabel()
    result.add("Your command in rot13: " + event.message.encode("rot13"), color=(0.4, 0.4, 0.4, 1.0))
    layout.add(result)
    input_field.clear()

    text_container.scroll_to_bottom()

# Create the input box
input_field = LUIInputField(parent=container, bottom=0, left=0, width="100%")
input_field.bind("enter", send_command)
input_field.request_focus()

# Add some initial commands
for demo_command in ["Hello world!", "This is a simple console", "You can type commands like this:", "/test"]:
    input_field.trigger_event("enter", unicode(demo_command))

s.run()
예제 #4
0
from DemoFramework import DemoFramework
from LUIInputField import LUIInputField

import random

f = DemoFramework()
f.prepare_demo("LUIInputField")

# Constructor
f.add_constructor_parameter("value", "u''")
f.add_constructor_parameter("placeholder", "u'Enter some text ..'")
f.add_property("value", "string")
f.add_event("changed")

# Construct source code
f.construct_sourcecode("LUIInputField")

# Create 2 new buttons, and store them in a vertical layout
field = LUIInputField(parent=f.get_widget_node())

f.set_actions({
        "Set Random Text": lambda: field.set_value(u"Text: " + unicode(random.randint(100, 10000000))),
        "Clear": lambda: field.clear(),
    })

run()
예제 #5
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")
예제 #6
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")