Re: How to create unique widget when reusing widget id's from a GladeXML object.

oops this missed the list...

On Tue, Aug 12, 2008 at 6:58 AM, Olivier Guilyardi <ml xung org> wrote:
About performance, from the liblglade manual : "the XML parse tree is cached
to speed up creating another GladeXML object for the same file".

Yes, and for the same reasons outlined above its a good idea to unref
your GladeXML objects as soon as your UI is built, so you dont have
access to the hash map provided by the glade xml.

  Your theory about keeping track by pages is indeed sane,
you can use a simple recursive algorythm to find a widget
by name inside a page, I'll leave some pseudo code for you here,
but IMO, using a structure in a list to hold pointers to the desired
widgets and other page specific datas is cleaner and better
programming practice - mostly because it maintains a cleaner
split between business logic and user interface.

Consider that when your UI and business logic become more
complex; with your model you might end up using g_object_get/set_data()
alot and working directly with widgets (which you may decide to rename,
change in the UI) - and with structs in a list, you will be adding struct
members instead - and possibly tweaking the code portion that
loads the structs and builds the UI whenever the UI might change.


Find widget in container by name recursively:
container_foreach (container, widget) {
 if (!strcmp (gtk_widget_get_name (widget) ,
     data.widget = widget;

  if (is_container (widget))
     gtk_container_foreach (widget, container_foreach, data);


GtkWidget *find_widget_in_container (container, name)
  struct {
       gchar *search = name;
       GtkWidget *widget = NULL;
  } data;

  gtk_container_foreach (container, container_foreach, &data);

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