本文整理汇总了Python中prompt_toolkit.CommandLineInterface.set_exit方法的典型用法代码示例。如果您正苦于以下问题:Python CommandLineInterface.set_exit方法的具体用法?Python CommandLineInterface.set_exit怎么用?Python CommandLineInterface.set_exit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit.CommandLineInterface
的用法示例。
在下文中一共展示了CommandLineInterface.set_exit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PythonCommandLineInterface
# 需要导入模块: from prompt_toolkit import CommandLineInterface [as 别名]
# 或者: from prompt_toolkit.CommandLineInterface import set_exit [as 别名]
#.........这里部分代码省略.........
# Never run multiple get-signature threads.
if self.get_signatures_thread_running:
return
self.get_signatures_thread_running = True
buffer = self.cli.current_buffer
document = buffer.document
def run():
script = get_jedi_script_from_document(document, self.get_locals(), self.get_globals())
# Show signatures in help text.
if script:
try:
signatures = script.call_signatures()
except ValueError:
# e.g. in case of an invalid \\x escape.
signatures = []
except Exception:
# Sometimes we still get an exception (TypeError), because
# of probably bugs in jedi. We can silence them.
# See: https://github.com/davidhalter/jedi/issues/492
signatures = []
else:
signatures = []
self.get_signatures_thread_running = False
# Set signatures and redraw if the text didn't change in the
# meantime. Otherwise request new signatures.
if buffer.text == document.text:
buffer.signatures = signatures
# Set docstring in docstring buffer.
if signatures:
string = signatures[0].docstring()
if not isinstance(string, six.text_type):
string = string.decode('utf-8')
self.cli.buffers['docstring'].reset(
initial_document=Document(string, cursor_position=0))
else:
self.cli.buffers['docstring'].reset()
self.cli.request_redraw()
else:
on_input_timeout()
self.cli.eventloop.run_in_executor(run)
self.cli.onInputTimeout += on_input_timeout
self.cli.onReset += self.key_bindings_manager.reset
self.add_new_python_buffer()
def _update_layout(self):
"""
Generate new layout.
(To be done when we add/remove buffers.)
"""
self.cli.layout = create_layout(
self.cli.buffers, self.settings, self.key_bindings_manager, self.python_prompt_control,
lexer=self._lexer,
extra_buffer_processors=self._extra_buffer_processors,
extra_sidebars=self._extra_sidebars)
def add_new_python_buffer(self):
# Create a new buffer.
buffer = self._create_buffer()
self.settings.buffer_index += 1
name = 'python-%i' % self.settings.buffer_index
# Insert and update layout.
self.cli.add_buffer(name, buffer, focus=True)
self._update_layout()
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()
def _create_buffer(self):
def is_buffer_multiline(document):
return (self.settings.paste_mode or
self.settings.currently_multiline or
document_is_multiline_python(document))
return PythonBuffer(
is_multiline=is_buffer_multiline,
tempfile_suffix='.py',
history=self.history,
completer=self.completer,
validator=self.validator)