示例#1
0
def horizontal_tokenlist_window(get_tokens, align='left'):
    tlc_attrs = {}
    if align == 'center':
        tlc_attrs['align_center'] = True
    if align == 'right':
        tlc_attrs['align_right'] = True
    height = dim(exact=1)
    content = controls.TokenListControl(get_tokens, **tlc_attrs)
    return containers.Window(height=height, content=content)
示例#2
0
文件: ui4.py 项目: lshenglin/dso-test
 def file_selection(self, filenum):
     sublayout = containers.VSplit([
         self.text_block(lambda x: [(Token, u" {:>2d}:".format(filenum))],
                         dont_extend_width=True),
         containers.Window(
             content=controls.BufferControl(buffer_name='FN%d' % filenum),
             dont_extend_height=True)
     ])
     return sublayout
    def _create_windows(self):
        """Create all the windows of the display (input, output, debugger,
        text completer)"""
        module_names = [m.name for m in self.model.modules]
        search_field = SearchToolbar()
        # Generate the input text area
        input_field = TextArea(prompt='> ',
                               style='class:arrow',
                               completer=ModuleCompleter(module_names),
                               search_field=search_field,
                               height=1,
                               multiline=False,
                               wrap_lines=True)

        # Field to show current time
        end_time = str(self.model.get_end_time())
        time_field = TextArea(text="",
                              style='class:rprompt',
                              height=1,
                              width=len(end_time) * 2 + 7,
                              multiline=False)

        output = Label(text="")
        self.display.update()

        # Create container with display window and input text area
        container = pt_containers.HSplit([
            self.display.get_top_view(),
            pt_containers.Window(height=1, char='-'), output,
            pt_containers.VSplit([input_field, time_field]), search_field
        ])

        # Floating menu for text completion
        completion_menu = CompletionsMenu(max_height=5, scroll_offset=1)
        body = pt_containers.FloatContainer(content=container,
                                            floats=[
                                                pt_containers.Float(
                                                    xcursor=True,
                                                    ycursor=True,
                                                    content=completion_menu)
                                            ])

        return body, input_field, time_field, output
示例#4
0
def normal_text_window(name=None,
                       lang=None,
                       lineno=False,
                       leading_space=False,
                       trailing_space=False,
                       width=None,
                       height=None):
    if name is None:
        name = buffers.DEFAULT_BUFFER
    bf_attrs = {
        'buffer_name': name,
        'lexer': style.get_lexer_by_lang(lang),
        'highlighters': [highlighters.SelectionHighlighter()]
    }

    input_processors = []
    if leading_space:
        input_processors.append(processors.ShowLeadingWhiteSpaceProcessor())
    if trailing_space:
        input_processors.append(processors.ShowTrailingWhiteSpaceProcessor())
    if input_processors:
        bf_attrs['input_processors'] = input_processors

    win_attrs = {}
    left_margins = []
    if lineno:
        left_margins.append(NumberredMargin(name))
    if left_margins:
        win_attrs['left_margins'] = left_margins

    if height is not None:
        win_attrs['height'] = height
    if width is not None:
        win_attrs['width'] = width

    content = controls.BufferControl(**bf_attrs)
    return containers.Window(content=content, **win_attrs)
示例#5
0
path_completer = completion.PathCompleter(expanduser=True)

buffer = Buffer(
    on_text_changed=on_text_changed,
    complete_while_typing=True,
    completer=path_completer,
    multiline=False,
)
header = controls.FormattedTextControl("Press C-d or C-c or C-g to quit")
buffer_control = controls.BufferControl(buffer=buffer)
content_display = controls.FormattedTextControl(text="hello world")
current_display = controls.FormattedTextControl(text="")

