On Mon, Nov 9, 2009 at 3:57 PM, Michael Libby <michael.c.li...@gmail.com> wrote:
> This seems to be either a bug in my understanding of how to use this
> functionality or a bug in the gtk_test_find_widget function itself.

After reading the source for the various gtk_test_find_* functions and
the documentation over again, the bug was my own understanding.

The function gtk_test_find_widget() is trying to find a widget *near*
a label with the text in question, whereas I was thinking it would
find the widget that *contained* the text in question.

No surprise that the existing function has somewhat strange behavior
when attempting to locate menu items.

Suggest to add something like to find the widget with the actual text:

GtkWidget*
gtk_test_find_widget_by_text (GtkWidget *widget,
                              const gchar *label_pattern,
                              GType widget_type)
{
  if (GTK_IS_LABEL (widget))
    {
      const gchar *text = gtk_label_get_text (GTK_LABEL (widget));
      if (g_pattern_match_simple (label_pattern, text))
        return widget;
    }
  if (GTK_IS_CONTAINER (widget))
    {
      GList *node, *list = gtk_container_get_children (GTK_CONTAINER (widget));
      for (node = list; node; node = node->next)
        {
          GtkWidget *label = gtk_test_find_widget_by_text (node->data,
label_pattern, widget_type);

          if (label)
            {
              if (g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
                {
                  return widget;
                }
              else
                {
                  return label;
                }
            }
        }
      g_list_free (list);
    }
  return NULL;
}


-- 
Michael C. Libby
www.mikelibby.com
_______________________________________________
gtk-devel-list mailing list
gtk-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list

Reply via email to