[gnome-devel-docs] tutorials python: commented samples and more detailed pages for windows samples
- From: Tiffany Antopolski <antopolski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs] tutorials python: commented samples and more detailed pages for windows samples
- Date: Thu, 14 Jun 2012 15:39:14 +0000 (UTC)
commit 7b48c07ba0d032e14649f1b41a1c6b86a9862c44
Author: Marta Maria Casetti <mmcasetti gmail com>
Date: Mon Jun 11 21:50:11 2012 +0100
tutorials python: commented samples and more detailed pages for windows samples
https://bugzilla.gnome.org/show_bug.cgi?id=677897
platform-demos/C/GtkApplicationWindow.py.page | 30 ++++++---
platform-demos/C/aboutdialog.py.page | 23 ++++---
platform-demos/C/dialog.py.page | 21 +++++-
platform-demos/C/messagedialog.py.page | 33 +++++++++-
platform-demos/C/samples/GtkApplicationWindow.py | 21 +++++--
platform-demos/C/samples/aboutdialog.py | 64 +++++++++++--------
platform-demos/C/samples/dialog.py | 44 ++++++++-----
platform-demos/C/samples/messagedialog.py | 74 +++++++++++++---------
platform-demos/C/samples/window.py | 13 +++-
platform-demos/C/window.py.page | 53 ++++++++++------
10 files changed, 250 insertions(+), 126 deletions(-)
---
diff --git a/platform-demos/C/GtkApplicationWindow.py.page b/platform-demos/C/GtkApplicationWindow.py.page
index 4e6ba91..68751d2 100644
--- a/platform-demos/C/GtkApplicationWindow.py.page
+++ b/platform-demos/C/GtkApplicationWindow.py.page
@@ -5,13 +5,18 @@
id="GtkApplicationWindow.py">
<info>
<link type="guide" xref="beginner.py#windows"/>
- <revision version="0.1" date="2012-04-07" status="draft"/>
+ <revision version="0.1" date="2012-06-10" status="draft"/>
<credit type="author copyright">
<name>Tiffany Antopolski</name>
<email>tiffany antopolski gmail com</email>
<years>2012</years>
</credit>
+ <credit type="author">
+ <name>Marta Maria Casetti</name>
+ <email>mmcasetti gmail com</email>
+ <years>2012</years>
+ </credit>
<desc>GtkWindow subclass with GtkApplication support</desc>
</info>
@@ -20,12 +25,19 @@
<media type="image" mime="image/png" src="media/window.png"/>
<p>The simplest GtkApplication Window which can support Menus.</p>
-<code mime="text/x-python" style="numbered"><xi:include href="samples/GtkApplicationWindow.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/GtkApplication.html">GtkApplication</link></p></item>
- <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkApplicationWindow.html">GtkApplicationWindow</link></p></item>
-</list>
+ <code mime="text/x-python" style="numbered"><xi:include href="samples/GtkApplicationWindow.py" parse="text"><xi:fallback/></xi:include></code>
+ <p>
+ Useful methods for a Gtk.ApplicationWindow widget (to be used in the class MyWindow with self. or in the function do_activate() with win.):
+ </p>
+ <list>
+ <item><p><code>self.set_default_size(200, 100)</code> sets the default size of the window to a width of <code>200</code> and a height of <code>100</code>; if instead of a positive number we pass <code>-1</code> we have the default size.</p></item>
+ <item><p><code>self.set_position(Gtk.WindowPosition.CENTER)</code> centers the window. Other options are described in the <link href="http://developer.gnome.org/gtk3/3.4/gtk3-Standard-Enumerations.html#GtkWindowPosition">standard enumerations</link> (with the caveat that they should be changed on the model of Gtk.WindowPosition.CENTER).</p></item>
+ </list>
+ <p>
+ In this sample we used the following:
+ </p>
+ <list>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkApplication.html">GtkApplication</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkApplicationWindow.html">GtkApplicationWindow</link></p></item>
+ </list>
</page>
diff --git a/platform-demos/C/aboutdialog.py.page b/platform-demos/C/aboutdialog.py.page
index 6efce85..e47839c 100644
--- a/platform-demos/C/aboutdialog.py.page
+++ b/platform-demos/C/aboutdialog.py.page
@@ -5,7 +5,7 @@
id="aboutdialog.py">
<info>
<link type="guide" xref="beginner.py#windows"/>
- <revision version="0.1" date="2012-05-21" status="draft"/>
+ <revision version="0.1" date="2012-06-11" status="draft"/>
<credit type="author copyright">
<name>Marta Maria Casetti</name>
@@ -20,14 +20,15 @@
<media type="image" mime="image/png" src="media/aboutdialog_GMenu.png"/>
<p>An AboutDialog example using Gtk.ApplicationWindow and Menu (the "about" is displayed if "About" in the menu is selected).</p>
-<code mime="text/x-python" style="numbered">
-<xi:include href="samples/aboutdialog.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/GtkApplication.html">GtkApplication</link></p></item>
- <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkApplicationWindow.html">GtkApplicationWindow</link></p></item>
- <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkAboutDialog.html">GtkAboutDialog</link></p></item>
-</list>
+ <code mime="text/x-python" style="numbered"><xi:include href="samples/aboutdialog.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/GtkAboutDialog.html">GtkAboutDialog</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkApplicationWindow.html">GtkApplicationWindow</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gio/stable/GMenu.html">GMenu</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkApplication.html">GtkApplication</link></p></item>
+ </list>
</page>
diff --git a/platform-demos/C/dialog.py.page b/platform-demos/C/dialog.py.page
index 579b389..8d5788e 100644
--- a/platform-demos/C/dialog.py.page
+++ b/platform-demos/C/dialog.py.page
@@ -5,7 +5,7 @@
id="dialog.py">
<info>
<link type="guide" xref="beginner.py#windows"/>
- <revision version="0.1" date="2012-04-07" status="stub"/>
+ <revision version="0.1" date="2012-06-11" status="draft"/>
<credit type="author copyright">
<name>Marta Maria Casetti</name>
@@ -18,9 +18,22 @@
<title>Dialog</title>
<media type="image" mime="image/png" src="media/dialog.png"/>
- <p>A dialog with the response signal hooked up to a callback function.</p>
+ <p>A dialog with the response signal connected to a callback function.</p>
- <code mime="text/x-python" style="numbered">
-<xi:include href="samples/dialog.py" parse="text"><xi:fallback/></xi:include></code>
+ <code mime="text/x-python" style="numbered"><xi:include href="samples/dialog.py" parse="text"><xi:fallback/></xi:include></code>
+ <p>
+ Useful methods for a Dialog widget:
+ </p>
+ <list>
+ <item><p>Instead of <code>dialog.set_modal(True)</code> we could have <code>dialog.set_modal(False)</code> followed by <code>dialog.set_destroy_with_parent(True)</code> that would destroy the dialog window if the main window is closed.</p></item>
+ <item><p><code>dialog.add_button(button_text="The Answer", response_id=42)</code>, where <code>42</code> is any integer, is an alternative to <code>dialog.add_button(button_text="text", response_id=Gtk.ResponseType.RESPONSE)</code>, where <code>RESPONSE</code> could be one of <code>OK, CANCEL, CLOSE, YES, NO, APPLY, HELP</code>, which in turn correspond to the integers <code>-5, -6,..., -11</code>.</p></item>
+ </list>
+ <p>
+ In this sample we used the following:
+ </p>
+ <list>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkDialog.html">GtkDialog</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkWindow.html">GtkWindow</link></p></item>
+ </list>
</page>
diff --git a/platform-demos/C/messagedialog.py.page b/platform-demos/C/messagedialog.py.page
index 8bc1959..6bcd0b9 100644
--- a/platform-demos/C/messagedialog.py.page
+++ b/platform-demos/C/messagedialog.py.page
@@ -5,7 +5,7 @@
id="messagedialog.py">
<info>
<link type="guide" xref="beginner.py#windows"/>
- <revision version="0.1" date="2012-04-07" status="stub"/>
+ <revision version="0.1" date="2012-06-11" status="draft"/>
<credit type="author copyright">
<name>Marta Maria Casetti</name>
@@ -20,5 +20,34 @@
<media type="image" mime="image/png" src="media/messagedialog.png"/>
<p>A message dialog which prints messages on the terminal, depending on your choices.</p>
-<code mime="text/x-python" style="numbered"><xi:include href="samples/messagedialog.py" parse="text"><xi:fallback/></xi:include></code>
+ <code mime="text/x-python" style="numbered"><xi:include href="samples/messagedialog.py" parse="text"><xi:fallback/></xi:include></code>
+
+ <p>
+ Useful methods for a MessageDialog widget:
+ </p>
+ <list>
+ <item><p>In the constructor of MessageDialog we could set flags as <code>Gtk.DialogFlags.DESTROY_WITH_PARENT</code> (to destroy the messagedialog window when its parent window is destroyed) or as <code>Gtk.DialogFlags.MODAL</code> (no interaction with other windows of the application).</p></item>
+ <item><p>In the constructor of MessageDialog we could set type as any of <code>Gtk.MessageType.INFO, Gtk.MessageType.WARNING, Gtk.MessageType.QUESTION, Gtk.MessageType.ERROR, Gtk.MessageType.OTHER</code> depending on what type of message we want.</p></item>
+ <item><p>In the constructor of MessageDialog we could set buttons as any of <code>Gtk.ButtonsType.NONE, Gtk.ButtonsType.OK, Gtk.ButtonsType.CLOSE, Gtk.ButtonsType.CANCEL, Gtk.ButtonsType.YES_NO, Gtk.ButtonsType.OK_CANCEL</code>, or any button using <code>messagedialog.add_button()</code> as in Gtk.Dialog.</p></item>
+ <item><p>We could substitute the default image of the MessageDialog with another image using</p>
+ <code mime="text/x-python" style="numbered">
+image = Gtk.Image()
+image.set_from_stock(Gtk.STOCK_CAPS_LOCK_WARNING, Gtk.IconSize.DIALOG)
+image.show()
+messagedialog.set_image(image)</code>
+ <p>where <code>Gtk.STOCK_CAPS_LOCK_WARNING</code> is any image from <link href="http://developer.gnome.org/gtk3/3.4/gtk3-Stock-Items.html">Stock Items</link>. We could also set any image as in the Image widget, as <code>image.set_from_file("filename.png")</code>.</p></item>
+ <item><p><code>messagedialog.format_secondary_text("some secondary message")</code> sets a secondary message. The primary text becomes bold.</p></item>
+ </list>
+ <p>
+ In this sample we used the following:
+ </p>
+ <list>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkMessageDialog.html">GtkMessageDialog</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkDialog.html">GtkDialog</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkWindow.html">GtkWindow</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gio/stable/GSimpleAction.html">GSimpleAction</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gio/unstable/GActionMap.html">GActionMap</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gio/stable/GMenu.html">GMenu</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkApplication.html">GtkApplication</link></p></item>
+ </list>
</page>
diff --git a/platform-demos/C/samples/GtkApplicationWindow.py b/platform-demos/C/samples/GtkApplicationWindow.py
index 13ed58a..f24d394 100644
--- a/platform-demos/C/samples/GtkApplicationWindow.py
+++ b/platform-demos/C/samples/GtkApplicationWindow.py
@@ -1,23 +1,34 @@
-from gi.repository import GLib
from gi.repository import Gtk
-from gi.repository import Gio
import sys
+# a Gtk ApplicationWindow
class MyWindow(Gtk.ApplicationWindow):
+ # constructor: the title is "Welcome to GNOME" and the window belongs
+ # to the application app
def __init__(self, app):
Gtk.Window.__init__(self, title="Welcome to GNOME", application=app)
class MyApplication(Gtk.Application):
+ # constructor of the Gtk Application
def __init__(self):
- Gtk.Application.__init__(self, application_id="org.gtk.example.grid")
+ Gtk.Application.__init__(self)
+ # create and activate a MyWindow, with self (the MyApplication) as
+ # application the window belongs to.
+ # Note that the function in C activate() becomes do_activate() in Python
def do_activate(self):
win = MyWindow(self)
+ # show the window and all its content
+ # this line could go in the constructor of MyWindow as well
win.show_all()
- def do_startup (self):
- Gtk.Application.do_startup (self)
+ # start up the application
+ # Note that the function in C startup() becomes do_startup() in Python
+ def do_startup(self):
+ Gtk.Application.do_startup(self)
+# create and run the application, exit with the value returned by
+# running the program
app = MyApplication()
exit_status = app.run(sys.argv)
sys.exit(exit_status)
diff --git a/platform-demos/C/samples/aboutdialog.py b/platform-demos/C/samples/aboutdialog.py
index 6462e21..f2312b1 100644
--- a/platform-demos/C/samples/aboutdialog.py
+++ b/platform-demos/C/samples/aboutdialog.py
@@ -1,68 +1,80 @@
-from gi.repository import GLib
from gi.repository import Gtk
from gi.repository import Gio
import sys
-
-# This is the window
+
class MyWindow(Gtk.ApplicationWindow):
-
- #constructor
+
+ # constructor for a window (the parent window)
def __init__(self, app):
Gtk.Window.__init__(self, title="AboutDialog Example", application=app)
self.set_default_size(200, 200)
-
- # We create the message_action and connect the
- # signal and add the action to the application.
+
+ # create the about_action (a Gio.SimpleAction)
about_action = Gio.SimpleAction.new("about", None)
+ # connect the signal from the action to the function about_cb()
about_action.connect("activate", self.about_cb)
+ # add the action to the application
app.add_action(about_action)
- self.show_all()
+ # callback function for the signal "about" from the action in the menu of the main window
def about_cb(self, action, parameter):
+ # a Gtk.AboutDialog
aboutdialog = Gtk.AboutDialog()
-
- #lists of authors and documenters (will be used later)
- authors = ["GNOME Documentation Team", None]
- documenters = ["GNOME Documentation Team", None]
-
+
+ # lists of authors and documenters (will be used later)
+ authors = ["GNOME Documentation Team"]
+ documenters = ["GNOME Documentation Team"]
+
+ # we fill in the aboutdialog
aboutdialog.set_program_name("AboutDialog Example")
aboutdialog.set_copyright("Copyright \xc2\xa9 2012 GNOME Documentation Team")
aboutdialog.set_authors(authors)
aboutdialog.set_documenters(documenters)
aboutdialog.set_website("http://developer.gnome.org")
aboutdialog.set_website_label("GNOME Developer Website")
-
- # to close the aboutdialog when "close" is clicked
+
+ # we do not want to show the title, which by default would be "About AboutDialog Example"
+ # we have to reset the title of the messagedialog window after setting the program name
+ aboutdialog.set_title("")
+
+ # to close the aboutdialog when "close" is clicked we connect the
+ # "response" signal to on_close
aboutdialog.connect("response", self.on_close)
-
+ # show the aboutdialog
aboutdialog.show()
-
+
+ # destroy the aboutdialog
def on_close(self, action, parameter):
action.destroy()
class MyApplication(Gtk.Application):
def __init__(self):
- Gtk.Application.__init__(self, application_id="org.gtk.example.grid")
-
+ Gtk.Application.__init__(self)
+
def do_activate(self):
win = MyWindow(self)
win.show_all()
-
+
def quit_cb(self, action, parameter):
self.quit()
-
+
def do_startup (self):
- Gtk.Application.do_startup (self)
-
+ Gtk.Application.do_startup(self)
+
+ # create a menu (a Gio.Menu)
menu = Gio.Menu()
+ # append a menu item with label "About" and action "app.about"
menu.append ("About", "app.about")
+ # append a menu item with label "Quit" and action "app.quit"
menu.append("Quit", "app.quit")
+ # set menu as the menu for the application
self.set_app_menu (menu)
-
+
+ # a new simpleaction - for the application
quit_action = Gio.SimpleAction.new("quit", None)
quit_action.connect("activate", self.quit_cb)
self.add_action(quit_action)
-
+
app = MyApplication()
exit_status = app.run(sys.argv)
sys.exit(exit_status)
diff --git a/platform-demos/C/samples/dialog.py b/platform-demos/C/samples/dialog.py
index 3c45f3e..335c794 100644
--- a/platform-demos/C/samples/dialog.py
+++ b/platform-demos/C/samples/dialog.py
@@ -1,45 +1,57 @@
-from gi.repository import GLib
from gi.repository import Gtk
-from gi.repository import Gio
import sys
class MyWindow(Gtk.ApplicationWindow):
+ # construct a window (the parent window)
def __init__(self, app):
Gtk.Window.__init__(self, title="GNOME Button", application=app)
self.set_default_size(250, 50)
-
+
+ # a button on the parent window
button = Gtk.Button("Click me")
+ # connect the signal "clicked" of the button with the function on_button_click()
button.connect("clicked", self.on_button_click)
+ # add the button to the window
self.add(button)
- button.show()
-
- def on_button_click(self, *args):
- dialog = Gtk.Dialog("A Gtk+ Dialog", self, Gtk.DialogFlags.MODAL)
+
+ # callbck function for the signal "clicked" of the button in the parent window
+ def on_button_click(self, widget):
+ # create a Gtk.Dialog
+ dialog = Gtk.Dialog()
+ dialog.set_title("A Gtk+ Dialog")
+ # The window defined in the constructor (self) is the parent of the dialog.
+ # Furthermore, the dialog is on top of the parent window
+ dialog.set_transient_for(self)
+ # set modal true: no interaction with other windows of the application
+ dialog.set_modal(True)
+ # add a button to the dialog window
dialog.add_button(button_text="OK", response_id=Gtk.ResponseType.OK)
- # otherwise, we can add buttons as
- # dialog.add_button(button_text="Another button", response_id=42)
- # where the response_id is any integer
+ # connect the "response" signal (the button has been clicked) to the function on_response()
+ dialog.connect("response", self.on_response)
+
+ # get the content area of the dialog, add a label to it
content_area = dialog.get_content_area()
label = Gtk.Label("This demonstrates a dialog with a label")
content_area.add(label)
- label.show()
- dialog.connect("response", self.on_response)
+ # show the dialog
dialog.show_all()
-
+
def on_response(self, widget, response_id):
print "response_id is", response_id
+ # destroy the widget (the dialog) when the function on_response() is called
+ # (that is, when the button of the dialog has been clicked)
widget.destroy()
-
+
class MyApplication(Gtk.Application):
def __init__(self):
- Gtk.Application.__init__(self, application_id="org.gtk.example.grid")
+ Gtk.Application.__init__(self)
def do_activate(self):
win = MyWindow(self)
win.show_all()
def do_startup (self):
- Gtk.Application.do_startup (self)
+ Gtk.Application.do_startup(self)
app = MyApplication()
exit_status = app.run(sys.argv)
diff --git a/platform-demos/C/samples/messagedialog.py b/platform-demos/C/samples/messagedialog.py
index ce4ac3d..6e81923 100644
--- a/platform-demos/C/samples/messagedialog.py
+++ b/platform-demos/C/samples/messagedialog.py
@@ -1,66 +1,80 @@
-from gi.repository import GLib
from gi.repository import Gtk
from gi.repository import Gio
import sys
-
-# This is the window
+
class MyWindow(Gtk.ApplicationWindow):
-
- #constructor
+
+ # constructor for a window (the parent window) with a label
def __init__(self, app):
Gtk.Window.__init__(self, title="GMenu Example", application=app)
+ self.set_default_size(400, 200)
label = Gtk.Label()
label.set_text("This application goes boom!")
self.add(label)
- self.set_default_size(400, 200)
-
- # We create the message_action and connect the
- # signal and add the action to the application.
+
+ # create the message_action (a Gio.SimpleAction) - for the window
message_action = Gio.SimpleAction.new("message", None)
+ # connect the signal from the action to the function message_cb()
message_action.connect("activate", self.message_cb)
- app.add_action (message_action)
+ # add the action to the application
+ app.add_action(message_action)
+
+ # callback function for the signal "activate" from the message_action
+ # in the menu of the parent window
+ def message_cb(self, action, parameter):
+ # a Gtk.MessageDialog
+ messagedialog = Gtk.MessageDialog(parent=self,
+ flags=Gtk.DialogFlags.MODAL,
+ type=Gtk.MessageType.WARNING,
+ buttons=Gtk.ButtonsType.OK_CANCEL,
+ message_format="This action will cause the universe to stop existing.")
+ # connect the response (of the button clicked) to the function
+ # dialog_response()
+ messagedialog.connect("response", self.dialog_response)
+ # show the messagedialog
+ messagedialog.show()
def dialog_response(self, widget, response_id):
+ # if the button clicked gives response OK (-5)
if response_id == Gtk.ResponseType.OK:
print "*boom*"
+ # if the button clicked gives response CANCEL (-6)
elif response_id == Gtk.ResponseType.CANCEL:
print "good choice"
+ # if the messagedialog is destroyed (by pressing ESC)
elif response_id == Gtk.ResponseType.DELETE_EVENT:
print "dialog closed or cancelled"
+ # finally, destroy the messagedialog
widget.destroy()
-
- def message_cb(self, action, parameter):
- messagedialog = Gtk.MessageDialog (self,
- Gtk.DialogFlags.MODAL,
- Gtk.MessageType.WARNING,
- Gtk.ButtonsType.OK_CANCEL,
- "This action will cause the universe to stop existing.")
- messagedialog.connect("response", self.dialog_response)
- messagedialog.show()
-
+
class MyApplication(Gtk.Application):
def __init__(self):
- Gtk.Application.__init__(self, application_id="org.gtk.example.grid")
-
+ Gtk.Application.__init__(self)
+
def do_activate(self):
win = MyWindow(self)
win.show_all()
-
+
def quit_cb(self, action, parameter):
self.quit()
-
+
def do_startup (self):
- Gtk.Application.do_startup (self)
-
+ Gtk.Application.do_startup(self)
+
+ # create a menu (a Gio.Menu)
menu = Gio.Menu()
- menu.append ("Message", "app.message")
+ # append a menu item with label "Message" and action "app.message"
+ menu.append("Message", "app.message")
+ # append a menu item with label "Quit" and action "app.quit"
menu.append("Quit", "app.quit")
- self.set_app_menu (menu)
-
+ # set menu as the menu for the application
+ self.set_app_menu(menu)
+
+ # a new simpleaction - for the application
quit_action = Gio.SimpleAction.new("quit", None)
quit_action.connect("activate", self.quit_cb)
self.add_action (quit_action)
-
+
app = MyApplication()
exit_status = app.run(sys.argv)
sys.exit(exit_status)
diff --git a/platform-demos/C/samples/window.py b/platform-demos/C/samples/window.py
index 2317455..7532cc2 100644
--- a/platform-demos/C/samples/window.py
+++ b/platform-demos/C/samples/window.py
@@ -1,10 +1,17 @@
from gi.repository import Gtk
import sys
-class MyApp(Gtk.Application):
+class MyApplication(Gtk.Application):
def do_activate(self):
- window = Gtk.Window(application = self)
+ # create a Gtk Window belonging to the application itself
+ window = Gtk.Window(application=self)
+ # set the title
window.set_title("Welcome to GNOME")
+ # show the window
window.show_all()
-MyApp(application_id = "org.example.whatever").run(sys.argv)
+# create and run the application, exit with the value returned by
+# running the program
+app = MyApplication()
+exit_status = app.run(sys.argv)
+sys.exit(exit_status)
diff --git a/platform-demos/C/window.py.page b/platform-demos/C/window.py.page
index 9295c3b..94227ba 100644
--- a/platform-demos/C/window.py.page
+++ b/platform-demos/C/window.py.page
@@ -5,37 +5,50 @@
id="window.py">
<info>
<link type="guide" xref="beginner.py#windows"/>
- <revision version="0.1" date="2012-04-07" status="stub"/>
+ <revision version="0.2" date="2012-06-09" status="draft"/>
<credit type="author copyright">
<name>Tiffany Antopolski</name>
<email>tiffany antopolski gmail com</email>
<years>2012</years>
</credit>
+ <credit type="author">
+ <name>Marta Maria Casetti</name>
+ <email>mmcasetti gmail com</email>
+ <years>2012</years>
+ </credit>
<desc>A toplevel window which can contain other widgets</desc>
</info>
<title>Window</title>
-<table>
- <tr>
- <td>
- <media type="image" mime="image/png" src="media/window.png"/>
- <p>A minimal Gtk+ Application.</p>
- </td>
- <td>
- <p>Use <link xref="GtkApplicationWindow.py">Application Window</link> if you need GMenu support.</p>
- </td>
- </tr>
-</table>
+ <table>
+ <tr>
+ <td>
+ <media type="image" mime="image/png" src="media/window.png"/>
+ <p>A minimal Gtk+ Application: a window with a title.</p>
+ </td>
+ <td>
+ <p>Use <link xref="GtkApplicationWindow.py">Application Window</link> if you need GMenu support.</p>
+ </td>
+ </tr>
+ </table>
-<code mime="text/x-python" style="numbered"><xi:include href="samples/window.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/GtkApplication.html">Gtk.Application</link></p></item>
- <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkWindow.html">Gtk.Window</link></p></item>
-</list>
+ <code mime="text/x-python" style="numbered"><xi:include href="samples/window.py" parse="text"><xi:fallback/></xi:include></code>
+ <p>
+ Useful methods for a Window widget:
+ </p>
+ <list>
+ <item><p><code>window = Gtk.Window(application=self, title="Welcome to GNOME")</code> sets the title as well, without the need for the line <code>window.set_title("Welcome to GNOME")</code>.</p></item>
+ <item><p><code>window.set_default_size(200, 100)</code> sets the default size of the window to a width of <code>200</code> and a height of <code>100</code>; if instead of a positive number we pass <code>-1</code> we have the default size.</p></item>
+ <item><p><code>window.set_position(Gtk.WindowPosition.CENTER)</code> centers the window. Other options are described in the <link href="http://developer.gnome.org/gtk3/3.4/gtk3-Standard-Enumerations.html#GtkWindowPosition">standard enumerations</link> (with the caveat that they should be changed on the model of Gtk.WindowPosition.CENTER).</p></item>
+ </list>
+ <p>
+ In this sample we used the following:
+ </p>
+ <list>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkApplication.html">GtkApplication</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkWindow.html">GtkWindow</link></p></item>
+ </list>
</page>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]