Re: Inspecting a Gtk2::GladeXML object



On Fri, 2006-06-23 at 15:09 +1000, Daniel Kasak wrote:
Hi all.

Is there a way to list all widgets in a Glade XML file?
It would be nice if I could iterate over them without knowing what they
are in advance ...

I can't see anything in the Gtk2::GladeXML API, but it is XML, so you
can parse the file using your favourite XML module; e.g.:

  use XML::LibXML;

  my $parser = XML::LibXML->new();

  my $doc  = $parser->parse_file($file);

  foreach my $widget ($doc->findnodes('//*[name() = "widget"]')) {
    my $class = $widget->findvalue('./@class');
    my $id    = $widget->findvalue('./@id');
    print "$class: $id\n";
  }

The widget class names are the C names rather than the Perl names, but
that shouldn't be too much of a barrier.

Cheers
Grant




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