[gnome-devel-docs] tutorials C: Progressbar sample/page
- From: Tiffany Antopolski <antopolski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs] tutorials C: Progressbar sample/page
- Date: Wed, 20 Jun 2012 19:28:52 +0000 (UTC)
commit 94522cb86d57394a10e0e946e04033d2946038a5
Author: Monica Kochofar <monicakochofar gmail com>
Date: Mon Jun 18 22:54:34 2012 -0400
tutorials C: Progressbar sample/page
platform-demos/C/progressbar.c.page | 14 +-------
platform-demos/C/samples/progressbar.c | 52 +++++++++++--------------------
2 files changed, 21 insertions(+), 45 deletions(-)
---
diff --git a/platform-demos/C/progressbar.c.page b/platform-demos/C/progressbar.c.page
index 944b58b..c207690 100644
--- a/platform-demos/C/progressbar.c.page
+++ b/platform-demos/C/progressbar.c.page
@@ -19,18 +19,8 @@
<title>ProgressBar</title>
- <media type="video" mime="application/ogv" src="media/progressbar.ogv">
- <tt:tt xmlns:tt="http://www.w3.org/ns/ttml">
- <tt:body>
- <tt:div begin="0s" end="6s">
- <tt:p>
- Pressing any key stops and starts this ProgressBar.
- </tt:p>
- </tt:div>
- </tt:body>
- </tt:tt>
- </media>
- <p>This ProgressBar is stopped and started by pressing any key.</p>
+ <media type="video" mime="application/ogv" src="media/progressbar_fill.ogv" />
+ <p>This ProgressBar "fills in" by a fraction of the bar until it is full.</p>
<code mime="text/x-csrc" style="numbered">
<xi:include href="samples/progressbar.c" parse="text"><xi:fallback/></xi:include></code>
diff --git a/platform-demos/C/samples/progressbar.c b/platform-demos/C/samples/progressbar.c
index 3bb0ef5..cd599be 100644
--- a/platform-demos/C/samples/progressbar.c
+++ b/platform-demos/C/samples/progressbar.c
@@ -1,39 +1,26 @@
#include <gtk/gtk.h>
-/*Global variable used to keep track of the progressbar's state*/
-guint sourceID;
-
-/*A function that pulses the progressbar once each time it is called*/
static gboolean
-pulse (gpointer user_data)
+fill (gpointer user_data)
{
GtkWidget *progress_bar = user_data;
- gtk_progress_bar_pulse (GTK_PROGRESS_BAR (progress_bar));
-
- return TRUE;
-}
-
-
+ /*Get the current progress*/
+ gdouble fraction;
+ fraction = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (progress_bar));
-/*A function that causes the progressbar to start pulsing, or stop, according
-to how many key-press-events have taken place*/
-static gboolean
-key_press_event (GtkWidget *widget,
- GdkEvent *event,
- gpointer user_data)
-{
- GtkWidget *progress_bar = user_data;
+ /*Increase the bar by 10% each time this function is called*/
+ fraction += 0.1;
- if (sourceID == 0)
- sourceID = g_timeout_add (100, pulse, GTK_PROGRESS_BAR (progress_bar));
- else {
- g_source_remove (sourceID);
- sourceID = 0;
- }
+ /*Fill in the bar with the new fraction*/
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), fraction);
- return TRUE;
+ /*Ensures that the fraction stays below 1.0*/
+ if (fraction < 1.0)
+ return TRUE;
+
+ return FALSE;
}
@@ -45,6 +32,8 @@ activate (GtkApplication *app,
GtkWidget *window;
GtkWidget *progress_bar;
+ gdouble fraction = 0.0;
+
/*Create a window with a title, and a default size*/
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "ProgressBar Example");
@@ -54,14 +43,11 @@ activate (GtkApplication *app,
progress_bar = gtk_progress_bar_new ();
gtk_container_add (GTK_CONTAINER (window), progress_bar);
- /*Use the created pulse function every 100 milliseconds*/
- sourceID = g_timeout_add (100, pulse, GTK_PROGRESS_BAR (progress_bar));
+ /*Fill in the given fraction of the bar. Has to be between 0.0-1.0 inclusive*/
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), fraction);
- /*connecting the key-press signal to the callback*/
- g_signal_connect (GTK_WINDOW (window),
- "key-press-event",
- G_CALLBACK (key_press_event),
- progress_bar);
+ /*Use the created fill function every 500 milliseconds*/
+ g_timeout_add (500, fill, GTK_PROGRESS_BAR (progress_bar));
gtk_widget_show_all (window);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]