##// END OF EJS Templates
Merge pull request #1548 from minrk/ar_sugar...
Merge pull request #1548 from minrk/ar_sugar Add sugar methods/properties to AsyncResult that are generically useful: * `ar.wall_time` = received - submitted * `ar.serial_time` = sum of serial computation time * `ar.elapsed` = time since submission (wall_time if done) * `ar.progress` = (int) number of sub-tasks that have completed * `len(ar)` = # of tasks * `ar.wait_interactive()`: prints progress These are simple methods derived from the metadata/timestamps already created. But I've been persuaded by @wesm's practice of including simple methods that do useful (and/or cool) things. This also required/revealed some minor fixes/cleanup to clear_output in some cases: * dedent base `core.displaypub.clear_output`, so it's actually defined in the class * clear_output publishes `'\r\b'`, so it will clear terminal-like frontends that don't understand full clear_output behavior. * `core.display.clear_output()` still works, even outside an IPython session. Added a new notebook that shows how to use these new methods and how to do simple animations/progress bars using `clear_output()`. Added `Client.spin_thread(interval)` / `stop_spin_thread()` for running spin in a background thread, to keep zmq queue clear. This can be used to ensure that timing information is as accurate as possible (at the cost of having a background thread active).

File last commit:

r4872:34c10438
r6485:e0b43119 merge
Show More
qt.py
66 lines | 2.1 KiB | text/x-python | PythonLexer
Evan Patterson
Paved the way for PySide support....
r3304 """ A Qt API selector that can be used to switch between PyQt and PySide.
MinRK
reorder qt support in kernel...
r4191
This uses the ETS 4.0 selection pattern of:
PySide first, PyQt with API v2. second.
Do not use this if you need PyQt with the old QString/QVariant API.
Evan Patterson
Paved the way for PySide support....
r3304 """
import os
epatters
Clean up in Qt API switcher.
r3306 # Available APIs.
QT_API_PYQT = 'pyqt'
QT_API_PYSIDE = 'pyside'
epatters
Smarter Qt binding selection when environment variable is not specified.
r3927 def prepare_pyqt4():
epatters
Fixed PySide incompatibility with QVariant....
r3364 # For PySide compatibility, use the new-style string API that automatically
# converts QStrings to Unicode Python strings. Also, automatically unpack
# QVariants to their underlying objects.
Evan Patterson
Paved the way for PySide support....
r3304 import sip
sip.setapi('QString', 2)
epatters
Fixed PySide incompatibility with QVariant....
r3364 sip.setapi('QVariant', 2)
Evan Patterson
Paved the way for PySide support....
r3304
epatters
Smarter Qt binding selection when environment variable is not specified.
r3927 # Select Qt binding, using the QT_API environment variable if available.
QT_API = os.environ.get('QT_API')
if QT_API is None:
try:
import PySide
MinRK
version check Qt bindings in external.qt...
r4677 if PySide.__version__ < '1.0.3':
# old PySide, fallback on PyQt
raise ImportError
epatters
Smarter Qt binding selection when environment variable is not specified.
r3927 QT_API = QT_API_PYSIDE
except ImportError:
try:
prepare_pyqt4()
import PyQt4
MinRK
version check Qt bindings in external.qt...
r4677 from PyQt4 import QtCore
if QtCore.PYQT_VERSION_STR < '4.7':
# PyQt 4.6 has issues with null strings returning as None
raise ImportError
epatters
Smarter Qt binding selection when environment variable is not specified.
r3927 QT_API = QT_API_PYQT
except ImportError:
MinRK
version check Qt bindings in external.qt...
r4677 raise ImportError('Cannot import PySide >= 1.0.3 or PyQt4 >= 4.7')
Bernardo B. Marques
remove all trailling spaces
r4872
epatters
Smarter Qt binding selection when environment variable is not specified.
r3927 elif QT_API == QT_API_PYQT:
# Note: This must be called *before* PyQt4 is imported.
prepare_pyqt4()
# Now peform the imports.
if QT_API == QT_API_PYQT:
Evan Patterson
Paved the way for PySide support....
r3304 from PyQt4 import QtCore, QtGui, QtSvg
MinRK
version check Qt bindings in external.qt...
r4677 if QtCore.PYQT_VERSION_STR < '4.7':
raise ImportError("IPython requires PyQt4 >= 4.7, found %s"%QtCore.PYQT_VERSION_STR)
Evan Patterson
Paved the way for PySide support....
r3304
# Alias PyQt-specific functions for PySide compatibility.
QtCore.Signal = QtCore.pyqtSignal
QtCore.Slot = QtCore.pyqtSlot
epatters
Clean up in Qt API switcher.
r3306 elif QT_API == QT_API_PYSIDE:
MinRK
version check Qt bindings in external.qt...
r4677 import PySide
if PySide.__version__ < '1.0.3':
raise ImportError("IPython requires PySide >= 1.0.3, found %s"%PySide.__version__)
Evan Patterson
Paved the way for PySide support....
r3304 from PySide import QtCore, QtGui, QtSvg
epatters
Clean up in Qt API switcher.
r3306
else:
Bernardo B. Marques
remove all trailling spaces
r4872 raise RuntimeError('Invalid Qt API %r, valid values are: %r or %r' %
epatters
Improved error message for Qt API switcher.
r3334 (QT_API, QT_API_PYQT, QT_API_PYSIDE))