Re: widget reuse question



Matthew Dalton wrote:

Henri Torgemane wrote:
Sure you could keep adding and removing widgets to your container, but
your code would be messy and it probably wouldn't look good to the user.

We'll see about that... :P

How would you do it anyway? I've written the rest of the program to
handle it that way, so I'd like to try it...

Well, without using a GtkNotebook, you can still minimize the amount of work
required to remove the current page and show the next one by manipulating
just one container:

assuming you built your first page inside a container named "first_page",
place that container inside a GtkBin object named "holder" using something
like:

gtk_container_add (GTK_CONTAINER (holder), first_page);
gtk_widget_show_all (holder);

then remove it with

gtk_container_remove (GTK_CONTAINER (holder), first_page);

build your second page in another container named "second_page", and put it
up

gtk_container_add (GTK_CONTAINER (holder), second_page);
gtk_widget_show_all (holder);

etc..

Instead, you can use a GtkNotebook to do that very kind of stuff.
Put each of your step in a different page, hide the tabs and borders and
plug your Next and Back buttons to gtk_notebook_next_page and
gtk_notebook_prev_page.

I don't know how the GtkNotebook works (I'll look in the tutorial
later...). I assume that you would have to prepare every page before
showing it? Does this incur a performance or memory usage hit? I guess
it might not make any difference depending on how libgtk manages memory
and non-visible widgets.

here's a quick example:

notebook = gtk_notebook_new ();
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE);
// build first page
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), first_page);
// build second page
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), second_page);
// ...

gtk_notebook_set_page (GTK_NOTEBOOK (notebook), 0);

then navigate in your notebook with
gtk_notebook_next_page (GTK_NOTEBOOK (notebook));
etc..


I guess you could build each new page as needed (and probably destroying the
previous widgets) to save some memory.
For a typical wizard application, I'd think it's not worth the trouble, but I
don't know your specific needs.


Henri






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