Re: nameless instances of objects



I am positive my question wasn't phrased all that well but thanks for
your helpful answer.. and while I don't have a full grip on signals and
such as yet.. I know vaguely how they work.. and I know they don't work
like in java where you specifically attach them to something.

So I have a toolbar, and I will create buttons on it dynamically during
program operation. I have 1 signal they all use (what it does depends on
the data the signal passes.)

But when I do:
widget = gtk_button_new(...);
I won't know the widget name.. are you telling me that I don't need to
give it a unique name? That I can reuse the same name for each button I
create and add?

So I end up with something like:

button = gtk_button_new(); 
g_signal_connect (G_OBJECT (button), "button_press_event",
                  G_CALLBACK (button_pressed), "UniqueInfo");

In between those 2 lines (for an explicit button) I have about 13 lines
more code, involving alignment objects, images, etc.. can that stuff
also be used generically without names?

Hope this also makes sense.. and better asks what I want to ask :)

On Wed, 2002-12-11 at 21:01, Tristan Van Berkom wrote:
I was wondering if it was possible to namelessly generate instances of
'objects' in Gtk.

      I think that widget names are only for
theeming purposes (or at least thats
all I've used them for).

If I can create un-named objects/widgets/buttons how do I go about
attaching signals to them? As obviously each new button would need to
have a signal attached to it relating to the purpose it was created for.

      You dont attach signals to widgets;
widgets come with signals. if you want to connect a handler
to a signal emitted by that widget; all you need is the
address (returned by g_object_new(G_TYPE...)).

      if you add the widgets to a container implementation
(i.e. A window) than you dont really need to worry about
freeing them. (they become the property of the container
unless you hold an explicit reference on them).

so basicly you want to:

widget = gtk_???_new(...);
g_signal_connect(... widget ... handler ...);
gtk_container_add(GTK_CONTAINER(container), widget);

if you want to remove that widget from the 
container before the container is destroyed you'll
need to hold on to its address.


Cheers,
                      -Tristan
-- 
                Azrael

           ("\''/").___..--'''"-._          
           `0_ O  )   `-.  (     ).`-.__.`) 
           (_Y_.)'  ._   )  `._ `. ``-..-'  
         _..`--'_..-_/  /--'_.' .'          
        ((i).-''  ((i).'  (((.-'         
   
Of all God's creatures there is only one that cannot be made the slave
of the lash. That one is the cat. If man could be crossed with a cat it
would improve man, but it would deteriorate the cat. 

ICQ#52944566




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