Example #1
0
        def get_tokens(cli):
            _, python_buffer = current_python_buffer(cli, settings)
            if not python_buffer:
                return []

            TB = token
            result = []
            append = result.append

            append((TB, ' '))
            result.extend(get_inputmode_tokens(TB, key_bindings_manager, cli))
            append((TB, '  '))

            # Position in history.
            append((TB, '%i/%i ' % (python_buffer.working_index + 1,
                                    len(python_buffer._working_lines))))

            # Shortcuts.
            if not key_bindings_manager.enable_vi_mode and cli.focus_stack.current == 'search':
                append((TB, '[Ctrl-G] Cancel search [Enter] Go to this position.'))
            elif bool(cli.current_buffer.selection_state) and not key_bindings_manager.enable_vi_mode:
                # Emacs cut/copy keys.
                append((TB, '[Ctrl-W] Cut [Meta-W] Copy [Ctrl-Y] Paste [Ctrl-G] Cancel'))
            else:
                append((TB, '  '))

                if settings.paste_mode:
                    append((TB.On, '[F6] Paste mode (on)   '))
                else:
                    append((TB.Off, '[F6] Paste mode (off)  '))

                if python_buffer.is_multiline:
                    append((TB, ' [Meta+Enter] Execute'))

            return result
Example #2
0
    def close_current_python_buffer(self):
        name, _ = current_python_buffer(self.cli, self.settings)

        if name:
            python_buffers_left = len([b for b in self.cli.buffers if b.startswith('python-')])

            if python_buffers_left > 1:
                focus_next_buffer(self.cli, name_filter=lambda name: name.startswith('python-'))
                del self.cli.buffers[name]
                self._update_layout()
            else:
                self.cli.set_exit()
Example #3
0
    def close_current_python_buffer(self):
        name, _ = current_python_buffer(self.cli, self.settings)

        if name:
            python_buffers_left = len(
                [b for b in self.cli.buffers if b.startswith('python-')])

            if python_buffers_left > 1:
                focus_next_buffer(
                    self.cli,
                    name_filter=lambda name: name.startswith('python-'))
                del self.cli.buffers[name]
                self._update_layout()
            else:
                self.cli.set_exit()
Example #4
0
        def get_tokens(cli):
            python_buffer_names = sorted([b for b in cli.buffers.keys() if b.startswith('python-')])

            current_name, _ = current_python_buffer(cli, settings)

            result = []
            append = result.append

            append((Token.TabBar, ' '))
            for b in python_buffer_names:
                if b == current_name:
                    append((Token.TabBar.Tab.Active, ' %s ' % b))
                else:
                    append((Token.TabBar.Tab, ' %s ' % b))
                append((Token.TabBar, ' '))

            return result
Example #5
0
        def get_tokens(cli):
            python_buffer_names = sorted(
                [b for b in cli.buffers.keys() if b.startswith('python-')])

            current_name, _ = current_python_buffer(cli, settings)

            result = []
            append = result.append

            append((Token.TabBar, ' '))
            for b in python_buffer_names:
                if b == current_name:
                    append((Token.TabBar.Tab.Active, ' %s ' % b))
                else:
                    append((Token.TabBar.Tab, ' %s ' % b))
                append((Token.TabBar, ' '))

            return result
Example #6
0
        def get_tokens(cli):
            _, python_buffer = current_python_buffer(cli, settings)
            if not python_buffer:
                return []

            TB = token
            result = []
            append = result.append

            append((TB, ' '))
            result.extend(get_inputmode_tokens(TB, key_bindings_manager, cli))
            append((TB, '  '))

            # Position in history.
            append((TB, '%i/%i ' % (python_buffer.working_index + 1,
                                    len(python_buffer._working_lines))))

            # Shortcuts.
            if not key_bindings_manager.enable_vi_mode and cli.focus_stack.current == 'search':
                append((TB,
                        '[Ctrl-G] Cancel search [Enter] Go to this position.'))
            elif bool(cli.current_buffer.selection_state
                      ) and not key_bindings_manager.enable_vi_mode:
                # Emacs cut/copy keys.
                append((
                    TB,
                    '[Ctrl-W] Cut [Meta-W] Copy [Ctrl-Y] Paste [Ctrl-G] Cancel'
                ))
            else:
                append((TB, '  '))

                if settings.paste_mode:
                    append((TB.On, '[F6] Paste mode (on)   '))
                else:
                    append((TB.Off, '[F6] Paste mode (off)  '))

                if python_buffer.is_multiline:
                    append((TB, ' [Meta+Enter] Execute'))

            return result
Example #7
0
        def get_tokens(cli):
            result = []
            append = result.append
            Signature = Token.Toolbar.Signature

            _, python_buffer = current_python_buffer(cli, settings)

            if python_buffer.signatures:
                sig = python_buffer.signatures[0]  # Always take the first one.

                append((Signature, ' '))
                try:
                    append((Signature, sig.full_name))
                except IndexError:
                    # Workaround for #37: https://github.com/jonathanslenders/python-prompt-toolkit/issues/37
                    # See also: https://github.com/davidhalter/jedi/issues/490
                    return []

                append((Signature.Operator, '('))

                for i, p in enumerate(sig.params):
                    if i == sig.index:
                        # Note: we use `_Param.description` instead of
                        #       `_Param.name`, that way we also get the '*' before args.
                        append((Signature.CurrentName, str(p.description)))
                    else:
                        append((Signature, str(p.description)))
                    append((Signature.Operator, ', '))

                if sig.params:
                    # Pop last comma
                    result.pop()

                append((Signature.Operator, ')'))
                append((Signature, ' '))
            return result
Example #8
0
        def get_tokens(cli):
            result = []
            append = result.append
            Signature = Token.Toolbar.Signature

            _, python_buffer = current_python_buffer(cli, settings)

            if python_buffer.signatures:
                sig = python_buffer.signatures[0]  # Always take the first one.

                append((Signature, ' '))
                try:
                    append((Signature, sig.full_name))
                except IndexError:
                    # Workaround for #37: https://github.com/jonathanslenders/python-prompt-toolkit/issues/37
                    # See also: https://github.com/davidhalter/jedi/issues/490
                    return []

                append((Signature.Operator, '('))

                for i, p in enumerate(sig.params):
                    if i == sig.index:
                        # Note: we use `_Param.description` instead of
                        #       `_Param.name`, that way we also get the '*' before args.
                        append((Signature.CurrentName, str(p.description)))
                    else:
                        append((Signature, str(p.description)))
                    append((Signature.Operator, ', '))

                if sig.params:
                    # Pop last comma
                    result.pop()

                append((Signature.Operator, ')'))
                append((Signature, ' '))
            return result
Example #9
0
 def __call__(self, cli):
     name, buffer_instance = current_python_buffer(cli, self.settings)
     return name == self.buffer_name
Example #10
0
 def __call__(self, cli):
     _, python_buffer = current_python_buffer(cli, self.settings)
     return python_buffer is not None and bool(python_buffer.signatures)
Example #11
0
 def __call__(self, cli):
     name, buffer_instance = current_python_buffer(cli, self.settings)
     return name == self.buffer_name
Example #12
0
 def __call__(self, cli):
     _, python_buffer = current_python_buffer(cli, self.settings)
     return python_buffer is not None and bool(python_buffer.signatures)