Blame platform-demos/C/samples/progressbar.vala
|
Packit |
1470ea |
public class MyApplication : Gtk.Application {
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Gtk.ProgressBar progress_bar;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
protected override void activate () {
|
|
Packit |
1470ea |
var window = new Gtk.ApplicationWindow (this);
|
|
Packit |
1470ea |
window.set_title ("ProgressBar Example");
|
|
Packit |
1470ea |
window.set_default_size (220, 20);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
progress_bar = new Gtk.ProgressBar ();
|
|
Packit |
1470ea |
window.add (progress_bar);
|
|
Packit |
1470ea |
window.show_all ();
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
double fraction = 0.0;
|
|
Packit |
1470ea |
progress_bar.set_fraction (fraction);
|
|
Packit |
1470ea |
GLib.Timeout.add (500, fill);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
bool fill () {
|
|
Packit |
1470ea |
double fraction = progress_bar.get_fraction (); //get current progress
|
|
Packit |
1470ea |
fraction += 0.1; //increase by 10% each time this function is called
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
progress_bar.set_fraction (fraction);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/* This function is only called by GLib.Timeout.add while it returns true; */
|
|
Packit |
1470ea |
if (fraction < 1.0)
|
|
Packit |
1470ea |
return true;
|
|
Packit |
1470ea |
return false;
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
public int main (string[] args) {
|
|
Packit |
1470ea |
var progress_bar_application = new MyApplication ();
|
|
Packit |
1470ea |
int status = progress_bar_application.run (args);
|
|
Packit |
1470ea |
return status;
|
|
Packit |
1470ea |
}
|