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...<div>
<br></div><div>pyqtWrapperType(name, (gui.QWidget,),{'spam':spam, 'yam': yam})</div><div><br></div><div>... or more generically....</div><div><br><div>gui.QWidget.__class__(name, (gui.QWidget,),{'spam':spam, 'yam': yam})</div>
</div><div><br></div><div><br></div><div>Thanks again,</div><div>Dan.</div><div><br><div class="gmail_quote">2011/9/9 Rafael Durán Castañeda <span dir="ltr"><<a href="mailto:rafadurancastaneda@gmail.com">rafadurancastaneda@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><u></u>
<div bgcolor="#ffffff" text="#000000">
I think you can do something like this:<br>
<br>
>>> import PyQt4.QtGui as gui<br>
>>> def factory(name):<br>
... def spam(): pass<br>
... def yam(): pass<br>
... return type(name, (gui.QWidget,),{'spam':spam, 'yam': yam})<br>
... <br>
>>> MyClass = factory('MyClass')<br>
>>> MyClass.__mro__<br>
(<class '__main__.MyClass'>, <class
'PyQt4.QtGui.QWidget'>, <class 'PyQt4.QtCore.QObject'>,
<type 'sip.wrapper'>, <class
'PyQt4.QtGui.QPaintDevice'>, <type 'sip.simplewrapper'>,
<type 'object'>)<div><div></div><div class="h5"><br>
<br>
On 08/09/11 23:33, Daniel Goertzen wrote:
</div></div><blockquote type="cite"><div><div></div><div class="h5">
<div><span style="font-family:arial,sans-serif">Does pyqt provide a way to override the
class name when deriving a QObject based class?</span></div>
<div>
<div><font face="arial, sans-serif"><br>
</font></div>
<div><font face="arial, sans-serif">An
example of why this is wanted:</font></div>
<div><font face="arial, sans-serif"><br>
</font></div>
<div><font face="arial, sans-serif">def
my_widget_class_factory(...):</font></div>
<div><font face="arial, sans-serif">
class temp(QWidget):</font></div>
<div><font face="arial, sans-serif">
...(dynamically generate class attributes and methods)</font></div>
<div><font face="arial, sans-serif">
return temp</font></div>
<div><font face="arial, sans-serif"><br>
</font></div>
<div><font face="arial, sans-serif">All
classes generated by the above function will come back with
className() as "temp". This causes headaches for Designer.</font></div>
</div>
<div><font face="arial, sans-serif"><br>
</font></div>
<div><font face="arial, sans-serif">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?)</font></div>
<div><font face="arial, sans-serif"><br>
</font></div>
<div><font face="arial, sans-serif">Thanks,</font></div>
<div><font face="arial, sans-serif">Dan.</font></div>
<div><font face="arial, sans-serif"><br>
</font></div>
</div></div><pre><fieldset></fieldset>
_______________________________________________
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></pre>
</blockquote>
<br>
</div>
<br>_______________________________________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><span style="border-collapse:collapse;font-family:arial, sans-serif"><font><font face="Verdana, Helvetica, Arial"><i>Daniel Goertzen<br>
Senior Software Engineer<br></i></font></font><font face="Calibri, Verdana, Helvetica, Arial">-- <br></font><font color="#0000FB" style="font-size:x-small"><font face="Verdana, Helvetica, Arial"><b>Network Integrity Systems<br>
</b></font></font><font face="Verdana, Helvetica, Arial"><font color="#FB0000" style="font-size:x-small">We Bring Security To Light™<br></font><br><font size="1">1937 Tate Blvd. SE</font><br><font size="1">Hickory, North Carolina 28602</font><br>
<font size="1"><br></font></font></span><font size="1"><span style="border-collapse:collapse;font-family:arial, sans-serif"><font face="Verdana, Helvetica, Arial">Phone: </font></span><span style="color:rgb(51, 51, 51);font-family:verdana, sans-serif">828.610.4596</span><span style="border-collapse:collapse;font-family:arial, sans-serif"><font face="Verdana, Helvetica, Arial"><br>
</font></span><span style="border-collapse:collapse;font-family:Verdana, Helvetica, Arial">Fax: 828.322.5294</span><span style="border-collapse:collapse;font-family:arial, sans-serif"><font face="Verdana, Helvetica, Arial"><br>
</font></span></font><div><span style="border-collapse:collapse;font-family:arial, sans-serif"><font face="Verdana, Helvetica, Arial" style="font-size:x-small"><br><font color="#0000FF"><a href="http://www.networkintegritysystems.com/" style="color:rgb(64, 100, 128)" target="_blank">http://www.networkintegritysystems.com/</a><br>
</font><br>Visit our Blog at:<br><font color="#0000FF"><a href="http://sipreasy.blogspot.com/" style="color:rgb(64, 100, 128)" target="_blank">http://sipreasy.blogspot.com/</a></font></font></span><div><font face="Verdana, Helvetica, Arial" size="1"><span style="border-collapse:collapse"><br>
</span></font><br></div></div><br>
</div>