[gnome-devel-docs] tutorials python: example of toolbar
- From: Tiffany Antopolski <antopolski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs] tutorials python: example of toolbar
- Date: Fri, 8 Jun 2012 11:07:10 +0000 (UTC)
commit b2e26c4f05391b9287095669b2e392ca1ebb838e
Author: Marta Maria Casetti <mmcasetti gmail com>
Date: Tue Jun 5 15:04:59 2012 +0100
tutorials python: example of toolbar
platform-demos/C/samples/toolbar.py | 109 +++++++++++++++++++++++++++++++++++
platform-demos/C/toolbar.py.page | 40 +++++++++++++
platform-demos/Makefile.am | 2 +
3 files changed, 151 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/samples/toolbar.py b/platform-demos/C/samples/toolbar.py
new file mode 100644
index 0000000..a225d55
--- /dev/null
+++ b/platform-demos/C/samples/toolbar.py
@@ -0,0 +1,109 @@
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import Gio
+import sys
+
+class MyWindow(Gtk.ApplicationWindow):
+ def __init__(self, app):
+ Gtk.Window.__init__(self, title="Toolbar Example", application=app)
+ self.set_default_size(400, 200)
+
+ # a grid to attach the toolbar created in the method create_toolbar (see below)
+ grid = Gtk.Grid()
+ toolbar = self.create_toolbar()
+ toolbar.set_hexpand(True)
+ toolbar.show()
+ grid.attach(toolbar, 0, 0, 1, 1)
+ self.add(grid)
+
+ # create the actions that control the window and connect their signal to a
+ # callback method (see below)
+ undo_action = Gio.SimpleAction.new("undo", None)
+ undo_action.connect("activate", self.undo_callback)
+ self.add_action(undo_action)
+
+ fullscreen_action = Gio.SimpleAction.new("fullscreen", None)
+ fullscreen_action.connect("activate", self.fullscreen_callback)
+ self.add_action(fullscreen_action)
+
+
+ def create_toolbar(self):
+ toolbar = Gtk.Toolbar()
+
+ # set this as the primary toolbar of the application
+ toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR);
+
+ # create a button with a stock image
+ new_button = Gtk.ToolButton.new_from_stock(Gtk.STOCK_NEW)
+ # label is shown
+ new_button.set_is_important(True)
+ # insert the button at position in the toolbar
+ toolbar.insert(new_button, 0)
+ # show the button
+ new_button.show()
+ # set the name of the action associated with the button.
+ # The action controls the application (app)
+ new_button.set_action_name("app.new")
+
+ open_button = Gtk.ToolButton.new_from_stock(Gtk.STOCK_OPEN)
+ open_button.set_is_important(True)
+ toolbar.insert(open_button, 1)
+ open_button.show()
+ open_button.set_action_name("app.open")
+
+ undo_button = Gtk.ToolButton.new_from_stock(Gtk.STOCK_UNDO)
+ undo_button.set_is_important(True)
+ toolbar.insert(undo_button, 2)
+ undo_button.show()
+ undo_button.set_action_name("win.undo")
+
+ self.fullscreen_button = Gtk.ToolButton.new_from_stock(Gtk.STOCK_FULLSCREEN)
+ self.fullscreen_button.set_is_important(True)
+ toolbar.insert(self.fullscreen_button, 3)
+ self.fullscreen_button.set_action_name("win.fullscreen")
+
+ return toolbar
+
+ def undo_callback(self, action, parameter):
+ print "You clicked \"Undo\"."
+
+ def fullscreen_callback(self, action, parameter):
+ # check if the state is the same as Gdk.WindowState.FULLSCREEN, which is a bit flag
+ is_fullscreen = self.get_window().get_state() & Gdk.WindowState.FULLSCREEN != 0
+ if not is_fullscreen:
+ self.fullscreen_button.set_stock_id(Gtk.STOCK_LEAVE_FULLSCREEN)
+ self.fullscreen()
+ else:
+ self.fullscreen_button.set_stock_id(Gtk.STOCK_FULLSCREEN)
+ self.unfullscreen()
+
+class MyApplication(Gtk.Application):
+ def __init__(self):
+ Gtk.Application.__init__(self, application_id="org.example.toolbar")
+
+ def do_activate(self):
+ win = MyWindow(self)
+ win.show_all()
+
+ def do_startup(self):
+ Gtk.Application.do_startup(self)
+
+ # actions that control the application...
+ new_action = Gio.SimpleAction.new("new", None)
+ new_action.connect("activate", self.new_callback)
+ app.add_action(new_action)
+
+ open_action = Gio.SimpleAction.new("open", None)
+ open_action.connect("activate", self.open_callback)
+ app.add_action(open_action)
+
+ # ... and their callback methods
+ def new_callback(self, action, parameter):
+ print "You clicked \"New\"."
+
+ def open_callback(self, action, parameter):
+ print "You clicked \"Open\"."
+
+app = MyApplication()
+exit_status = app.run(sys.argv)
+sys.exit(exit_status)
diff --git a/platform-demos/C/toolbar.py.page b/platform-demos/C/toolbar.py.page
new file mode 100644
index 0000000..3314c17
--- /dev/null
+++ b/platform-demos/C/toolbar.py.page
@@ -0,0 +1,40 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<page xmlns="http://projectmallard.org/1.0/"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ type="guide" style="task"
+ id="toolbar.py">
+ <info>
+ <link type="guide" xref="beginner.py#menu-combo-toolbar"/>
+ <link type="seealso" xref="grid.py"/>
+ <revision version="0.1" date="2012-06-05" status="draft"/>
+
+ <credit type="author copyright">
+ <name>Marta Maria Casetti</name>
+ <email>mmcasetti gmail com</email>
+ <years>2012</years>
+ </credit>
+
+ <desc>A bar of buttons and other widgets</desc>
+ </info>
+
+ <title>Toolbar</title>
+
+ <media type="image" mime="image/png" src="media/toolbar.png"/>
+ <p>An example of toolbar with buttons (from stock icons).</p>
+
+<code mime="text/x-python" style="numbered"><xi:include href="samples/toolbar.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/GtkToolbar.html">GtkToolbar</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkToolButton.html">GtkToolButton</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkToolItem.html">GtkToolItem</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/gtk3-Stock-Items.html">Stock Items</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkActionable.html">GtkActionable</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkWidget.html">GtkWidget</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gdk3/3.4/gdk3-Event-Structures.html">Event Structures</link></p></item>
+</list>
+
+</page>
diff --git a/platform-demos/Makefile.am b/platform-demos/Makefile.am
index 97fc506..0b55ced 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -93,6 +93,7 @@ demo_sources = \
samples/togglebutton.py \
samples/togglebutton.vala \
samples/toolbar.js \
+ samples/toolbar.py \
samples/toolbar.vala \
samples/treeview_simple_liststore.py \
samples/treeview_simple_liststore.vala \
@@ -254,6 +255,7 @@ DOC_PAGES = \
togglebutton.py.page \
togglebutton.vala.page \
toolbar.js.page \
+ toolbar.py.page \
toolbar.vala.page \
treeview_simple_liststore.py.page \
treeview_simple_liststore.vala.page \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]