FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Glib.Timeout and ProgressBar

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
GG



Joined: 05 Nov 2009
Posts: 18

PostPosted: Fri Dec 11, 2009 8:54 pm    Post subject: Glib.Timeout and ProgressBar Reply with quote

I try to use ProgressBar with Glib.Timeout in this sample code but I get a segmentation fault when enter in update_progress_bar.

I'm doing something wrong ?

Code:

module sample;

import gtk.Window;
import gtk.Main;
import gtk.MainWindow;
import gtk.Widget;
import gtk.ProgressBar;
import glib.Timeout;

gboolean update_progress_bar(gpointer data)
{
  //gtk_progress_bar_pulse(GTK_PROGRESS_BAR (data));
  ProgressBar p = cast(ProgressBar)data;
  p.setPulseStep(0.1);
  p.pulse();
  p.pulse();
  p.pulse();

  /* Return true so the function will be called again; returning false removes
   * this timeout function.
   */
  return false;
}




int main (string[] args)
{
   Main.init(args);
   
   Window w = new Window("test");
   
   w.addOnHide(delegate void(Widget wid) {Main.exit(0);});
   
   ProgressBar p = new ProgressBar();
   p.setPulseStep(0.1);
   
   Timeout.add(1000,cast(GSourceFunc)&update_progress_bar,p.getProgressBarStruct()); // or passing p : same problem
   
   w.add(p);
   w.showAll();
   
   Main.run();
   return 0;
}


Thanks !
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sat Dec 12, 2009 5:16 am    Post subject: Reply with quote

I'll test this later today,

but the update_progress_bar needs to be marked as extern(C).
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sat Dec 12, 2009 7:13 am    Post subject: Reply with quote

This example is working for me:

Code:
module sample;

import gtk.Window;
import gtk.Main;
import gtk.MainWindow;
import gtk.Widget;
import gtk.ProgressBar;
import glib.Timeout;

extern(C) gboolean update_progress_bar(gpointer data)
{
  //gtk_progress_bar_pulse(GTK_PROGRESS_BAR (data));
  ProgressBar p = cast(ProgressBar)data;
  p.setPulseStep(0.1);
  p.pulse();
  p.pulse();
  p.pulse();

  /* Return true so the function will be called again; returning false removes
   * this timeout function.
   */
  return true;
}




int main (string[] args)
{
   Main.init(args);
   
   Window w = new Window("test");
   
   w.addOnHide(delegate void(Widget wid) {Main.exit(0);});
   
   ProgressBar p = new ProgressBar();
   p.setPulseStep(0.1);
   
  Timeout.add(100,cast(GSourceFunc)&update_progress_bar,cast(void*)p);

   w.add(p);
   w.showAll();
   
   Main.run();
   return 0;
}


Quote:
// or passing p : same problem


cast it to void, or when passing the struct, use the constructor for ProgressBar to turn it back into the object. since there is already an object associated with the struct the constructor will not create a new opject but rather return the same associated object.
Back to top
View user's profile Send private message
GG



Joined: 05 Nov 2009
Posts: 18

PostPosted: Sat Dec 12, 2009 11:34 pm    Post subject: Reply with quote

I forgot extern C at the beginning of the fonction.
Do we have to use extern C because the fonction is not implemented in D ? If I want to implement in D, is there a solution ? Convert into a delegate fonction maybe?

Thanks Mike for your support, I learned a lot this week.
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sun Dec 13, 2009 8:49 am    Post subject: Reply with quote

It has to be marked as extern(C) so that glib is able to call it.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group