layout = Layout(
    containers.HSplit([
        containers.Window(header, height=1, style="reverse"),
        containers.FloatContainer(
            containers.HSplit([
                containers.Window(content=buffer_control, height=1),
                containers.Window(height=1, char="-", style="class:line"),
                containers.Window(content=current_display, height=1),
                containers.Window(height=1, char="-", style="class:line"),
                containers.Window(content=content_display),
            ]),
            floats=[
                containers.Float(
                    xcursor=True,
                    ycursor=True,
                    content=menus.CompletionsMenu(max_height=12,
                                                  scroll_offset=1),
                )
示例#6
0
    ],
    ignore_case=True,
)

top_text = "Press C-c or C-g to quit"
buffer = Buffer(
    on_text_changed=on_text_changed,
    complete_while_typing=True,
    completer=animal_completer,
)
header = controls.FormattedTextControl(top_text)
display = controls.FormattedTextControl(text="hello world")

layout = Layout(
    containers.HSplit([
        containers.Window(header, height=1, style="reverse"),
        containers.FloatContainer(
            containers.HSplit([
                containers.Window(content=controls.BufferControl(
                    buffer=buffer))
            ]),
            floats=[
                containers.Float(
                    xcursor=True,
                    ycursor=True,
                    content=menus.CompletionsMenu(max_height=16,
                                                  scroll_offset=1),
                )
            ],
        ),
        containers.Window(height=1, char="-", style="class:line"),
示例#7
0
文件: ui4.py 项目: lshenglin/dso-test
    def create(self):
        self.buffer = pt.buffer.Buffer(
            accept_action=pt.buffer.AcceptAction(handler=self.handle_command),
            history=self.history,
            completer=CommandCompleter(self.valid_commands),
            on_cursor_position_changed=self.handle_help_bar,
        )
        self.buffers = {'PROMPT': self.buffer}
        for i in range(10):
            self.buffers['FN%d' % i] = pt.buffer.Buffer(
                accept_action=pt.buffer.AcceptAction(handler=self.save_state),
                history=None,
                completer=None)

        divider_line = lambda: containers.Window(
            content=controls.FillControl('-', token=Token.Line),
            height=dimension.LayoutDimension.exact(1))

        buffer_sublayout = containers.VSplit([
            # containers.Window(content=controls.TokenListControl(get_tokens=lambda cli : ([Token.Red, u'> ']))),
            self.text_block(lambda x: [(Token.Prompt, u">> ")],
                            dont_extend_width=True),
            containers.Window(
                content=controls.BufferControl(buffer_name='PROMPT'),
                dont_extend_height=True),
        ])

        self.main_layout = containers.HSplit([
            divider_line(),
            self.text_block(self.test_mode),
            self.text_block(self.test_settings),
            divider_line(),
            self.text_block(self.turn_table_settings),
            divider_line(),
            self.text_block(self.save_location_setting),
            divider_line(),
            buffer_sublayout,
            containers.Window(content=controls.TokenListControl(
                get_tokens=self.status_bar)),
        ])

        self.save_load_layout = containers.HSplit(
            [divider_line()] + [self.file_selection(i) for i in range(10)] + [
                divider_line(),
                containers.Window(content=controls.TokenListControl(
                    get_tokens=self.status_bar)),
            ])
        self.update_state_name_display()

        loop = pt.shortcuts.create_eventloop()
        application = pt.application.Application(
            layout=self.main_layout,
            buffers=self.buffers,
            style=self.style,
            initial_focussed_buffer='PROMPT',
            key_bindings_registry=registry)
        cli = pt.interface.CommandLineInterface(application=application,
                                                eventloop=loop)
        cli.state = "MAIN"
        self.init_key_bindings()
        cli.run()
示例#8
0
文件: ui4.py 项目: lshenglin/dso-test
 def text_block(source, **kwargs):
     return containers.Window(
         content=controls.TokenListControl(get_tokens=source),
         dont_extend_height=True,
         **kwargs)
示例#9
0
def vertical_line(min_height=None, max_height=None, char=' '):
    width = dim(exact=1)
    height = dim(min_=min_height, max_=max_height)
    content = controls.FillControl(char, token=style.Line)
    return containers.Window(width=width, height=height, content=content)
示例#10
0
def horizontal_line(min_width=None, max_width=None, char=' '):
    height = dim(exact=1)
    width = dim(min_=min_width, max_=max_width)
    content = controls.FillControl(char, token=style.Line)
    return containers.Window(width=width, height=height, content=content)
示例#11
0

def on_text_changed(buf):
    global display
    if buf.text != display.text:
        display.text = buf.text


top_text = "Press C-c to quit"
buffer = Buffer(on_text_changed=on_text_changed)
header = controls.FormattedTextControl(top_text)
display = controls.FormattedTextControl(text="hello world")

layout = Layout(
    containers.HSplit([
        containers.Window(header, height=1, style="reverse"),
        containers.Window(content=controls.BufferControl(buffer=buffer)),
        containers.Window(content=display),
    ]))

kb = KeyBindings()


@kb.add("c-c")
def exit_(event):
    event.app.exit()


app = Application(layout=layout, full_screen=True, key_bindings=kb)
app.run()