[gnome-devel-docs] tutorials python: example of a statusbar



commit 4291e86706ac0e720d933160389e001de42379c4
Author: Marta Maria Casetti <mmcasetti gmail com>
Date:   Fri May 25 10:52:03 2012 +0100

    tutorials python: example of a statusbar

 platform-demos/C/samples/statusbar.py |   62 +++++++++++++++++++++++++++++++++
 platform-demos/C/statusbar.py.page    |   33 +++++++++++++++++
 2 files changed, 95 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/samples/statusbar.py b/platform-demos/C/samples/statusbar.py
new file mode 100644
index 0000000..529bbf2
--- /dev/null
+++ b/platform-demos/C/samples/statusbar.py
@@ -0,0 +1,62 @@
+from gi.repository import Gtk
+from gi.repository import Gdk
+import sys
+
+class MyWindow(Gtk.ApplicationWindow):
+    def __init__(self, app):
+        Gtk.Window.__init__(self, title="StatusBar Example", application=app)
+        self.set_default_size(200, 100)
+
+        # a label
+        label = Gtk.Label(label="Press any key or ")
+
+        # a button
+        button = Gtk.Button(label="click me.")
+        # connected to a callback
+        button.connect("clicked", self.button_clicked_cb)
+
+        # the statusbar (the context_id is not shown in the UI but it is needed)
+        statusbar = Gtk.Statusbar()
+        context_id = statusbar.get_context_id("example")
+        # pushed a new message onto the statusbar's stack
+        statusbar.push(context_id, "Waiting for you to do something...")
+
+        # a grid to attach the widgets
+        grid = Gtk.Grid()
+        grid.set_column_spacing(5)
+        grid.set_column_homogeneous(True)
+        grid.set_row_homogeneous(True)
+        grid.attach(label, 1, 1, 1, 1)
+        grid.attach_next_to(button, label, Gtk.PositionType.RIGHT, 1, 1)
+        grid.attach(statusbar, 1, 2, 2, 1)
+
+        self.add(grid)
+
+        self.bar = statusbar
+        self.id = context_id
+
+    # if the button is clicked the event is signaled to the statusbar
+    # onto which we push a new status
+    def button_clicked_cb(self, button):
+        self.bar.push(self.id, "You clicked the button.")
+
+    # any signal from the keyboard is signaled to the statusbar
+    # onto which we push a new status
+    def do_key_press_event(self, event):
+        self.bar.push(self.id, Gdk.keyval_name(event.keyval) + " key was pressed.")
+        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)
diff --git a/platform-demos/C/statusbar.py.page b/platform-demos/C/statusbar.py.page
new file mode 100644
index 0000000..86ed8a7
--- /dev/null
+++ b/platform-demos/C/statusbar.py.page
@@ -0,0 +1,33 @@
+<page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
+      type="guide" style="task"
+      id="statusbar.py">
+  <info>
+    <link type="guide" xref="beginner.py#display-widgets"/>
+    <link type="seealso" xref="grid.py"/>
+    <link type="seealso" xref="button.py"/>
+    <link type="seealso" xref="label.py"/>
+    <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>Report messages of minor importance to the user</desc>
+  </info>
+
+  <title>Statusbar</title>
+  <media type="image" mime="image/png" src="media/statusbar.png"/>
+  <p>This statusbar tells you if you click the button or if you press any key (and which key).</p>
+
+<code mime="text/x-python" style="numbered"><xi:include href="samples/statusbar.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/GtkStatusbar.html";>GtkStatusbar</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gdk/stable/gdk-Keyboard-Handling.html";>Gdk - Key Values</link></p></item>
+</list>
+</page>



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