<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body 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'>)<br>
<br>
On 08/09/11 23:33, Daniel Goertzen wrote:
<blockquote
cite="mid:CAJCf5RzmjCN+QQrOO-us7tRCr+cvp=LXUFaJMre-ZaF7aii10w@mail.gmail.com"
type="cite">
<div><span class="Apple-style-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 class="Apple-style-span" face="arial, sans-serif"><br>
</font></div>
<div><font class="Apple-style-span" face="arial, sans-serif">An
example of why this is wanted:</font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><br>
</font></div>
<div><font class="Apple-style-span" face="arial, sans-serif">def
my_widget_class_factory(...):</font></div>
<div><font class="Apple-style-span" face="arial, sans-serif">
class temp(QWidget):</font></div>
<div><font class="Apple-style-span" face="arial, sans-serif">
...(dynamically generate class attributes and methods)</font></div>
<div><font class="Apple-style-span" face="arial, sans-serif">
return temp</font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><br>
</font></div>
<div><font class="Apple-style-span" 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 class="Apple-style-span" face="arial, sans-serif"><br>
</font></div>
<div><font class="Apple-style-span" 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 class="Apple-style-span" face="arial, sans-serif"><br>
</font></div>
<div><font class="Apple-style-span" face="arial, sans-serif">Thanks,</font></div>
<div><font class="Apple-style-span" face="arial, sans-serif">Dan.</font></div>
<div><font class="Apple-style-span" face="arial, sans-serif"><br>
</font></div>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
PyQt mailing list <a class="moz-txt-link-abbreviated" href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a>
<a class="moz-txt-link-freetext" href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></pre>
</blockquote>
<br>
</body>
</html>