[Vala] Setting up a timer with callback event



Hello every one.
I want to write some animation in my program.
I want to be able to activate it or cancel it where ever I want.
My basic program structure looks like this:

using Gtk;

public class MyApp {

 private Window window;
private uint timerID;

public MyApp () throws Error {
 var builder = new Builder ();
builder.add_from_file ("gui.ui");
 builder.connect_signals (this);
this.window = builder.get_object ("win_main") as Window;
 this.window.destroy += Gtk.main_quit;
}

 public void run () {
this.window.show_all ();
Gtk.main ();
 }
}

//This should activate the timer.
  [CCode (instance_pos = -1)]
  public void on_btnActivate_clicked (Button source) {
       timerID = Timeout.add(1000, SourceFunc);
  }

//This should deactivate the timer..
  [CCode (instance_pos = -1)]
  public void on_btnDeactivate_clicked (Button source) {
       Source.remove(timerID);
  }

//Timer listener
[CCode (instance_pos = -1)]
public delegate bool SourceFunc ()
  {
      return true;
  }

int main (string[] args) {
Gtk.init (ref args);
 try {
var app = new MyApp ();
app.run ();
 } catch (Error e) {
stderr.printf ("Could not load UI: %s\n", e.message);
 return 1;
}
return 0;
}

I need help to fix this code so I can setup a timer properly....
I don't sure what is wrong with my code....


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