GNOME Bugzilla – Bug 167603
gtk.show_about_dialog() not wrapped
Last modified: 2008-06-10 21:33:43 UTC
Seems worthwhile to track this one bugzilla: Could not write function show_about_dialog: varargs functions not supported Its just a utility wrapper, but it saves a lot of hassle.
Perhaps we can provide a similar function written in pure python? What did you end up doing in your application?
I ended up writing a python version of it: http://cvs.gnome.org/viewcvs/*checkout*/sabayon/admin-tool/aboutdialog.py
Created attachment 54324 [details] [review] Doesn't quite work Start of an implementation which doesn't really work yet... Issues still are: * When dialog appears, it is empty. * Trying to set a GStrv property results in >>> gtk.show_about_dialog (None, name="Foo", version="1.0", comments="Foo is a program for the GNOME Desktop which does Bar", copyright="2005 caillon", authors=["caillon"]) Parent is: (nil) Dialog is: (nil) No Dialog Have kwargs Parsing Property name: 'name' Setting property: name Parsing Property name: 'version' Setting property: version Parsing Property name: 'comments' Setting property: comments Parsing Property name: 'copyright' Setting property: copyright Parsing Property name: 'authors' __main__:1: Warning: gvalue.c:89: cannot initialize GValue with type `GStrv', the value has already been initialized as `GStrv' Setting property: authors
(Gah, the dialog was empty because I forgot to run gtk.main() from the python console).
Created attachment 54333 [details] [review] Working patch Okay, this works. I needed to remove the g_value_init () in _pyg_strv_to_gvalue () as other to_gvalue methods don't call it, and callers don't expect this to happen.
Created attachment 60884 [details] [review] Updated patch Only a few minor tweaks, and removes the already-committed portion of this patch.
Comment on attachment 60884 [details] [review] Updated patch [...] >+ if (!dialog) { >+ dialog = gtk_about_dialog_new (); >+ >+ g_object_ref (dialog); >+ gtk_object_sink (GTK_OBJECT (dialog)); >+ >+ g_signal_connect (dialog, "delete_event", G_CALLBACK (gtk_widget_hide_on_delete), NULL); On gtk+ sources I also found this code at this point: /* Close dialog on user response */ g_signal_connect (dialog, "response", G_CALLBACK (close_cb), NULL); >+ >+ if (kwargs) { >+ int pos = 0; >+ PyObject *py_prop_name; >+ PyObject *py_prop_value; >+ >+ while (PyDict_Next (kwargs, &pos, &py_prop_name, &py_prop_value)) { >+ GParamSpec *pspec; >+ const gchar *property_name; >+ GValue property_gvalue = { 0, }; >+ >+ property_name = PyString_AsString (py_prop_name); >+ >+ klass = G_OBJECT_CLASS (GTK_ABOUT_DIALOG_GET_CLASS(dialog)); >+ >+ pspec = g_object_class_find_property (klass, property_name); >+ if (!pspec) { >+ PyErr_Format(PyExc_TypeError, >+ "Gtk.AboutDialog doesn't support property `%s'", >+ property_name); >+ break; Error handling here is incorrect. If you break, the function continues to create the about dialog and returns None. But whenever one raises an exception NULL must be returned, after any necessary cleanup. >+ } >+ >+ g_value_init (&property_gvalue, G_PARAM_SPEC_VALUE_TYPE(pspec)); >+ if (pyg_param_gvalue_from_pyobject(&property_gvalue, py_prop_value) < 0) { >+ PyErr_Format(PyExc_TypeError, >+ "could not convert value for property `%s'", >+ property_name); >+ g_value_unset (&property_gvalue); >+ break; Same comment as above. >+ } >+ >+ g_object_set_property (G_OBJECT (dialog), property_name, &property_gvalue); >+ g_value_unset (&property_gvalue); >+ } >+ } [...]
Okay, will update this soon with a new patch (currently travelling).
Created attachment 63314 [details] [review] updated patch So, the missing bit that gcj pointed out is a brand new addition to GTK+ sources, and it relies on the private portion, so we can't easily duplicate its functionality. So, rather than attempt to do so, I'll just destroy the widget each time its closed instead of keeping a copy in memory. I don't believe this is a big deal anyway. (Note that I haven't actually tested with this patch yet.)
It seems that now you don't have a global variable pointing to the about dialog, so if the user does Help->About twice it gets two dialogs. BTW, shouldn't this be implemented in python (on gtk/__init__.py) instead?...
Correct. As I said, things moved around in GTK. So I can leak or be agressive in destruction as I am now.
To default owner. Hopefully someone can find time to merge this.
(In reply to comment #9) > Created an attachment (id=63314) [edit] > updated patch > > So, the missing bit that gcj pointed out is a brand new addition to GTK+ > sources, and it relies on the private portion, so we can't easily duplicate its > functionality. So, rather than attempt to do so, I'll just destroy the widget > each time its closed instead of keeping a copy in memory. I don't believe this > is a big deal anyway. > > (Note that I haven't actually tested with this patch yet.) > In general this looks good. It would be even easier to accept the patch if you could submit a test to make sure that it works. Remember, there's no need to test what the C function does, only the wrapper itself.
Created attachment 101674 [details] [review] Updated once again Only minor changes since the last one, for API changes.
Created attachment 101675 [details] testcase Just a quick python testcase
jdahlin I think we should push this one in trunk now.
Sure, let's commit it
I've fixed the indentation and 80 columns layout. Sending ChangeLog Sending gtk/gtk.override Transmitting file data .. Committed revision 2993.