Re: Using Gtk macros



On Fri, 6 Sep 2019 at 16:57, Mike Martin via gtk-perl-list <gtk-perl-list gnome org> 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.

--


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