[pygtk] Add a gtk.InfoBar demo



commit a744feaed3dd56c85ac730f5114ff705c8bd067a
Author: John Stowers <john stowers gmail com>
Date:   Sat May 8 12:14:59 2010 +1200

    Add a gtk.InfoBar demo

 examples/Makefile.am                 |    3 +-
 examples/pygtk-demo/demos/infobar.py |   87 ++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+), 1 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 2edce6b..268b223 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -89,7 +89,8 @@ demo_PYTHON = \
 	pygtk-demo/demos/tree_store.py		\
 	pygtk-demo/demos/treemodel.py		\
 	pygtk-demo/demos/statusicon.py		\
-	pygtk-demo/demos/ui_manager.py
+	pygtk-demo/demos/ui_manager.py		\
+	pygtk-demo/demos/infobar.py
 
 demoimg_DATA = \
 	pygtk-demo/demos/images/alphatest.png		\
diff --git a/examples/pygtk-demo/demos/infobar.py b/examples/pygtk-demo/demos/infobar.py
new file mode 100644
index 0000000..b4a5440
--- /dev/null
+++ b/examples/pygtk-demo/demos/infobar.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+'''Info Bar
+
+is a widget that can be used to show messages to the user without showing a 
+dialog. It is often temporarily shown at the top or bottom of a document.
+'''
+# pygtk version: John Stowers <john stowers gmail com>
+
+import gtk
+
+class InfoBarDemo(gtk.Window):
+    def __init__(self, parent=None):
+        gtk.Window.__init__(self)
+        try:
+            self.set_screen(parent.get_screen())
+        except AttributeError:
+            self.connect('destroy', lambda *w: gtk.main_quit())
+        self.set_title(self.__class__.__name__)
+        self.set_border_width(8)
+
+        vb = gtk.VBox()
+        self.add(vb)
+
+        bar = gtk.InfoBar()
+        vb.pack_start(bar, False, False)
+        bar.set_message_type(gtk.MESSAGE_INFO)
+        bar.get_content_area().pack_start(
+                gtk.Label("This is an info bar with message type GTK_MESSAGE_INFO"),
+                False, False)
+
+        bar = gtk.InfoBar()
+        vb.pack_start(bar, False, False)
+        bar.set_message_type(gtk.MESSAGE_WARNING)
+        bar.get_content_area().pack_start(
+                gtk.Label("This is an info bar with message type GTK_MESSAGE_WARNING"),
+                False, False)
+
+        bar = gtk.InfoBar()
+        bar.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
+        bar.connect("response", self._on_bar_response)
+        vb.pack_start(bar, False, False)
+        bar.set_message_type(gtk.MESSAGE_QUESTION)
+        bar.get_content_area().pack_start(
+                gtk.Label("This is an info bar with message type GTK_MESSAGE_QUESTION"),
+                False, False)
+
+        bar = gtk.InfoBar()
+        vb.pack_start(bar, False, False)
+        bar.set_message_type(gtk.MESSAGE_ERROR)
+        bar.get_content_area().pack_start(
+                gtk.Label("This is an info bar with message type GTK_MESSAGE_ERROR"),
+                False, False)
+
+        bar = gtk.InfoBar()
+        vb.pack_start(bar, False, False)
+        bar.set_message_type(gtk.MESSAGE_OTHER)
+        bar.get_content_area().pack_start(
+                gtk.Label("This is an info bar with message type GTK_MESSAGE_OTHER"),
+                False, False)
+
+        frame = gtk.Frame("Info bars")
+        vb.pack_start(frame, False, False, 8)
+        vb2 = gtk.VBox(spacing=8)
+        vb2.set_border_width(8)
+        frame.add(vb2)
+        vb2.pack_start(gtk.Label("An example of different info bars"), False, False)
+
+        self.show_all()
+
+    def _on_bar_response(self, button, response_id):
+        dialog = gtk.MessageDialog(
+                        self,
+                        gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT,
+                        gtk.MESSAGE_INFO,
+                        gtk.BUTTONS_OK,
+                        "You clicked a button on an info bar")
+        dialog.format_secondary_text("Your response has id %d" % response_id)
+        dialog.run()
+        dialog.destroy()
+
+
+def main():
+    InfoBarDemo()
+    gtk.main()
+
+if __name__ == '__main__':
+    main()



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