Re: Gnome::App->create_menus() not inserting widget info



Paolo,
   Thanks a bunch for fixing that, works like a charm now.  Here is
some code to do the widget_from_uiinfo that you mentioned :

sub widget_from_uiinfo {
  my ( $uiinfo, $uipath ) = @_;
  my ( @parent_array, $array_item, $find_type );
  my @uiinfo_path = split(/\//, $uipath);
  @parent_array = @{$uiinfo};
  while(@uiinfo_path) {
     next unless($search_path = shift(@uiinfo_path));
     $find_type = ($#uiinfo_path == -1) ? 'item' : 'subtree';
     foreach $array_item ( @parent_array ) {
        print "Comparing $array_item->{type} to $find_type for $array_item->{label}\n";
        if ( $array_item->{type} eq $find_type ) {
           if( $array_item->{label} eq $search_path ) {
              return($array_item->{widget}) if ($find_type eq 'item');
              @parent_array = @{$array_item->{subtree}};
              last;
           }
        }
     }
  }
  return(0);
}

It works well, returning 0 if it fails.  The are only two gotchas that I came
across with this code.  The first is that if you have menu items with
accelerators, like '_New', you have to put the accellerator in your search path :

widget_from_uiinfo(\ main_menus, "/_File/_New")

Easily fixed with one more substituion before comparison, but I thought it
was okay as it is.

The second is if your menuitem label contains a / in it.  My split will break
on that.  Didn't have a good way around it, so I'll toss it out there to see if
someone else has a good idea.

Feel free to use, modify, and abuse the above code in anyway you see fit.

Andrew

On 05/30/01 Andrew Schretter wrote:
I'm creating a set of menus and toolbars the easy way with the
create_menus and create_toolbar functions of Gnome::App.

I create an array like :

@main_toolbar = (
   {
        type => 'item',
        label => 'Quit',
        pixmap_type => 'filename',
        pixmap_info => 'pics/quit.xpm',
        hint => "Click here to quit",
        callback => sub \&my_function,
   }
);

and then call :

$app->create_toolbar(@main_toolbar);

Almost everything looks perfect.  The problem I am encountering is that
create_menus in the C code is supposed to put into the 11th field of GnomeUIInfo
a pointer to the GtkWidget that is the menuitem.  I can't seem to reference this
info, either it is not placed into the hash above when create_toolbar is called
or it is placed with a key that I can't find.

Ok, I wasn't aware of this feature (and anyway I didn't write
that code, so blame dhd:-). When I needed to get a handle on a widget
I used the append_item() API.
Anyway, this is now fixed in cvs and will be included in the next release.
I changed Gnome/samples/app-helper.pl to show how to get the widgets.
I'd appreciate if someone writes a convenience function along the lines
of show_widget in the sample code that returns a widget given a path:

      my $widget = Gnome::widget_from_uiinfo (\ toolbar_info, "/Help/About")

lupus

--
-----------------------------------------------------------------
lupus debian org                                     debian/rules
lupus ximian com                             Monkeys do it better

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list



Andrew Schretter
Systems Programmer, Duke University
Dept. of Mathematics (919) 660-2866






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