Re: How to create unique widget when reusing widget id's from a GladeXML object.
Tristan Van Berkom wrote: oops this missed the list... On Tue, Aug 12, 2008 at 6:58 AM, Olivier Guilyardi <[EMAIL PROTECTED]> 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. dhk: 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. Cheers, -Tristan Find widget in container by name recursively: container_foreach (container, widget) { if (!strcmp (gtk_widget_get_name (widget) , data.search)) 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); } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list Good point, but right now I don't want to store the info. I'll look it up when necessary. I'll keep it in mind though. Thanks, dave ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: How to create unique widget when reusing widget id's from a GladeXML object.
Olivier Guilyardi wrote: Hi, dhk wrote: How can a unique widget be created by using the same widget from a GladeXML object multiple times? You can use different GladeXML objects, constructed out of the same glade file. Example: GladeXML *xml = glade_xml_new("test.glade", NULL, NULL); GtkWidget *widget1 = glade_xml_get_widget(xml, "mywidget"); GladeXML *xml2 = glade_xml_new("test.glade", NULL, NULL); GtkWidget *widget2 = glade_xml_get_widget(xml2, "mywidget"); Here widget1 and widget2 (and their children) are different "instances" of mywidget. About performance, from the liblglade manual : "the XML parse tree is cached to speed up creating another GladeXML object for the same file". Regards, This is exactly the way I expected it to work, and it does. Thanks for the confirmation on the functionality. It help me find the real problem that was somewhere else. At least now I know for sure that this procedure is acceptable. Thanks, dave ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: How to create unique widget when reusing widget id's from a GladeXML object.
On Tue, Aug 12, 2008 at 6:58 AM, Olivier Guilyardi <[EMAIL PROTECTED]> 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. dhk: 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. Cheers, -Tristan Find widget in container by name recursively: container_foreach (container, widget) { if (!strcmp (gtk_widget_get_name (widget) , data.search)) 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); } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: How to create unique widget when reusing widget id's from a GladeXML object.
On Tue, Aug 12, 2008 at 6:58 AM, Olivier Guilyardi <[EMAIL PROTECTED]> 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. dhk: 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. Cheers, -Tristan Find widget in container by name recursively: container_foreach (container, widget) { if (!strcmp (gtk_widget_get_name (widget) , data.search)) 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); } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
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 <[EMAIL PROTECTED]> 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. dhk: 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. Cheers, -Tristan Find widget in container by name recursively: container_foreach (container, widget) { if (!strcmp (gtk_widget_get_name (widget) , data.search)) 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); } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: How to create unique widget when reusing widget id's from a GladeXML object.
Hi, dhk wrote: How can a unique widget be created by using the same widget from a GladeXML object multiple times? You can use different GladeXML objects, constructed out of the same glade file. Example: GladeXML *xml = glade_xml_new("test.glade", NULL, NULL); GtkWidget *widget1 = glade_xml_get_widget(xml, "mywidget"); GladeXML *xml2 = glade_xml_new("test.glade", NULL, NULL); GtkWidget *widget2 = glade_xml_get_widget(xml2, "mywidget"); Here widget1 and widget2 (and their children) are different "instances" of mywidget. About performance, from the liblglade manual : "the XML parse tree is cached to speed up creating another GladeXML object for the same file". Regards, -- Olivier Guilyardi / Samalyse ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: How to create unique widget when reusing widget id's from a GladeXML object.
Tristan Van Berkom wrote: If you are using one glade file for the tab contents and parsing it again for each tab, then you get widgets in your runtime interface that have the same name, thats not an issue for gtk+ - but, as you named them yourself, its up to you to identify them some other way. Im not sure I understood properly what you wrote, but if I did, I would expect you to be using a list of structs or objects representing the data and widgets in that tab. Cheers, -Tristan On Mon, Aug 11, 2008 at 7:15 PM, dhk <[EMAIL PROTECTED]> wrote: dhk wrote: I'm adding tabs to a notebook by getting the tab (a vbox) out of a GladeXML object. The tab widget returned from glade_xml_build_widget() can be added to the notebook and everything works fine. The problem is when more tabs are added. It doesn't seem like the widget id's on each tab are exclusive to that tab. The last tab added behaves the best, but if a previous tab is clicked data entered and events on that tab appear on the last tab. This appears to be because the widget id's are the same in each tab because each tab was build from the same widget in the GladeXML file. What happens is when there are two tabs, the data placed in a field on tab one shows up in the field on both tabs. I thought the scope of the widget added to one tab would be out of scope for all other tabs. How can a unique widget be created by using the same widget from a GladeXML object multiple times? Thanks, dave ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list Does this have to do with referencing? It looks like the same resources are being used by the new widgets. Any ideas? Thanks, dave ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list Are you saying that I have to get each object out of the widget and store their reference and data somewhere? That sounds like it could get messy. I thought just by adding a widget to a container, in this case a notebook container, would keep track of that widget as long a I could keep track of the page it's on. What's happening is I add the same widget from the Glade xml, it's a vbox which is a tab page to a notebook, multiple times. Now I have a notebook of n pages. Each page is a form. The data and events on one page affect other pages which it shouldn't. Each page has a unique name so when I search that vbox widget for the page with focus I would expect to get the widgets of the form on that page, but I don't. So in a way I am keeping track of the widget by the unique name of the tab. Is this ok? Thanks, dave ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: How to create unique widget when reusing widget id's from a GladeXML object.
If you are using one glade file for the tab contents and parsing it again for each tab, then you get widgets in your runtime interface that have the same name, thats not an issue for gtk+ - but, as you named them yourself, its up to you to identify them some other way. Im not sure I understood properly what you wrote, but if I did, I would expect you to be using a list of structs or objects representing the data and widgets in that tab. Cheers, -Tristan On Mon, Aug 11, 2008 at 7:15 PM, dhk <[EMAIL PROTECTED]> wrote: > dhk wrote: >> >> I'm adding tabs to a notebook by getting the tab (a vbox) out of a >> GladeXML object. The tab widget returned from glade_xml_build_widget() can >> be added to the notebook and everything works fine. >> >> The problem is when more tabs are added. It doesn't seem like the widget >> id's on each tab are exclusive to that tab. The last tab added behaves the >> best, but if a previous tab is clicked data entered and events on that tab >> appear on the last tab. This appears to be because the widget id's are the >> same in each tab because each tab was build from the same widget in the >> GladeXML file. What happens is when there are two tabs, the data placed in >> a field on tab one shows up in the field on both tabs. I thought the scope >> of the widget added to one tab would be out of scope for all other tabs. >> >> How can a unique widget be created by using the same widget from a >> GladeXML object multiple times? >> >> Thanks, >> dave >> ___ >> gtk-app-devel-list mailing list >> gtk-app-devel-list@gnome.org >> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list >> > Does this have to do with referencing? It looks like the same resources are > being used by the new widgets. Any ideas? > > Thanks, > dave > > > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: How to create unique widget when reusing widget id's from a GladeXML object.
dhk wrote: I'm adding tabs to a notebook by getting the tab (a vbox) out of a GladeXML object. The tab widget returned from glade_xml_build_widget() can be added to the notebook and everything works fine. The problem is when more tabs are added. It doesn't seem like the widget id's on each tab are exclusive to that tab. The last tab added behaves the best, but if a previous tab is clicked data entered and events on that tab appear on the last tab. This appears to be because the widget id's are the same in each tab because each tab was build from the same widget in the GladeXML file. What happens is when there are two tabs, the data placed in a field on tab one shows up in the field on both tabs. I thought the scope of the widget added to one tab would be out of scope for all other tabs. How can a unique widget be created by using the same widget from a GladeXML object multiple times? Thanks, dave ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list Does this have to do with referencing? It looks like the same resources are being used by the new widgets. Any ideas? Thanks, dave ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
How to create unique widget when reusing widget id's from a GladeXML object.
I'm adding tabs to a notebook by getting the tab (a vbox) out of a GladeXML object. The tab widget returned from glade_xml_build_widget() can be added to the notebook and everything works fine. The problem is when more tabs are added. It doesn't seem like the widget id's on each tab are exclusive to that tab. The last tab added behaves the best, but if a previous tab is clicked data entered and events on that tab appear on the last tab. This appears to be because the widget id's are the same in each tab because each tab was build from the same widget in the GladeXML file. What happens is when there are two tabs, the data placed in a field on tab one shows up in the field on both tabs. I thought the scope of the widget added to one tab would be out of scope for all other tabs. How can a unique widget be created by using the same widget from a GladeXML object multiple times? Thanks, dave ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list