Re: [pygtk] ExtensionClass based pygtk
Thanks for this patch. I have applied it and added support for keyword arguments to a lot of the functions in the gtk.override file. I was able to run the examples/ide/browse.py example almost without modification (just adding `import ltihooks' to the top, as I was running it from the build directory, and changing the name of one variable), and it subclasses GtkObjects and uses keyword arguments. I think I have sorted out all the bugs related to the wrapper rescue code in the destructor, but I am not that happy with the code (according to the change log it is evil :). It would be nice if python provided a more general way of doing this sort of thing. I will put out another snapshot tarball when I have a few more things working. BTW, I switched the stable version of pygtk and gnome-python over to using the cvs automake, so now you can use an (almost) standard version of automake to build gnome-python from cvs. James. -- Email: [EMAIL PROTECTED] WWW: http://www.daa.com.au/~james/ On Fri, 31 Mar 2000, Toby D. Reeves wrote: > James, > > The ExtensionClass based pygtk looks great so far. I've been watching CVS > as you built it up and have been waiting for you to announce that it is > ready for folks to look at it. > > I've attached a CVS diff that make the generated code use > PyArg_ParseTupleAndKeywords instead of PyArg_ParseTuple. This allows > keywords to be used to override default arguments, like in the old pygtk. > My implemention is kind-of brute force. It could be changed to only use > ParseTupleAndKeywords for functions and methods that have been assigned > default argument values. > > The GtkItemFactory code in both the old and new pygtk has a refcount > problem. The attached python code demonstrates the bug. I have looked at > the gtk+ code and do not see a simple fix. Maybe someone else will. > Basically, gtk_item_factory_create_item() does not allow a GtkDestroyNotify > to be specified for the callback_data. > > I look forward to using the added capabilities of the new pygtk in a > reorg/rewrite of our hyperspectral code. > > I'm glad that you agreed that using ExtensionClass was a good idea. > > Later, > > Toby > - To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]
[pygtk] ExtensionClass based pygtk
James, The ExtensionClass based pygtk looks great so far. I've been watching CVS as you built it up and have been waiting for you to announce that it is ready for folks to look at it. I've attached a CVS diff that make the generated code use PyArg_ParseTupleAndKeywords instead of PyArg_ParseTuple. This allows keywords to be used to override default arguments, like in the old pygtk. My implemention is kind-of brute force. It could be changed to only use ParseTupleAndKeywords for functions and methods that have been assigned default argument values. The GtkItemFactory code in both the old and new pygtk has a refcount problem. The attached python code demonstrates the bug. I have looked at the gtk+ code and do not see a simple fix. Maybe someone else will. Basically, gtk_item_factory_create_item() does not allow a GtkDestroyNotify to be specified for the callback_data. I look forward to using the added capabilities of the new pygtk in a reorg/rewrite of our hyperspectral code. I'm glad that you agreed that using ExtensionClass was a good idea. Later, Toby Diff.out import sys import ltihooks from gtk import * import gtk class SuperButton(GtkButton): def __init__(self,args): GtkButton.__init__(self,args) self.msg='I am a super button' def __del__(self): print 'SuperButton.__del__' def itemf_cb(arg,w): if hasattr(w,'count'): w.count=w.count+1 else: w.count=1 print 'itemf_cb():', arg, w, w.count class TestWindow(GtkWindow): def __init__(self): GtkWindow.__init__(self) self.set_title('TestWindow') self.connect('delete_event', self.quit) box=GtkVBox() self.add(box) # BUG: GtkItemFactory.create_items() has no (at least not obvious) way to Py_DECREF the callback. # This one keeps TestWindow.__del__ from being called cb=self.itemf_cb # This one puts the problem somewhere else. #cb=itemf_cb self.itemf = GtkItemFactory(GtkMenuBar.get_type(), "", None) self.itemf.create_items([ ('/_File', None, None, 0, ''), ('/_File/_New', 'N', cb, 0, ''), ('/_File/sep1', None, None, 0, ''), ('/_File/E_xit','X',cb, 0, ''), ('/_Help', None, None, 0, ''), ('/_Help/_About', 'A', cb, 0, '') ]) self.menubar = self.itemf.get_widget('') self.menubar.show() hb=GtkHandleBox() hb.show() box.pack_start(hb, expand=FALSE) hb.add(self.menubar) lab=GtkLabel('Hello') lab.set_text('Hello') lab.show() box.pack_start_defaults(lab) but=SuperButton('Push 1') box.add(but) but.connect('clicked', self.pushed, ([1,2,3],'ok')) but.n=1 but=GtkButton('Push 2') box.pack_start(but,0,0) but.connect('clicked', self.pushed ) but.n=2 but=GtkToggleButton('Toggle') but.connect('toggled', self.toggled) box.pack_start(but,0,0) but=GtkButton('Quit') box.add(but) but.connect('clicked', self.quit) self.show_all() def quit(self,*args): print 'quit:', args self.hide() self.destroy() main_quit() def pushed(self,b, *args): print 'pushed:', b.get('GtkButton::label'), b, b.n, args, sys.getrefcount(b), sys.getrefcount(self) if hasattr(b,'msg'): print 'msg:',b.msg b.n=b.n+1 def toggled(self,b, *args): print 'toggled:', b, args def itemf_cb(self,arg,w): if hasattr(w,'count'): w.count=w.count+1 else: w.count=1 print 'TestWindow.itemf_cb():', self, arg, w, w.count def __del__(self): print 'TestWindow.__del__()' w=TestWindow() w.show_all() mainloop() print 'There are %d bogus references left for TestWindow instance' % (sys.getrefcount(w)-2)
[pygtk] ExtensionClass based pygtk
I have done a bit more work on ExtensionClass based pygtk, and have got to a stage where others may want to try it out. I put together a tarball for people who don't have CVS access, or don't want to use it. It is available at: ftp://ftp.daa.com.au/pub/james/python/pygtk-0.7.0-unstable-dont-use.tar.gz (the name is just so people don't complain too much when it breaks their system if they try to install it). To build it, do the following: ./configure --prefix=/usr # or whatever your python prefix is make I don't recommend installing it, as it is not complete and will probably not work on all setups. You can test it out from the build directory though. Pygtk uses libtool now, so to use it without installing it, you will either have to set up some symlinks for the shared libraries, or make your program import ltihooks before importing gtk. Ltihooks is a small set of import hooks that treats .la files as extensions, and resolves the real location of the shared library. The single wrapper stuff is working correctly now, so that can be tested out. Post your comments about the code to the list. James. -- Email: [EMAIL PROTECTED] WWW: http://www.daa.com.au/~james/ - To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]