Re: Button remains "pressed" until callback function ends



On Wed, 16 Feb 2005 11:04:19 +0100, Michal Kepien
<lordpopcorn poczta onet pl> wrote:
function is connected to the "clicked" event of a button. The problem is, the
button stays "pushed" until the sound playing function finishes its work. I want
the button to pop out immediately after it has been clicked (and of course, the
callback function to play the sound anyway). Is there any way to achieve that?

Your callback needs to start the sound playing and return immediately.
If you wait for the sound to finish, your GUI will lock up for the
duration of the sample, since callbacks execute in the same thread as
the widgets.

There are lots of ways to do this: one of the simplest (on linux) is
just to play the sound with system( "&" ). For example (ahem,
untested):

void
my_button_click( GtkWIdget *button, const char *filename )
{
  char buf[256];

  snprintf( buf, 256, "mpg123 %s &", filename );
  system( buf );
}

  g_signal_connect( button, "clicked",
    G_CALLBACK( my_button_click ), "sample.mp3" );

John



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