Re: galde & gtk question



On Tue, 2003-05-27 at 04:51, David M. Cook wrote:
On Mon, May 26, 2003 at 08:14:25AM -0400, Rajarshi Guha wrote:


Is there any easy way to add user data to a callback using Glade and
libglade (apart from setting individual callbacks by hand) ?

If the widget itself is passed, you could use the widget name as a key, if
that's what you need.

I know it sounds pretty hackish (and a waste of some memory), but one way
that comes to mind is to stick a label with some default text in a
nonvisible window and then use the label name in the "object" field.  Then
retrieve the text with get_text.

It would help to know why you need to pass the string.  If you need to act
based on some key value, It might make sense to have a different callback
for each widget, and have each callback call a function with the shared
functionality:


Basically I have several buttons that all have the same callback. All
the buttons require the same action except two for which some extra
stuff is required. 

I know I could write a seperate callback for those two but I thought
that since the extra stuff was minor I would just use one function -
laziness :)   

Anyway, in the end I got round it by using glade_get_widget_name() to
get the name of the button (that is the name of the element in the UI
file) and then take action depending on the name. 

I think this is cleaner than attaching data to an element (via
g_object_set_data()) by hand as I was doing before using libglade.

-------------------------------------------------------------------
Rajarshi Guha <rajarshi presidency com> <http://jijo.cjb.net>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
Did you hear that two rabbits escaped from the zoo and so far they have
only recaptured 116 of them?




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