Tux has asked for the wisdom of the Perl Monks concerning the following question:

I was writing a simple application in perl-Tk that would replace my beep-media-player or xmms. These two are ancient and use a audio interface that will block other applications of also using the audio devices.

So I create a (very) simple GUI in perl-Tk, test it (buttons, open play-list or CD, display status etc etc). Then I add the actual GStreamer calls as documented. I even browsed the examples section to see if I did it right.

Now when I hit the [play] button, the music starts :), so the basics work fine, but the GUI now renders irresponsible. The status isn't updated and none of the buttons work.

Is the Glib::MainLoop overruling the Tk::MainLoop?

Are there any recipes to make this combination work?


Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re: Does GStreamer block Tk?
by Anonymous Monk on Aug 18, 2010 at 06:53 UTC
    Is the Glib::MainLoop overruling the Tk::MainLoop?

    Yes

    Are there any recipes to make this combination work?

    You could fork, but its better to use Gtk2 to make your gui instead (Glib is a prerequisite for Gtk2)

Re: Does GStreamer block Tk?
by Tux (Canon) on Aug 18, 2010 at 09:23 UTC

    I found a workaround:

    GStreamer->init (); Glib::Idle->add (sub { $mw->update; $mw->idletasks; return TRUE; }, undef, 0); MainLoop;

    Enjoy, Have FUN! H.Merijn
Re: Does GStreamer block Tk?
by zentara (Cardinal) on Aug 18, 2010 at 12:36 UTC
    Is the Glib::MainLoop overruling the Tk::MainLoop? Are there any recipes to make this combination work?

    Yes, you can make the Tk and Gtk2 loop work together. One loop must be the master, and the other is given a (pseudocode) do_one_loop command thru a timer.

    Here is a basic example. This technique works for combining all eventloop systems, like Gtk2, SDL, Tk, POE, GLib, Wx, etc.

    #!/usr/bin/perl -w use strict; use Gtk2; use Tk; #setup Tk loop my $mw = MainWindow->new(-title=>'Tk Window'); my $count_tk = 0; my $labtk = $mw->Label(-textvariable =>\$count_tk)->pack; #setup Gtk2 loop Gtk2->init; my $count_gtk = 0; my $window = Gtk2::Window->new('toplevel'); $window->set_title('Gtk2 Window'); my $glabel = Gtk2::Label->new("This is a Gtk2 Label $count_gtk"); $window->add($glabel); $window->show_all; # make Tk loop the master, but you could make Gtk2 master if desired # the lower the repeat rate, i.e. 1 ms, # will give more cpu time to the gtk2 loop # this is sometimes called manually pumping the event loop my $tktimer = $mw->repeat(10, sub{ $count_gtk++; $glabel->set_text("This is a Gtk2 Label $count_gtk"); Gtk2->main_iteration while Gtk2->events_pending; $count_tk++; }); $mw->Button(-text=>' Tk control Quit ', -command => sub{exit} )->pack(); # make the Tk Mainloop the controller MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku
Re: Does GStreamer block Tk?
by Tux (Canon) on Aug 18, 2010 at 15:15 UTC

    Thanks a lot. The other way aound is:

    GStreamer->init (); Glib::Timeout->add (250, sub { $mw->update; return TRUE; }, undef, 0); MainLoop;

    In my case, that 250 ms is enough.


    Enjoy, Have FUN! H.Merijn