[gnome-devel-docs] tutorials python: example of progressbar



commit 4022b2e246795eeb603a0473ae2c5166a1e9fe1c
Author: Marta Maria Casetti <mmcasetti gmail com>
Date:   Fri May 25 09:56:21 2012 +0100

    tutorials python: example of progressbar

 platform-demos/C/progressbar.py.page    |   41 ++++++++++++++++++++++++
 platform-demos/C/samples/progressbar.py |   53 +++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/progressbar.py.page b/platform-demos/C/progressbar.py.page
new file mode 100644
index 0000000..f057fdc
--- /dev/null
+++ b/platform-demos/C/progressbar.py.page
@@ -0,0 +1,41 @@
+<page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
+      type="guide" style="task"
+      id="progressbar.py">
+  <info>
+    <link type="guide" xref="beginner.py#display-widgets"/>
+    <revision version="0.1" date="2012-05-25" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Marta Maria Casetti</name>
+      <email>mmcasetti gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>A widget which indicates progress visually.</desc>
+  </info>
+
+  <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>
+
+<code mime="text/x-python" style="numbered"><xi:include href="samples/progressbar.py" parse="text"><xi:fallback/></xi:include></code>
+<p>
+  In this sample we used the following:
+</p>
+<list>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkProgressBar.html";>GtkProgressBar</link></p></item>
+  <item><p><link href="http://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html";>GLib - The Main Event Loop</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gdk/stable/gdk-Keyboard-Handling";>Gdk - Key Values</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/samples/progressbar.py b/platform-demos/C/samples/progressbar.py
new file mode 100644
index 0000000..7fb5829
--- /dev/null
+++ b/platform-demos/C/samples/progressbar.py
@@ -0,0 +1,53 @@
+from gi.repository import GLib
+from gi.repository import Gtk
+import sys
+
+class MyWindow(Gtk.ApplicationWindow):
+    def __init__(self, app):
+        Gtk.Window.__init__(self, title="ProgressBar Example", application=app)
+        self.set_default_size(220, 20)
+
+        # a progressbar
+        progress_bar = Gtk.ProgressBar()
+        self.add(progress_bar)
+
+        self.bar = progress_bar
+
+        # the method pulse is called each 100 milliseconds
+        # and self.source_id is set to be the ID of the event source
+        # (the bar moves)
+        self.source_id = GLib.timeout_add(100, self.pulse)
+
+
+    # any signal from the keyboard controls if the progressbar stops/starts
+    def do_key_press_event(self, event):
+        # if the bar has been stopped (and source_id == 0 - see below),
+        # turn it back on
+        if (self.source_id == 0):
+            self.source_id = GLib.timeout_add(100, self.pulse)
+        # if the bar is moving, remove the source with the ID of source_id
+        # from the main context (stop the bar) and set the source_id to 0
+        else:
+            GLib.source_remove(self.source_id)
+            self.source_id = 0
+        return True
+
+    # the progressbar is in "activity mode"
+    def pulse(self):
+        self.bar.pulse()
+        return True
+
+class MyApplication(Gtk.Application):
+    def __init__(self):
+        Gtk.Application.__init__(self, application_id="org.example.spinner")
+
+    def do_activate(self):
+        win = MyWindow(self)
+        win.show_all()
+
+    def do_startup(self):
+        Gtk.Application.do_startup(self)
+
+app = MyApplication()
+exit_status = app.run(sys.argv)
+sys.exit(exit_status)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]