Re: [gtk-list] Re: which way is better?



Matthew D Allen wrote:

> >be better to use global variables for Gtk widgets, and have all
> >functions in that file use them, or create separate widgets for each
> >function?
>
> Well, if it's a quick program that isn't going to get big, global is ok
> but it's not really stellar coding style and doesn't scale well at all.
> In fact, it becomes an ugly mess pretty fast if you're not really careful.
>
> >void exfunc(void)
> >{
> >    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
> >    button = gtk_button_new_with_label("Button");
> >    gtk_widget_show(button);
> >    gtk_widget_show(window);
> >}
>
> Umm...I dunno if this is just example code that you wrote, or if you're
> actually using it, but I think you need a line in there that says
> gtk_container_add(GTK_CONTAINER(window), button); to put the button i n
> the window.

yes, this is just example code, that is why stuff is missing :-)

>
>
> >By defining those widgets as globals, do I reduce the amount of memory
> >used by the program?
>
> No.  You just save yourself the "inconvenience" of passing them around in
> signal handlers.  It's much better to use signal handlers though.  Example
> of passing stuff around:
>
> button = gtk_button_new_with_label("Foobar");
> gtk_signal_connect(GTK_OBJECT(button), "clicked",
>                   GTK_SIGNAL_FUNC(foobar_callback), "Foobar");
>
> void foobar_callback(GtkWidget *emitter, gpointer data)
> {
>         /* Here, emitter is the button */
>         printf("%s\n",(char *)data);
> }
>
> The "gpointer data" can be whatever you want, including widgets, data
> structures, whatever.
>
> Hope this helps somewhat.

Thanks,
Aaron

>
>
> David Allen
> http://opop.nols.com/ Free Software Development
> Der Horizont vieler Menschen ist ein Kreis mit Radius Null -- und das
> nennen sie ihren Standpunkt.
>
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null

--
This message is powered by RedHat 6.1 and Perl
Visit my web site at http://iconmedia.com/cgi-bin/index.pl

Current uptime:
  1:00am  up  5:49,  0 users,  load average: 0.05, 0.06, 0.05





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