שימו לב שמבנה הממשק הגרפי שמור בקובץ - gui.ui ואנו פשוט שולפים אותו משם... לכן לא תוכלו להריץ את הדוגמא בלי שתצרו אחד משלכם...
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, on_timer_event);
}
//This should deactivate the timer..
[CCode (instance_pos = -1)]
public void on_btnDeactivate_clicked (Button source) {
Source.remove (timerID);
}
//Timer listener
public bool on_timer_event () {
stdout.printf ("timer event");
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;
}
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, on_timer_event);
}
//This should deactivate the timer..
[CCode (instance_pos = -1)]
public void on_btnDeactivate_clicked (Button source) {
Source.remove (timerID);
}
//Timer listener
public bool on_timer_event () {
stdout.printf ("timer event");
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;
}



