-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Martin Gadbois wrote:
| Hello,
|
| Being a Newbie, I was surprised to see that I could not do something
| like that for my brand new
| gnome2 applet (see >>> enphasis):
|
| class MyApplet:
| ~ def __init__(self,applet):
| ~ propxml="""
| <popup name="button3">
| <menuitem name="Item 1" verb="Props" label="_Preferences..."
| pixtype="stock"
| pixname="gtk-properties"/>
| </popup>
| """
|
| ~ self.cfg = { }
| ~ self.get_config()
| |>> applet.setup_menu(propxml,[ ("Props",MyApplet.properties) ],self)
| ~ applet.add(frame)
| ~ applet.show_all()
| |>> def properties(widget,self):
| ~ # Access self.cfg here, display a property box
| ~ pass
| ~ def get_config(self):
| ~ pass # Do something, get config from gconf
|
| def applet_factory(applet):
| ~ MyApplet(applet)
|
| No, in fact, when I successfully got it to work, the arguments passed to
| the callback properties()
| were a BonoboUIComponent instance and the verb being called ("Props"). I
| assumed the 3rd arg to
| setup_menu() would be passed to the callback as 'data'.
|
| I use gnome-python & pyGtk 2.0.0.
|
| My questions:
| 1) What is the 3rd argument of setup_menu() (gnome-python says it is
| extra_args) and how is it used?
| 2) Can callbacks be methods of a class?
| 2b) How to pass 'self' to a callback?
| 3) Should I just use procedural functions?
For the record:
1) It is user-data. It does behave differently when None. When none, the callback
requires 2 args
(widget,verb). If not None, the callback requires (widget,verb,user_data)
2) Yes. use 'self.method' in the verbs
2b) Use self.method, not Class.method.
3) No. member class works well.
Working example:
class MyApplet:
~ def __init__(self,applet):
~ propxml="""
~ <popup name="button3">
~ <menuitem name="Item 1" verb="Props" label="_Preferences..."
~ pixtype="stock"
~ pixname="gtk-properties"/>
~ </popup>
~ """
~ self.cfg = { }
~ self.get_config()
~ applet.setup_menu(propxml,[ ("Props",self.properties) ],"Extra")
~ applet.add(frame)
~ applet.show_all()
~ def properties(widget,extra):
~ # Access self.cfg here, display a property box
# here, extra == "Extra"
~ pass
~ def get_config(self):
~ pass # Do something, get config from gconf
def applet_factory(applet):
~ MyApplet(applet)
- --
Martin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/gcVx9Y3/iTTCEDkRAlcXAJ9p2YWWG5aUsfWlFjp4znZp0BXquwCgyDvC
Ax5I43Ty4x+lsX8JrNQBFZM=
=il45
-----END PGP SIGNATURE-----
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/