##// END OF EJS Templates
Release 5.0.0b4...
Release 5.0.0b4 What's new since b3: Small delay since last beta release, sorry about that, a few reasons though: - We / I slowed down a bit on the beta release pace, there was a few bugs/issues/User interface annoyance that needed a new version of prompt_toolkit to be released, there was no reasons to make extra-beta without this new version released. - We backed-down on some changes on which we had a few disagrements (more below). - I got sick, and had to catch up with backlog. Anyway, Jonathan release prompt_toolkit 1.0.1 and 1.0.2, so even if you don't try this new beta, upgrading prompt_toolkit will fix some of your issues. == Move back `TerminalInteractiveShell` to it's old place. This is a bigger breaking change since 5.0b3, the `TerminalInteractiveshell` moved back from `IPython.terminal.ptshell` to `IPython.terminal.interactiveshell`, if you've updated your project recently to adapt to this change we're sorry, but despite the fact that the version pre 5.0 and post 5.0 are relatively different the cost of conditional import for project depending on us appeared to be too high. So it's now easier to migrate from 4.0 to 5.0 as the class have the same name, and same location == Option name and default changed. `TerminalInteractiveShell.display_completions_in_column` is now gone. It was not present on 4.x so no API breakage there, and is now replaced by `TerminalInteractiveShell.display_completions` and is a enum that gained a 3rd mode for the completer: `readlinelike` for those of you that regret readline. This give us more flexibility for further options. Would appreciate testing of this new layout from vi user. The two other mode now being `column` and `multicolumn`. By popular request, `multicolumn` is not the default value for the previous option. == bug fixed: - quit/exit broken in ipdb - Copy/Past broken on windowm - Unicode broken on windows - function signature garbled when using `object?` - issue with paging text with `?` - completer could get stuck. See the complete git log for more informations.

File last commit:

r21934:c0fffd17
r22560:1b487f7a
Show More
tk.py
93 lines | 3.6 KiB | text/x-python | PythonLexer
# Code borrowed from ptpython
# https://github.com/jonathanslenders/ptpython/blob/86b71a89626114b18898a0af463978bdb32eeb70/ptpython/eventloop.py
# Copyright (c) 2015, Jonathan Slenders
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# * Neither the name of the {organization} nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
Wrapper around the eventloop that gives some time to the Tkinter GUI to process
events when it's loaded and while we are waiting for input at the REPL. This
way we don't block the UI of for instance ``turtle`` and other Tk libraries.
(Normally Tkinter registeres it's callbacks in ``PyOS_InputHook`` to integrate
in readline. ``prompt-toolkit`` doesn't understand that input hook, but this
will fix it for Tk.)
"""
import time
import _tkinter
try:
import tkinter
except ImportError:
import Tkinter as tkinter # Python 2
def inputhook(inputhook_context):
"""
Inputhook for Tk.
Run the Tk eventloop until prompt-toolkit needs to process the next input.
"""
# Get the current TK application.
root = tkinter._default_root
def wait_using_filehandler():
"""
Run the TK eventloop until the file handler that we got from the
inputhook becomes readable.
"""
# Add a handler that sets the stop flag when `prompt-toolkit` has input
# to process.
stop = [False]
def done(*a):
stop[0] = True
root.createfilehandler(inputhook_context.fileno(), _tkinter.READABLE, done)
# Run the TK event loop as long as we don't receive input.
while root.dooneevent(_tkinter.ALL_EVENTS):
if stop[0]:
break
root.deletefilehandler(inputhook_context.fileno())
def wait_using_polling():
"""
Windows TK doesn't support 'createfilehandler'.
So, run the TK eventloop and poll until input is ready.
"""
while not inputhook_context.input_is_ready():
while root.dooneevent(_tkinter.ALL_EVENTS | _tkinter.DONT_WAIT):
pass
# Sleep to make the CPU idle, but not too long, so that the UI
# stays responsive.
time.sleep(.01)
if root is not None:
if hasattr(root, 'createfilehandler'):
wait_using_filehandler()
else:
wait_using_polling()