##// END OF EJS Templates
Merge branch 'fix-del-method-exit-test' of http://github.com/takowl/ipython into takowl-fix-del-method-exit-test...
Merge branch 'fix-del-method-exit-test' of http://github.com/takowl/ipython into takowl-fix-del-method-exit-test Fix errors with __del__ methods being called on exit. This branch reintroduces a recent fix that got accidentally overwritten, as well as adding a more stringent form of the test so that we don't miss it again in the future (the old test only printed a message but didn't fail, so it was easy to miss). Closes gh-172 (pull request).

File last commit:

r2994:e3a069f3
r3178:5c6a3477 merge
Show More
util.py
87 lines | 3.1 KiB | text/x-python | PythonLexer
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643 """ Defines miscellaneous Qt-related helper classes and functions.
"""
# System library imports.
Fernando Perez
Centralize Qt font selection into a generic utility....
r2986 from PyQt4 import QtCore, QtGui
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643
# IPython imports.
from IPython.utils.traitlets import HasTraits
epatters
Initial checkin of (not yet working) matplotlib payload backend and associated machinery.
r2756 #-----------------------------------------------------------------------------
# Metaclasses
#-----------------------------------------------------------------------------
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643
MetaHasTraits = type(HasTraits)
MetaQObject = type(QtCore.QObject)
Brian Granger
Merge branch 'epatters-qtfrontend' into kernelmanager...
r2726 # You can switch the order of the parents here and it doesn't seem to matter.
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643 class MetaQObjectHasTraits(MetaQObject, MetaHasTraits):
epatters
* Added Cut support to ConsoleWidget....
r2990 """ A metaclass that inherits from the metaclasses of HasTraits and QObject.
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643
epatters
* Added Cut support to ConsoleWidget....
r2990 Using this metaclass allows a class to inherit from both HasTraits and
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994 QObject. Using SuperQObject instead of QObject is highly recommended. See
QtKernelManager for an example.
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643 """
epatters
* Added 'req_port' option to 'launch_kernel' and the kernel entry point....
r2702 pass
Fernando Perez
Centralize Qt font selection into a generic utility....
r2986
epatters
* Added Cut support to ConsoleWidget....
r2990 #-----------------------------------------------------------------------------
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994 # Classes
#-----------------------------------------------------------------------------
class SuperQObject(QtCore.QObject):
""" Permits the use of super() in class hierarchies that contain QObject.
Unlike QObject, SuperQObject does not accept a QObject parent. If it did,
super could not be emulated properly (all other classes in the heierarchy
would have to accept the parent argument--they don't, of course, because
they don't inherit QObject.)
This class is primarily useful for attaching signals to existing non-Qt
classes. See QtKernelManager for an example.
"""
def __new__(cls, *args, **kw):
# We initialize QObject as early as possible. Without this, Qt complains
# if SuperQObject is not the first class in the super class list.
inst = QtCore.QObject.__new__(cls)
QtCore.QObject.__init__(inst)
return inst
def __init__(self, *args, **kw):
# Emulate super by calling the next method in the MRO, if there is one.
mro = self.__class__.mro()
for qt_class in QtCore.QObject.mro():
mro.remove(qt_class)
next_index = mro.index(SuperQObject) + 1
if next_index < len(mro):
mro[next_index].__init__(self, *args, **kw)
#-----------------------------------------------------------------------------
epatters
* Added Cut support to ConsoleWidget....
r2990 # Functions
#-----------------------------------------------------------------------------
Fernando Perez
Centralize Qt font selection into a generic utility....
r2986
def get_font(family, fallback=None):
"""Return a font of the requested family, using fallback as alternative.
If a fallback is provided, it is used in case the requested family isn't
found. If no fallback is given, no alternative is chosen and Qt's internal
algorithms may automatically choose a fallback font.
Parameters
----------
family : str
A font name.
fallback : str
A font name.
Returns
-------
font : QFont object
"""
font = QtGui.QFont(family)
# Check whether we got what we wanted using QFontInfo, since exactMatch()
# is overly strict and returns false in too many cases.
font_info = QtGui.QFontInfo(font)
if fallback is not None and font_info.family() != family:
font = QtGui.QFont(fallback)
return font