GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 23, 2014 5:12 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: mplayer stdout in textview
PostPosted: Fri Mar 30, 2012 11:45 pm 
Offline
Familiar Face

Joined: Sun Feb 12, 2012 2:23 pm
Posts: 7
Hi,
I write a simple frontend for mplayer and redirect stdout to a TextView:
Code:
for(;;)
   {
      gtk_widget_set_sensitive(data_app->button_play, FALSE);
      while(g_main_context_iteration(NULL, FALSE));

      status = g_io_channel_read_line(out_ch, &string, &size, NULL, NULL);
      
      buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(data_app->mplayer_view));      
      mark = gtk_text_buffer_get_insert(buffer);
      gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
      gtk_text_buffer_insert(buffer, &iter, string, -1);
      g_free(string);
      
      if(status == G_IO_STATUS_EOF)
      {
         gtk_widget_set_sensitive(data_app->button_play, TRUE);
         break;
      }
   }

but encountered a problem visible in the screenshot, multiple lines with A: ... A-V ...
How to make TextView behaved like in the console, refresh this lines in one place?
Maybe there is a better way to show mplayer stdout?

Image


Top
 Profile  
 
 Post subject: Re: mplayer stdout in textview
PostPosted: Sat Mar 31, 2012 11:36 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Not really a GTK question but a basic programming question.
You need to have an if else condition where if the mplayer text matches the A AV format (for the 2nd or more time in a row) you overwrite the last line in the textview, otherwise you just output it as usual.


Top
 Profile  
 
 Post subject: Re: mplayer stdout in textview
PostPosted: Sat Mar 31, 2012 7:52 pm 
Offline
Familiar Face

Joined: Sun Feb 12, 2012 2:23 pm
Posts: 7
Thank you for your reply,
I rewrote this part of the program like this:
Code:
for(;;)
   {
      gtk_widget_set_sensitive(data_app->button_play, FALSE);
      while(g_main_context_iteration(NULL, FALSE));

      status = g_io_channel_read_line(out_ch, &string, &size, NULL, NULL);
      GString *temp = g_string_new(string);
      if(!(g_strstr_len(temp->str, temp->len, "A-V:")))
      {
         buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(data_app->mplayer_view));
         mark = gtk_text_buffer_get_insert(buffer);
         gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
         gtk_text_buffer_insert(buffer, &iter, string, -1);
      }
      else      
      {
         gtk_text_buffer_get_iter_at_line(buffer, &start, 25);
         gtk_text_buffer_get_end_iter(buffer, &end);
         gtk_text_buffer_delete(buffer, &start, &end);
         gtk_text_buffer_insert(buffer, &start, string, -1);   
      }
      
      g_free(string);
      g_string_free(temp, TRUE);
      
      if(status == G_IO_STATUS_EOF)
      {
         gtk_widget_set_sensitive(data_app->button_play, TRUE);
         break;
      }
   }

it does the trick, but how to automatically get start iter when A-V line occurs? Copy to start the last one iter from if block gtk_text_iter_copy()?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group