Re: passing object(widgets) references: preferred way [gtkbuilder, g_object(set/get)_data, or..]

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

 



2009/2/2 Fabio Mariotti <mariotti.fabio@xxxxxxxxx>:
> Dears,
>
> I guess it is a beginner question. The problem is:

Hi,
   I recommend that you use structures or even objects
to store your pointers - a perfect simple example of this
is the DevHelp sources, which are marvelously cleanly
maintained and easy to understand.

Basically, you *want* to have some module specific or
at least one program specific structure to hold any
kind of module specific or global data (not only objects
but also possibly integers, strings etc), this is a perfect
object/structure to pass as user data to all signal callbacks
and store all the relevant widget (or GtkAction) pointers.

Libglade's GladeXML was severely memory intensive so
it was always important to free it up and store pointers
in advance (as opposed to calling glade_xml_get_widget
on the memory bloated object). GtkBuilder is not that
memory intensive - but the truth is that there is no reason
for you to need a hash table full of widget pointers by name
either, all you need is some pointers to a handful of widgets
relevant to your program flow control.

Based on these facts and requirements I currently conclude
that holding pointers to relevant widgets after building your
ui with builder and freeing the builder object; is still the
cleanest, most readable and most efficient way to write
libglade/gtkbuilder using UI code (using object qdata IMO is
just a convenient hack for people who need a quick fix
without properly refactoring their module, I would avoid it
as much as possible in fresh new code).

Hope this gives you some good insight.

Cheers,
                -Tristan

>
> At a given point you have to set the text of a textbox


> deep within your code. How do I retrieve the object?
> Or better I do I set the object to be found?
>
> The gtkbuilder option 1:
> I use gtkbuilder and I globally store the *builder reference
> so that I can always use:
> gtk_builder_get_object(builder,"myobject")
> [and free the builder only once I close the app]
>
> The gtkbuilder option 2:
> I use gtkbuilder and I set up a local function "mycode_reference_all()"
> in the style of the old glade which was "g_object_set_data()" for every
> entry and free the builder after allocation.
>
> I guess that the difference is on one side the memory of the builder
> and on the other a matter of style. At least for this simple picture.
> In more complex cases I guess it is also a matter of sharing
> information between parts of the code and OOP style stuff.
> But I need you to teach me. Which one?
>
> In this respect. What would be the difference if I set up a couple or more
> structures to store the pointers instead to use a "g_object_set_data()"
> to share the widgets references?
> I partially answer my question:
> We need a mechanism in order to create widgets which is consistent.
> But why can't we do it implicit? I mean: lookup_widget(parent,"name").
> It might be that it is already there... so sorry for double asking..
>
> In any case: in my pretty simple apps I can work it out.
> But what it will be the "best practice" for complex applications?
>
> cheers
> Fabio
>
>
> _______________________________________________
> gtk-list mailing list
> gtk-list@xxxxxxxxx
> http://mail.gnome.org/mailman/listinfo/gtk-list
>
>
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux