ProgressBar

This ProgressBar "fills in" by a fraction of the bar until it is full.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
public class MyApplication : Gtk.Application {

	Gtk.ProgressBar progress_bar;

	protected override void activate () {
		var window = new Gtk.ApplicationWindow (this);
		window.set_title ("ProgressBar Example");
		window.set_default_size (220, 20);

		progress_bar = new Gtk.ProgressBar ();
		window.add (progress_bar);
		window.show_all ();

		double fraction = 0.0;
		progress_bar.set_fraction (fraction);
		GLib.Timeout.add (500, fill);
	}

	bool fill () {
		double fraction = progress_bar.get_fraction (); //get current progress
		fraction += 0.1; //increase by 10% each time this function is called

		progress_bar.set_fraction (fraction);

		/* This function is only called by GLib.Timeout.add while it returns true; */
		if (fraction < 1.0)
			return true;
		return false;
	}
}

public int main (string[] args) {
	var progress_bar_application = new MyApplication ();
	int status =  progress_bar_application.run (args);
	return status;
}

In this sample we used the following: