On 21.12.2012 12:24, Torsten Schoenfeld wrote:
On 21.12.2012 12:03, Mario Kemper wrote:
When I change it to...
my $image = Gtk3::Image->new_from_stock( 'gtk-index', 'menu' );
... the following error occurs:
Argument "menu" isn't numeric in subroutine entry at
/usr/lib/perl5/Glib/Object/Introspection.pm line 57, <DATA> line 19.
Does the matching between the numeric values and the corresponding
strings not work yet? Passing '1' does work as expected.
Unfortunately, that seems to be intentional. Looking at
<http://developer.gnome.org/gtk3/stable/GtkImage.html#gtk-image-new-from-stock>,
the "size" parameter has a "[type int]" annotation. The Perl bindings
thus see a plain integer parameter, and the enum string magic is never
invoked. The reason for this annotation is explained in
<https://bugzilla.gnome.org/show_bug.cgi?id=604895>.
With a recent round of commits to G:O:I¹, this can now be tackled. I
attach an initial patch for the cited constructor. Would you, or anyone
else listening, be willing to complete this patch to include support for
all or part of the following?
• gtk_image_new_from_stock, gtk_image_new_from_icon_set,
gtk_image_new_from_icon_name, [gtk_image_new_from_gicon],
gtk_image_set_from_stock, gtk_image_set_from_icon_set,
gtk_image_set_from_icon_name, [gtk_image_set_from_gicon],
gtk_image_get_stock, gtk_image_get_icon_set, gtk_image_get_icon_name,
[gtk_image_get_gicon]
• gtk_icon_size_*
• (gtk_icon_set_render_icon), gtk_icon_set_render_icon_pixbuf,
gtk_icon_set_get_sizes
• gtk_icon_source_set_size, gtk_icon_source_get_size
• gtk_action_create_icon
• gtk_scale_button_new
• gtk_tool_item_get_icon_size
• gtk_tool_palette_set_icon_size, gtk_tool_palette_get_icon_size
• gtk_tool_shell_get_icon_size
• gtk_toolbar_get_icon_size, gtk_toolbar_set_icon_size
• gtk_tooltip_set_icon_from_stock, gtk_tooltip_set_icon_from_icon_name,
[gtk_tooltip_set_icon_from_gicon]
• (gtk_style_render_icon)
• (gtk_widget_render_icon), gtk_widget_render_icon_pixbuf
• gtk_render_icon_pixbuf
Items in round brackets are deprecated and thus no priority. Items in
square brackets might need more work (Glib::IO support) than just the
icon size conversion.
¹
<http://git.gnome.org/browse/perl-Glib-Object-Introspection/commit/?id=9e214e19daa68e72b2bca38f7f09347e25880e13>,
<http://git.gnome.org/browse/perl-Glib-Object-Introspection/commit/?id=277a23086a28a1420a90a7100df357d8f008fc35>.
diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index a6bb17e..127d4f3 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -94,6 +94,43 @@ sub Gtk3::Dialog::_gtk3_perl_response_converter {
return ($dialog, $_GTK_RESPONSE_ID_TO_NICK->($id));
}
+my $_GTK_ICON_SIZE_ID_TO_NICK = sub {
+ my ($id) = @_;
+ {
+ local $@;
+ my $nick = eval { Glib::Object::Introspection->convert_enum_to_sv (
+ 'Gtk3::IconSize', $id) };
+ if (defined $nick) {
+ return $nick;
+ }
+ }
+ {
+ my $nick = Gtk3::IconSize::get_name ($id);
+ if (defined $nick) {
+ return $nick;
+ }
+ }
+ return $id;
+};
+my $_GTK_ICON_SIZE_NICK_TO_ID = sub {
+ my ($nick) = @_;
+ {
+ local $@;
+ my $id = eval { Glib::Object::Introspection->convert_sv_to_enum (
+ 'Gtk3::IconSize', $nick) };
+ if (defined $id) {
+ return $id;
+ }
+ }
+ {
+ my $id = Gtk3::IconSize::from_name ($nick);
+ if ($id) { # if it's not zero
+ return $id;
+ }
+ }
+ return $nick;
+};
+
# - gdk customization ------------------------------------------------------- #
my @_GDK_HANDLE_SENTINEL_BOOLEAN_FOR = qw/
@@ -774,6 +811,12 @@ sub Gtk3::HBox::new {
$_GTK_BASENAME, 'HBox', 'new', $class, $homogeneous, $spacing);
}
+sub Gtk3::Image::new_from_stock {
+ return Glib::Object::Introspection->invoke (
+ $_GTK_BASENAME, 'Image', 'new_from_stock',
+ $_[0], $_[1], $_GTK_ICON_SIZE_NICK_TO_ID->($_[2]));
+}
+
sub Gtk3::ImageMenuItem::new {
my ($class, $mnemonic) = @_;
if (defined $mnemonic) {
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list