App-Chart

 view release on metacpan or  search on metacpan

lib/App/Chart/Glib/Ex/ChildPid.pm  view on Meta::CPAN

    $! = POSIX::ECHILD();
    return -1;
  }
  if (! defined $sig) { $sig = 'TERM'; }
  $self->{'terminate_sig'} = $sig;
  if ($self->kill($sig) != 1) {
    return -1;
  }

  $self->{'terminate_ids'} = Glib::Ex::SourceIds->new
    (Glib::Timeout->add ($self->get('terminate-timeout'),
                         \&_terminate_timeout,
                         App::Chart::Glib::Ex::MoreUtils::ref_weak($self)));
  return 1;
}
sub _terminate_timeout {
  my ($ref_weak_self) = @_;
  my $self = $$ref_weak_self || return;
  my $sig = $self->{'terminate_sig'};

  if ($sig eq 'KILL' || $sig eq POSIX::SIGKILL()) {

lib/App/Chart/Gtk2/Subprocess.pm  view on Meta::CPAN

  }
  return Glib::SOURCE_CONTINUE;
}

sub _update_idle_timer {
  my ($self) = @_;
  my $want_timer = ($self->pid && ! $self->{'job'});

  if ($want_timer) {
    $self->{'timer_ids'} ||= Glib::Ex::SourceIds->new
      (Glib::Timeout->add (IDLE_TIMEOUT_SECONDS * 1000,
                           \&_do_idle_timeout,
                           App::Chart::Glib::Ex::MoreUtils::ref_weak($self)));
  } else {
    $self->{'timer_ids'} = undef;
  }
}

sub _do_idle_timeout {
  my ($ref_weak_self) = @_;
  my $self = $$ref_weak_self || return Glib::SOURCE_REMOVE;

maybe/TimerObject.pm  view on Meta::CPAN


sub _establish {
  my ($self) = @_;
  if (my $id = delete $self->{'source_id'}) {
    Glib::Source->remove ($id);
  }

  if (my $period = $self->{'period'}) {
    my $weak_self = $self;
    Scalar::Util::weaken ($weak_self);
    $self->{'source_id'} = Glib::Timeout->add
      ($period,
       \&Gtk2::Ex::SourceObject::_source_callback, \$weak_self,
       $self->{'priority'} || Glib::G_PRIORITY_DEFAULT);
    ### timer id: "$self $self->{'source_id'}"
  }
}

sub set_period {
  my ($self, $period) = @_;
  my $old_period = $self->{'period'};

maybe/TimerObject.pm  view on Meta::CPAN

      userdata      => $widget,
      weak_userdata => 1);

 $timer->set_period (100);
 $timer->start;
 $timer->stop;

=head1 DESCRIPTION

C<Gtk2::Ex::TimerObject> is an object-oriented wrapper around the
C<< Glib::Timeout->add >> timer mechanism.  A timer object can be stopped
and later restarted, and is automatically stopped if the object is destroyed
(when all references to it are dropped).

The "C<weak>" option allows only a weak reference to be kept to the userdata
passed to the callback function.  If the userdata object or widget is
destroyed then the timer stops.  This is good if the timer is part of a
widget implementation (the weakening avoid a circular reference).

=head1 FUNCTIONS

maybe/TimerObject.pm  view on Meta::CPAN

=item C<< $timer->set_period ($milliseconds) >>

Set the period of C<$timer> to C<$milliseconds>, or stop it if
C<$milliseconds> is C<undef>.

In the current implementation, if the timer is running and the period is
changed then it starts counting down again from a whole new C<$milliseconds>
period.  Perhaps in the future it'll be possible to take into account how
long since the last firing, to keep it running smoothly if merely making
small adjustments to the period, but current Glib (version 2.14) doesn't
allow that (not with the basic C<< Glib::Timeout->add >>).

=item C<< $timer->stop >>

Stop C<$timer>, so no further calls to its C<$callback> are made.  This is
the same as a C<< $timer->set_period(undef) >>.  The timer can be restarted
later by a new C<set_period>, if desired.

=back

=head1 OTHER NOTES

C<TimerObject> is currently implemented as a Perl object holding a timer ID
from C<< Glib::Timeout->add >>.  If C<GSource> was available at the Perl
level in the future then perhaps C<TimerObject> could become a subclass of
that.

=head1 SEE ALSO

L<Glib::MainLoop>, L<Gtk2::Ex::IdleObject>, L<Glib::Ex::SignalObject>

=cut

maybe/TimerObject.t  view on Meta::CPAN

$SIG{ALRM} = sub {
  die "main loop hung: $main_where";
};
my $attempts = 0;
sub attempts {
  if (--$attempts < 0) { Gtk2->main_quit; }
  return 1;
}
sub main {
  $attempts = 10;
  my $id = Glib::Timeout->add (1, \&attempts);
  alarm(5);
  Gtk2->main;
  alarm(0);
  ($main_where) = 'nowhere';
  Glib::Source->remove ($id);
  
}

skip ($if_no_display, sub {
        my $timer = Gtk2::Ex::TimerObject->new (1000, \&noop);

misc/t-button-sens.pl  view on Meta::CPAN


my $toplevel = Gtk2::Window->new('toplevel');
$toplevel->signal_connect (destroy => sub { Gtk2->main_quit });

my $button = Gtk2::Button->new_with_label ('Press');
$toplevel->add ($button);
$button->signal_connect
  (clicked => sub {
     print "insensitive\n";
     $button->set_sensitive (0);
     Glib::Timeout->add (1000, sub {
                           print "sensitive again\n";
                           $button->set_sensitive (1);
                           return 1; # Glib::SOURCE_CONTINUE
                         });
   });

$toplevel->show_all;
Gtk2->main;
exit 0;

misc/t-entry.pl  view on Meta::CPAN

     print "$progname: entry activate\n";
   });
$vbox->pack_start ($entry, 0,0,0);

my $keyval_left = Gtk2::Gdk->keyval_from_name('Left');

{
  my $button = Gtk2::Button->new_with_label ("keyval left");
  $button->signal_connect
    (clicked => sub {
       Glib::Timeout->add
           (3000, sub {
              print "$progname: keyval left\n";
              $entry->bindings_activate ($keyval_left, []);
              return 0;
            });
     });
  $vbox->pack_start ($button, 0,0,0);
}
{
  my $button = Gtk2::Button->new_with_label ("event left");
  $button->signal_connect
    (clicked => sub {
       my $event = Gtk2::Gdk::Event->new ('key-press');
       $event->window ($entry->window);
       # $event->hardware_keycode (100); # Left
       $event->hardware_keycode (36); # Return
       $event->group (0);
       $event->keyval ($keyval_left);
       $event->set_state ([]);
       Glib::Timeout->add
           (3000, sub {
              print "$progname: event left\n";
              print "  dispatch ",($entry->bindings_activate_event($event)
                                   ? "yes" : "no"), "\n";
              return 0;
            });
     });
  $vbox->pack_start ($button, 0,0,0);
}

misc/t-timer-object.pl  view on Meta::CPAN

       weak => 1);
  }
  Gtk2->main;
  exit 0;
}

