Thank you Rafeal, I forgot about that usage of metaclasses. It certainly cleans things up for me. One thing of note is that the metaclass of QWidget is not 'type', but 'pyqtWrapperType'. So the invocation should be...
pyqtWrapperType(name, (gui.QWidget,),{'spam':spam, 'yam': yam}) ... or more generically.... gui.QWidget.__class__(name, (gui.QWidget,),{'spam':spam, 'yam': yam}) Thanks again, Dan. 2011/9/9 Rafael Durán Castañeda <rafadurancastan...@gmail.com> > ** > I think you can do something like this: > > >>> import PyQt4.QtGui as gui > >>> def factory(name): > ... def spam(): pass > ... def yam(): pass > ... return type(name, (gui.QWidget,),{'spam':spam, 'yam': yam}) > ... > >>> MyClass = factory('MyClass') > >>> MyClass.__mro__ > (<class '__main__.MyClass'>, <class 'PyQt4.QtGui.QWidget'>, <class > 'PyQt4.QtCore.QObject'>, <type 'sip.wrapper'>, <class > 'PyQt4.QtGui.QPaintDevice'>, <type 'sip.simplewrapper'>, <type 'object'>) > > > On 08/09/11 23:33, Daniel Goertzen wrote: > > Does pyqt provide a way to override the class name when deriving a QObject > based class? > > An example of why this is wanted: > > def my_widget_class_factory(...): > class temp(QWidget): > ...(dynamically generate class attributes and methods) > return temp > > All classes generated by the above function will come back with > className() as "temp". This causes headaches for Designer. > > I know I can add a metaclass to mangle the class name, but I was > wondering there was an easier way (ie, does QObject's metaclass provided a > way to rename the class?) > > Thanks, > Dan. > > > _______________________________________________ > PyQt mailing list > PyQt@riverbankcomputing.comhttp://www.riverbankcomputing.com/mailman/listinfo/pyqt > > > > _______________________________________________ > PyQt mailing list PyQt@riverbankcomputing.com > http://www.riverbankcomputing.com/mailman/listinfo/pyqt > -- *Daniel Goertzen Senior Software Engineer *-- *Network Integrity Systems *We Bring Security To Light™ 1937 Tate Blvd. SE Hickory, North Carolina 28602 Phone: 828.610.4596 Fax: 828.322.5294 http://www.networkintegritysystems.com/ Visit our Blog at: http://sipreasy.blogspot.com/
_______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt