Re: event_pending question?



Sargonnas wrote:

Before you catch the list on fire, Id like to point out that I am a newb
to both perl and gtk-perl. I got bored one day, and started playing around
with making a front-end of sorts for MPlayer.. and it was going along
fairly well, until I came upon a problem. The problem is that when I
attempt to run mplayer, the gui will stop updating. Ive found that
appearantly Gtk->iteration() will keep it from doing this, but I haven't
found out exactly how I should use it... What Im guessing is making this
hard, is the fact that I have it gathering all console output from MPlayer
and inserting it into a text widget. Heres a little code snippet.. any
help would be appreciated.

You need a Gtk::Gdk::input_add for this. Your playmovie() subroutine 
doesn't give back the control to Gtk's main event loop. It blocks the 
whole program while running mplayer.

It should work like this (hacked into my email client, no warranty for 
syntax-error-freeness ;)

--snip--

  sub playmovie {
    my ($file) = @_;

    my $fh = FileHandle->new;

    open($fh, "mplayer $file |") or die "can't fork mplayer";

    my $handle;

    $handle = Gtk::Gdk->input_add (
      $fh->fileno, 'read',
      sub { got_mplayer_output( $fh, $handle ) }
    );

    1;
  }

  sub got_mplayer_output {
    my ($fh, $handle) = @_;

    if ( eof($fh) ) {
      # mplayer exit
      Gtk::Gdk->input_remove($handle);
      close $fh;
      print "mplayer:exit\n";
      return 1;
    }

    my $line = <$fh>;
    print "mplayer:$line";

    1;
  }

--snip--

Hope this helps,

Joern

-- 
Joern Reder
Development Head ZYN! Coding Division - http://www.zyn.de/




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