##// END OF EJS Templates
BUG: Explicitly merge the __init__ and __new__ metaclass methods for MetaQObjectHasTraits. The MetaHasTraits code was not being executed previously.
Robert Kern -
Show More
@@ -1,11 +1,14 b''
1 1 """ Defines miscellaneous Qt-related helper classes and functions.
2 2 """
3 3
4 # Standard library imports.
5 import inspect
6
4 7 # System library imports.
5 8 from PyQt4 import QtCore, QtGui
6 9
7 10 # IPython imports.
8 from IPython.utils.traitlets import HasTraits
11 from IPython.utils.traitlets import HasTraits, TraitType
9 12
10 13 #-----------------------------------------------------------------------------
11 14 # Metaclasses
@@ -14,7 +17,6 b' from IPython.utils.traitlets import HasTraits'
14 17 MetaHasTraits = type(HasTraits)
15 18 MetaQObject = type(QtCore.QObject)
16 19
17 # You can switch the order of the parents here and it doesn't seem to matter.
18 20 class MetaQObjectHasTraits(MetaQObject, MetaHasTraits):
19 21 """ A metaclass that inherits from the metaclasses of HasTraits and QObject.
20 22
@@ -22,7 +24,24 b' class MetaQObjectHasTraits(MetaQObject, MetaHasTraits):'
22 24 QObject. Using SuperQObject instead of QObject is highly recommended. See
23 25 QtKernelManager for an example.
24 26 """
25 pass
27 def __new__(mcls, name, bases, classdict):
28 # FIXME: this duplicates the code from MetaHasTraits.
29 # I don't think a super() call will help me here.
30 for k,v in classdict.iteritems():
31 if isinstance(v, TraitType):
32 v.name = k
33 elif inspect.isclass(v):
34 if issubclass(v, TraitType):
35 vinst = v()
36 vinst.name = k
37 classdict[k] = vinst
38 cls = MetaQObject.__new__(mcls, name, bases, classdict)
39 return cls
40
41 def __init__(mcls, name, bases, classdict):
42 # Note: super() did not work, so we explicitly call these.
43 MetaQObject.__init__(mcls, name, bases, classdict)
44 MetaHasTraits.__init__(mcls, name, bases, classdict)
26 45
27 46 #-----------------------------------------------------------------------------
28 47 # Classes
General Comments 0
You need to be logged in to leave comments. Login now