Re: duplicating GtkBuilder created widget objects
- From: Tristan Van Berkom <tvb gnome org>
- To: js hipro co in
- Cc: GTK App Devel <gtk-app-devel-list gnome org>
- Subject: Re: duplicating GtkBuilder created widget objects
- Date: Tue, 4 Dec 2012 01:33:08 +0900
On Mon, Dec 3, 2012 at 3:12 PM, Joe Steeve <js hipro co in> wrote:
On Sun, 2012-12-02 at 13:35 +0100, Tomasz Jankowski wrote:
I think, that you cannot easily copy widgets. In such situation I
usually use gtk_builder_add_objects_from_file().
When we do this, can there be two sets of objects with the same name? I
dont think so. Scenario: There is one top-level window (win-a). And, a
button in win-a brings up another top-level window (win-b). Each click
on the button should bring a win-b. There can be more than one win-b at
the same time. If I do Builder::add_objects_from_file, wont there be a
name clash of widgets from the new file and the ones already there?
I am now using multiple GtkBuilder objects. I moved win-b into a
separate glade file and load it every time I need a new window. Is there
a better approach?
This is correct, there is no good reason to keep a GtkBuilder object
itself alive for longer than the time it takes to create some widgets
from xml, after creating your window just dispose of the builder
object.
For even better encapsulation, create the GtkBuilder object
from the ->constructor() vfunc of your window, add the contents
created by GtkBuilder to your window, save any pointers to
widgets you might need (presumably as private object members
of your window) and destroy the builder object right away.
This way the builder constructs your window content implicitly
any time g_object_new() is called for your window type.
Probably you want to use GResource to store your builder
xml (or const gchar* memory) instead of scratching the HD
every time you need a new object.
Cheers,
-Tristan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]