[Glade-users] Passing User defined data in signal handlers[through Glade defined widgets]

Ashwin Ramachandran wrote:
Hi All,

I am new to Glade and to this list. I am creating a new
application UI interface through glade[glade-2].

I have a couple of queries regarding passing application data in signal
handlers. The details of which are given below:

Query 1: Regarding passing user data in menu item signal handlers

a. I have an application where I create the menu items
through Glade. The menu editor gives me only a Handler
option, where I add the signal handler that needs to be called.
Apart from the signal handler call,   I also need to pass the user data[or
udata ]
as well, when this handler gets called. For eg:  I have a menu item of this
- ByteStream
- Enum
- Parameter
[Where ByteStream, Enum, Parameter are sub menuitems are under Add].
Each of the activations of ByteStream, Enum, Parameter call the same
signal handler [add_parameter]. I also need to pass a constant alongwith
this call
[for eg BYTESTREAM, ENUM, PARAMETER], to identify which menu item
was activated.

Is it possible to make this constant get passed using the signal handler
added through

For comparison sake, if I had to create the menuitems manually, I would 
had code like this:
$param_bytestream_menuitem->signal_connect( ACTIVATE, \&add_parameter,
$param_enum_menuitem->signal_connect( ACTIVATE, \&add_parameter, ENUM);

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

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 ...


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]