Using Gtk macros

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Gtk macros

Gtk+ - Perl mailing list
How do I use Gtk macros in perl-gtk?
eg in c
GTK_IS_CONTAINER(widget)
What is the corresponding method in perl-gtk
thanks

_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Using Gtk macros

Gtk+ - Perl mailing list
On Fri, 6 Sep 2019 at 16:57, Mike Martin via gtk-perl-list <[hidden email]> wrote:
How do I use Gtk macros in perl-gtk?
eg in c
GTK_IS_CONTAINER(widget)
What is the corresponding method in perl-gtk

I assume you're talking about Gtk3.

Macros are not introspected unless they evaluate to simple scalar values. The "IS" type checking macros are replaces by normal Perl type checking operations:

```
use v5.22;
use Gtk3 '-init';

my $x = Gtk3::Button->new_with_label('foo');
say "The type of x is: ", ref($x);
```

will print out:

```
The type of x is: Gtk3::Button
```

If you want to check if an instance is of a certain type, you can use UNIVERSAL::isa:

```
use v5.22;
use Gtk3 '-init';
 
my $x = Gtk3::Button->new_with_label('Foo');

say "x is a button" if $x->isa('Gtk3::Button');
say "x is a container" if $x->isa('Gtk3::Container');
say "x is a widget" if $x->isa('Gtk3::Widget');
say "x is a window" if $x->isa('Gtk3::Window');
```

will print out:

```
x is a button
x is a container
x is a widget
```

Hope this helps.

Ciao,
 Emmanuele.


_______________________________________________
gtk-perl-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-perl-list