GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Oct 25, 2014 5:31 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: I can't see my progress bar!
PostPosted: Mon Jan 17, 2011 10:15 pm 
Offline
GTK+ Geek

Joined: Sat Sep 26, 2009 6:41 am
Posts: 69
No doubt I'm missing something stunningly obvious - but...

I have a textview. I need to do some heavy processing on the text which takes several seconds (or a couple of minutes), so I'd like a progress bar.

Every reference I can find suggests I need to make it:

Code:
   pbar = gtk_progress_bar_new ();
   //gtk_progress_bar_set_text ((GtkProgressBar *) pbar, "Spell-checking entire text");
   gtk_widget_show (pbar);
   while (g_main_context_iteration(NULL, FALSE));


and then I need to update it in a loop. I have one conveniently which changes on a percentage basis...

Code:
      if (((100*gtk_text_iter_get_line(&start))/lines_in_buffer) > last_percent)
      {
         last_percent = (100*gtk_text_iter_get_line(&start))/lines_in_buffer;
         gtk_progress_bar_set_fraction ((GtkProgressBar *) pbar, (double)last_percent/100);
         while (g_main_context_iteration(NULL, FALSE));
         printf("%c%c%c%c%d%% ", 0x08, 0x08, 0x08, 0x08, last_percent);
         fflush(stdout);
      {


This last part is working; the percentage increases on the console and the screen updates through the process - but the progress box never appears.

What am I doing stupid? I see that most of the examples use either threads or a progress box which is part of the main window, but in my innocence I had foolishly assumed that a progress box is such a useful thing that it would be a self-contained window in and of itself - do I have to get all complicated?

Thanks,

Neil


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2011 1:48 am 
Offline
GTK+ Geek

Joined: Fri Sep 04, 2009 6:53 am
Posts: 68
If you want to show a widget, you must put it directly or indirectly in a GtkWindow or some of its derivates.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2011 3:41 am 
Offline
GTK+ Geek

Joined: Sat Sep 26, 2009 6:41 am
Posts: 69
So this means I'd need to set up a child window, put the progress bar in that, and implement callbacks between the main routine and the child?

Meh, complicated... any examples you can point to?

Thanks,

Neil


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2011 9:07 pm 
Offline
GTK+ Geek

Joined: Sat Sep 26, 2009 6:41 am
Posts: 69
Ah, answering myself - I see I can drop a progress bar on top of the status bar, and I can talk to that directly (the layout is from Glade). I can't see how to proportion the progress bar - and it would be nice to appear/disappear it as required.

It works nicely so far, though.

Neil


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 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