Re: GIO in Perl



In case you still need an example program with app menu, try this:

---
#!perl
use strict;
use warnings;
use Glib::IO;
use Gtk3;

Glib::set_application_name ("App");
my $app = Gtk3::Application->new ("org.gtk-perl.App", qw/flags-none/);

$app->signal_connect (startup => sub {
  my ($app) = @_;

  my $action = Glib::IO::SimpleAction->new_stateful (
    "active", undef, Glib::Variant->new ("b", Glib::FALSE));
  $action->signal_connect (activate => sub {
    my $b = $action->get_state->get_boolean;
    warn "activate: ", $b;
    $action->set_state (Glib::Variant->new ("b", !$b));
  });
  $app->add_action ($action);

  my $menu = Glib::IO::Menu->new;
  $menu->append ("Active", "app.active");
  $app->set_app_menu ($menu);
});

# activate
$app->signal_connect (activate => sub {
  my ($app) = @_;

  my $window = Gtk3::ApplicationWindow->new ($app);
  $window->set_title ("App");
  $window->show_all;
});

exit $app->run;
---


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