|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="progressbar.vala" xml:lang="ca">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">ProgressBar (Vala)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.vala#display-widgets"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-05-08" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Tiffany Antopolski</name>
|
|
Packit |
1470ea |
<email its:translate="no">tiffany.antopolski@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>A widget which indicates progress visually</desc>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>ProgressBar</title>
|
|
Packit |
1470ea |
<media type="video" mime="application/ogv" src="media/progressbar_fill.ogv"/>
|
|
Packit |
1470ea |
This ProgressBar "fills in" by a fraction of the bar until it is full.
|
|
Packit |
1470ea |
|
|
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 |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
In this sample we used the following:
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/gtk+-3.0/Gtk.ProgressBar.html">Gtk.ProgressBar</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://www.valadoc.org/glib-2.0/GLib.Timeout.html">GLib.Timeout</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</page>
|