{
  my $widget = Gtk2::Label->new;
  my $weak_widget = $widget;
  Scalar::Util::weaken ($weak_widget);
  my $id = Glib::Timeout->add (1000, \&timer, $weak_widget);
  Gtk2->main;
  exit 0;
}

__END__




{

misc/t-timer-object.pl  view on Meta::CPAN

  my ($period, $callback, $userdata, @optional_priority) = @_;
  if (ref $userdata) {
    my @wdata = ($callback, $userdata);
    Scalar::Util::weaken ($wdata[1]);
    return (\&_weak_callback, \@wdata);
  } else {
    return ($callback, $userdata);
  }
}

#   $self->{'timer_id'} = Glib::Timeout->add
#     ($period, weak_callback(\&_timer_object_callback,$self), @optional_priority);




#------------------------------------------------------------------------------
# integer ID, with weak reference to userdata

sub timeout_add_weak {
  my ($period, $callback, $userdata, @optional_priority) = @_;
  if (ref $userdata) {
    my @wdata = ($callback, $userdata);
    Scalar::Util::weaken ($wdata[1]);
    $callback = \&_timeout_weak_callback;
    $userdata = \@wdata;
  }
  return Glib::Timeout->add ($period, $callback, $userdata,
                             @optional_priority);
}
sub _timeout_weak_callback {
  my ($wdata) = @_;
  if (! defined $wdata->[1]) {
    print "userdata garbage collected, stopping\n";
    return 0;
  }
  return (&{$wdata->[0]} ($wdata->[1]));
}

t/MyTestHelpers.pm  view on Meta::CPAN

  my ($widget, $signame) = @_;
  if (DEBUG) { MyTestHelpers::diag ("wait_for_event() $signame on ",$widget); }
  my $done = 0;
  my $got_event = 0;
  my $sig_id = $widget->signal_connect
    ($signame => sub {
       if (DEBUG) { MyTestHelpers::diag ("wait_for_event()   $signame received"); }
       $done = 1;
       return 0; # Gtk2::EVENT_PROPAGATE (new in Gtk2 1.220)
     });
  my $timer_id = Glib::Timeout->add
    (30_000, # 30 seconds
     sub {
       $done = 1;
       MyTestHelpers::diag ("wait_for_event() oops, timeout waiting for $signame on ",$widget);
       return 1; # Glib::SOURCE_CONTINUE (new in Glib 1.220)
     });
  if ($widget->can('get_display')) {
    # display new in Gtk 2.2
    $widget->get_display->sync;
  } else {



( run in 0.361 second using v1.01-cache-2.11-cpan-a5abf4f5562 )