|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="GtkApplicationWindow.py" xml:lang="pt-BR">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">ApplicationWindow (Python)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.py#windows"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="properties.py"/>
|
|
Packit |
1470ea |
<link type="next" xref="image.py"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-06-10" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Tiffany Antopolski</name>
|
|
Packit |
1470ea |
<email its:translate="no">tiffany.antopolski@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
<credit type="author">
|
|
Packit |
1470ea |
<name>Marta Maria Casetti</name>
|
|
Packit |
1470ea |
<email its:translate="no">mmcasetti@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>GtkWindow subclass with GtkApplication support</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Rafael Ferreira</mal:name>
|
|
Packit |
1470ea |
<mal:email>rafael.f.f1@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2013</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>ApplicationWindow</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/window.png"/>
|
|
Packit |
1470ea |
The simplest GtkApplication Window which can support <link xref="gmenu.py"/>.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<links type="section"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="code">
|
|
Packit |
1470ea |
<title>Code used to generate this example</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
from gi.repository import Gtk
|
|
Packit |
1470ea |
import sys
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a Gtk ApplicationWindow
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyWindow(Gtk.ApplicationWindow):
|
|
Packit |
1470ea |
# constructor: the title is "Welcome to GNOME" and the window belongs
|
|
Packit |
1470ea |
# to the application app
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self, app):
|
|
Packit |
1470ea |
Gtk.Window.__init__(self, title="Welcome to GNOME", application=app)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyApplication(Gtk.Application):
|
|
Packit |
1470ea |
# constructor of the Gtk Application
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self):
|
|
Packit |
1470ea |
Gtk.Application.__init__(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# create and activate a MyWindow, with self (the MyApplication) as
|
|
Packit |
1470ea |
# application the window belongs to.
|
|
Packit |
1470ea |
# Note that the function in C activate() becomes do_activate() in Python
|
|
Packit |
1470ea |
def do_activate(self):
|
|
Packit |
1470ea |
win = MyWindow(self)
|
|
Packit |
1470ea |
# show the window and all its content
|
|
Packit |
1470ea |
# this line could go in the constructor of MyWindow as well
|
|
Packit |
1470ea |
win.show_all()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# start up the application
|
|
Packit |
1470ea |
# Note that the function in C startup() becomes do_startup() in Python
|
|
Packit |
1470ea |
def do_startup(self):
|
|
Packit |
1470ea |
Gtk.Application.do_startup(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# create and run the application, exit with the value returned by
|
|
Packit |
1470ea |
# running the program
|
|
Packit |
1470ea |
app = MyApplication()
|
|
Packit |
1470ea |
exit_status = app.run(sys.argv)
|
|
Packit |
1470ea |
sys.exit(exit_status)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
<section id="methods">
|
|
Packit |
1470ea |
<title>Useful methods for a Gtk.ApplicationWindow widget</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item>set_default_size(200, 100) sets the default size of the window to a width of 200 and a height of 100 ; if instead of a positive number we pass -1 we have the default size. </item>
|
|
Packit |
1470ea |
<item>set_position(Gtk.WindowPosition.CENTER) centers the window. Other options are Gtk.WindowPosition.NONE, Gtk.WindowPosition.MOUSE, Gtk.WindowPosition.CENTER_ALWAYS, Gtk.WindowPosition.CENTER_ON_PARENT . </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="references">
|
|
Packit |
1470ea |
<title>API References</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
In this sample we used the following:
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkApplication.html">GtkApplication</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkApplicationWindow.html">GtkApplicationWindow</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</page>
|