Constructor of object

Thinker thinker at branda.to
Wed Mar 14 21:08:40 CET 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

inline wrote:

> I know it, but i don't want call constructor of parent class - I
> use PyGTK and want to load window from glade file and assign it to
> object, parented gtk.Window:

> #!/usr/bin/env python

> import gtk import gtk.glade

> class HelloWindow (gtk.Window): def __init__(self): xml =
> gtk.glade.XML("hello.glade") xml.signal_autoconnect(self) self =
> xml.get_widget("window")

> window = HelloWindow() window.connect("delete_event",
> gtk.main_quit) window.show_all() gtk.main()

Why don't you just define HelloWindow as a function? It is more simple.
If you want HelloWindow() to return the object from glade, you can
make HelloWindow as a function or
a class with __new__() method, suggested by Sylvain's, that return a
object from glade.

for ex:
def HelloWindow():
......
return xml.get_widget("window")
pass

or
class HelloWindow:
def __init__(self):
pass
def __new__(clz, *args):
........
return xml.get_widget("window")

- --
Thinker Li - thinker at branda.to thinker.li at gmail.com
http://heaven.branda.to/~thinker/GinGin_CGI.py
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF+FZH1LDUVnWfY8gRAv/yAKDz6VWmIJkLmQ72UwZLBF/hrHUPPgCePRBq
jSx5PySyDc/pW3SOqZEFM/I=
=T746
-----END PGP SIGNATURE-----




More information about the Python-list mailing list