Ricerca tra la vecchia roba

Bestemmiare contro Glade3

Posted: Gennaio 29th, 2008 | Author: | Filed under: Programmazione | Commenti disabilitati su Bestemmiare contro Glade3

Succede che qualcuno ti chieda di spiegargli un po’ come funzionano le GTK e allora per farti il figo gli fai vedere i programmi che ho completato con successo (niente di particolare, solo applicazioni montate con poche funzioni) e poi ti venga in mente di proporgli di scrivere un qualcosa che presupponga di passare un widget come user_data di una callback… adesso inizia l’ingiuria contro il mezzo informatico.

Dopo tipo 3 ore di seguito nel tentare di capire come sia possibile che non funzioni, scopro che quei pazzi dei programmatori di Glade, quando viene chiamata la funzione in risposta ad un segnale, la mandano swapped, cioé, se la funzione di callback è definita come

void callback_della_zoccola_bip_bip(GtkWidget* widget, gpointer user_data);

allora in realtà widget contiene user_data e viceversa… per conferma vi mando la mail che ho trovato che spiega il problema

 

	> Query 2: Regarding Passing user data in signal handlers
	> ------------------------------------------------------------------------------------ 
	> 
	> I have another  requirement in the application to pass user data alongwith
	> the signal handlers for other
	> Gtk widgets for eg: Toolbar widgets. [Similar
	> to the above one]. This data is in the form of constants.
	> I understand that the 'Object' portion under the Signals can be used for
	> this purpose.
	> But,  I am not clear as to how to use this portion and what type of values
	> to give in here.
	> For eg in my case, I need to pass constants alongwith the signal handler
	> call
	> 
	> Any help for the above two issues, will be highly appreciated.
	
	Hi Ashwin,
	you've just outlined one of the problems that have existed in glade/libglade
	for a long time, let me try to illustrate how it works and what we've done
	to address that.
	The way it works:
	Currently if you set the "object" string in the signal handler, libglade
	will use that to lookup the said "object" by name in the interface
	(i.e. the same widget that would be returned by glade_xml_get_widget () on
	that string would become your userdata)... but wait ! it gets even more confusing,
	signals in glade files that bear the "object" attribute are always connected
	with the SWAPPED flag, that means that the "object" will be passed to your
	callback as the _first_ argument and the actual object that emitted the signal
	in question will be passed as the user_data argument to the signal handler.
	One step to improve this:
	in glade3 we originally included a "lookup" checkbutton on the signal
	data and supplied support for this in libglade as part of a GObject support
	patch to libglade: http://bugzilla.gnome.org/show_bug.cgi?id=161903 .
	this approach; if ever applied to libglade (or the future gtk+ builder code)
	would allow us to specify a symbol name for the user_data argument, the
	builder code (i.e. libglade) would simply g_module_lookup() the symbol
	string provided and pass that address to the callback as user_data.
	Ideally it would probably be great to allow the user to specify enum/flag/int
	values to user_data as well, enums and flags would be difficult because they
	have to be typed.
	Discussion on improving this situation probably belongs on gtk-devel-list
	or on http://bugzilla.gnome.org/show_bug.cgi?id=172535 ...
	Cheers,
	-Tristan
	
che anche se del 2006, risolve il mio problema, ma non inficia l'amore che riverso nell'altissimo...

Comments are closed.