|
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="toolbar_builder.py" xml:lang="es">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">Barra de herramientas creada con Glade (Python)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.py#menu-combo-toolbar"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="toolbar.py"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="grid.py"/>
|
|
Packit |
1470ea |
<link type="next" xref="menubar.py"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-07-17" 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 |
|
|
Packit |
1470ea |
<credit type="author copyright edit">
|
|
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 |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Sebastian Pölsterl</name>
|
|
Packit |
1470ea |
<email its:translate="no">sebp@k-d-w.org</email>
|
|
Packit |
1470ea |
<years>2011</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>Una barra de botones y otros widgets</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Daniel Mustieles</mal:name>
|
|
Packit |
1470ea |
<mal:email>daniel.mustieles@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011 - 2017</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Nicolás Satragno</mal:name>
|
|
Packit |
1470ea |
<mal:email>nsatragno@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2012 - 2013</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Jorge González</mal:name>
|
|
Packit |
1470ea |
<mal:email>jorgegonz@svn.gnome.org</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>Barra de herramientas creada con Glade</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/toolbar.png"/>
|
|
Packit |
1470ea |
Este ejemplo es similar al de la <link xref="toolbar.py"/>, excepto que se usa Glade para crear la barra de herramientas en un archivo .ui XML.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<links type="sections"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="glade">
|
|
Packit |
1470ea |
<title>Crear la barra de herramientas con Glade</title>
|
|
Packit |
1470ea |
Para crear la barra de herramientas usando el <link href="http://glade.gnome.org/">diseñador de interfaces Glade</link>:
|
|
Packit |
1470ea |
<steps>
|
|
Packit |
1470ea |
<item>Abra Glade y guarde el archivo como <file>toolbar_builder.ui</file>
|
|
Packit |
1470ea |
<media type="image" src="media/glade_ui.png" width="900"> Captura de pantalla de la IU de Glade </media>
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<item>Bajo <gui>Contenedores</gui> en el lado izquierdo, pulse con el botón derecho en el icono de la barra de herramientas y seleccione <gui>Añadir widget como nivel superior</gui>.
|
|
Packit |
1470ea |
<media type="image" src="media/glade_select_toolbar.png"> Captura de pantalla del icono de la barra de herramientas en la IU de Glade </media>
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<item>Bajo la pestaña <gui>General</gui> en la parte inferior derecha, cambie el <gui>Nombre</gui> a <input>toolbar</input> y <gui>Mostrar flecha</gui> a <gui>No</gui>.
|
|
Packit |
1470ea |
<media type="image" src="media/glade_toolbar_general.png"> Captura de pantalla de la pestaña «General» </media>
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<item>Bajo la pestaña <gui>Comunes</gui>, establezca <gui>Expansión horizontal</gui> a <gui>Sí</gui>.
|
|
Packit |
1470ea |
<media type="image" src="media/glade_toolbar_common.png"> Captura de pantalla de la pestaña «Común» </media>
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<item>Pulse el botón derecho sobre la barra de herramientas en la parte superior derecha y seleccione <gui>Editar</gui>. La ventana <gui>Editor de barras de herramientas</gui> aparecerá.
|
|
Packit |
1470ea |
<media type="image" src="media/glade_toolbar_edit.png"> Captura de pantalla que muestra dónde pulsar el botón derecho para editar la barra de herramientas. </media>
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<item>Se quieren añadir 5 «ToolButton»: «New», «Open», «Undo», «Fullscreen», y «Leave Fullscreen». Primero, se añadirá el «ToolButton» «New».
|
|
Packit |
1470ea |
<steps>
|
|
Packit |
1470ea |
<item>Bajo la pestaña <gui>Jerarquía</gui>, pulse <gui>Añadir</gui>. </item>
|
|
Packit |
1470ea |
<item>Cambie el nombre del «ToolItem» a <input>new_button</input>. </item>
|
|
Packit |
1470ea |
<item>Deslícese hacia abajo y establezca <gui>Es Importante</gui> a <gui>Sí</gui>. Esto hará que la etiqueta del «ToolButton» se muestre cuando vea la barra de herramientas. </item>
|
|
Packit |
1470ea |
<item>Introduzca el <gui>Nombre de la acción</gui>: <input>app.new</input>. </item>
|
|
Packit |
1470ea |
<item>Cambie la <gui>Etiqueta</gui> a <input>New</input>. </item>
|
|
Packit |
1470ea |
<item>Seleccione el ID del inventario <gui>Nuevo</gui> desde el menú desplegable, o escriba <input>gtk-new</input>. </item>
|
|
Packit |
1470ea |
</steps>
|
|
Packit |
1470ea |
Repita los pasos anteriores para los «ToolButton» restantes, con las siguientes propiedades:
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Name
|
|
Packit |
1470ea |
Es importante
|
|
Packit |
1470ea |
Nombre de la acción
|
|
Packit |
1470ea |
Etiqueta
|
|
Packit |
1470ea |
ID del inventario
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
open_button
|
|
Packit |
1470ea |
Sí
|
|
Packit |
1470ea |
app.open
|
|
Packit |
1470ea |
Open
|
|
Packit |
1470ea |
gtk-open
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
undo_button
|
|
Packit |
1470ea |
Sí
|
|
Packit |
1470ea |
win.undo
|
|
Packit |
1470ea |
Undo
|
|
Packit |
1470ea |
gtk-undo
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
fullscreen_button
|
|
Packit |
1470ea |
Sí
|
|
Packit |
1470ea |
win.fullscreen
|
|
Packit |
1470ea |
Fullscreen
|
|
Packit |
1470ea |
gtk-fullscreen
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
leave_fullscreen_button
|
|
Packit |
1470ea |
Sí
|
|
Packit |
1470ea |
win.fullscreen
|
|
Packit |
1470ea |
Leave Fullscreen
|
|
Packit |
1470ea |
gtk-leave-fullscreen
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<media type="image" src="media/glade_toolbar_editor.png">
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</media>
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<item>Cierre el <gui>Editor de la barra de herramientas</gui>.
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<item>No se quiere que se vea el «ToolButton» <gui>Salir de pantalla completa</gui> cuando el programa se inicie por primera vez, dado que la aplicación no estará en modo pantalla completa. Puede establecer esto en la pestaña <gui>Comunes</gui>, pulsando <gui>No</gui> en la propiedad <gui>Visible</gui>. El «ToolButton» aparecerá de todos modos en el diseñador de interfaces, pero se comportará correctamente cuando se cargue el archivo en el código de su programa. Tenga en cuenta que el método <gui>show_all()</gui> anularía esta opción, por lo que en el código se tiene que usar <gui>show()</gui> en todos los elementos por separado.
|
|
Packit |
1470ea |
<media type="image" src="media/glade_visible_no.png"> Establecer la propiedad «visible» a «No» </media>
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<item>Guarde su trabajo y cierre Glade.
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<item>El archivo XML generado por Glade se muestra debajo. Este es la descripción de la barra de herramientas. En el momento en el que se escribe esto, la opción para añadir la clase «Gtk.STYLE_CLASS_PRIMARY_TOOLBAR» en el diseñador de interfaces Glade no existe. Se puede añadir manualmente al archivo XML. Para hacer esto, añada el siguiente código XML en la línea 9 de <file>toolbar_builder.ui</file>:
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<style>
|
|
Packit |
1470ea |
<class name="primary-toolbar"/>
|
|
Packit |
1470ea |
</style>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Si no añade esto, el programa seguirá funcionando bien. La barra de herramientas resultante se verá, sin embargo, ligeramente distinta a la de la captura de pantalla en la parte superior de esta página.
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
</steps>
|
|
Packit |
1470ea |
<?xml version="1.0" encoding="UTF-8"?>
|
|
Packit |
1470ea |
<interface>
|
|
Packit |
1470ea |
<!-- interface-requires gtk+ 3.0 -->
|
|
Packit |
1470ea |
<object class="GtkToolbar" id="toolbar">
|
|
Packit |
1470ea |
<property name="visible">True</property>
|
|
Packit |
1470ea |
<property name="can_focus">False</property>
|
|
Packit |
1470ea |
<property name="hexpand">True</property>
|
|
Packit |
1470ea |
<property name="show_arrow">False</property>
|
|
Packit |
1470ea |
<child>
|
|
Packit |
1470ea |
<object class="GtkToolButton" id="new_button">
|
|
Packit |
1470ea |
<property name="use_action_appearance">False</property>
|
|
Packit |
1470ea |
<property name="visible">True</property>
|
|
Packit |
1470ea |
<property name="can_focus">False</property>
|
|
Packit |
1470ea |
<property name="use_action_appearance">False</property>
|
|
Packit |
1470ea |
<property name="is_important">True</property>
|
|
Packit |
1470ea |
<property name="action_name">app.new</property>
|
|
Packit |
1470ea |
<property name="label" translatable="yes">New</property>
|
|
Packit |
1470ea |
<property name="use_underline">True</property>
|
|
Packit |
1470ea |
<property name="stock_id">gtk-new</property>
|
|
Packit |
1470ea |
</object>
|
|
Packit |
1470ea |
<packing>
|
|
Packit |
1470ea |
<property name="expand">False</property>
|
|
Packit |
1470ea |
<property name="homogeneous">True</property>
|
|
Packit |
1470ea |
</packing>
|
|
Packit |
1470ea |
</child>
|
|
Packit |
1470ea |
<child>
|
|
Packit |
1470ea |
<object class="GtkToolButton" id="open_button">
|
|
Packit |
1470ea |
<property name="use_action_appearance">False</property>
|
|
Packit |
1470ea |
<property name="visible">True</property>
|
|
Packit |
1470ea |
<property name="can_focus">False</property>
|
|
Packit |
1470ea |
<property name="use_action_appearance">False</property>
|
|
Packit |
1470ea |
<property name="is_important">True</property>
|
|
Packit |
1470ea |
<property name="action_name">app.open</property>
|
|
Packit |
1470ea |
<property name="label" translatable="yes">Open</property>
|
|
Packit |
1470ea |
<property name="use_underline">True</property>
|
|
Packit |
1470ea |
<property name="stock_id">gtk-open</property>
|
|
Packit |
1470ea |
</object>
|
|
Packit |
1470ea |
<packing>
|
|
Packit |
1470ea |
<property name="expand">False</property>
|
|
Packit |
1470ea |
<property name="homogeneous">True</property>
|
|
Packit |
1470ea |
</packing>
|
|
Packit |
1470ea |
</child>
|
|
Packit |
1470ea |
<child>
|
|
Packit |
1470ea |
<object class="GtkToolButton" id="undo_button">
|
|
Packit |
1470ea |
<property name="use_action_appearance">False</property>
|
|
Packit |
1470ea |
<property name="visible">True</property>
|
|
Packit |
1470ea |
<property name="can_focus">False</property>
|
|
Packit |
1470ea |
<property name="use_action_appearance">False</property>
|
|
Packit |
1470ea |
<property name="is_important">True</property>
|
|
Packit |
1470ea |
<property name="action_name">win.undo</property>
|
|
Packit |
1470ea |
<property name="label" translatable="yes">Undo</property>
|
|
Packit |
1470ea |
<property name="use_underline">True</property>
|
|
Packit |
1470ea |
<property name="stock_id">gtk-undo</property>
|
|
Packit |
1470ea |
</object>
|
|
Packit |
1470ea |
<packing>
|
|
Packit |
1470ea |
<property name="expand">False</property>
|
|
Packit |
1470ea |
<property name="homogeneous">True</property>
|
|
Packit |
1470ea |
</packing>
|
|
Packit |
1470ea |
</child>
|
|
Packit |
1470ea |
<child>
|
|
Packit |
1470ea |
<object class="GtkToolButton" id="fullscreen_button">
|
|
Packit |
1470ea |
<property name="use_action_appearance">False</property>
|
|
Packit |
1470ea |
<property name="visible">True</property>
|
|
Packit |
1470ea |
<property name="can_focus">False</property>
|
|
Packit |
1470ea |
<property name="use_action_appearance">False</property>
|
|
Packit |
1470ea |
<property name="is_important">True</property>
|
|
Packit |
1470ea |
<property name="action_name">win.fullscreen</property>
|
|
Packit |
1470ea |
<property name="label" translatable="yes">Fullscreen</property>
|
|
Packit |
1470ea |
<property name="use_underline">True</property>
|
|
Packit |
1470ea |
<property name="stock_id">gtk-fullscreen</property>
|
|
Packit |
1470ea |
</object>
|
|
Packit |
1470ea |
<packing>
|
|
Packit |
1470ea |
<property name="expand">False</property>
|
|
Packit |
1470ea |
<property name="homogeneous">True</property>
|
|
Packit |
1470ea |
</packing>
|
|
Packit |
1470ea |
</child>
|
|
Packit |
1470ea |
<child>
|
|
Packit |
1470ea |
<object class="GtkToolButton" id="leave_fullscreen_button">
|
|
Packit |
1470ea |
<property name="use_action_appearance">False</property>
|
|
Packit |
1470ea |
<property name="can_focus">False</property>
|
|
Packit |
1470ea |
<property name="use_action_appearance">False</property>
|
|
Packit |
1470ea |
<property name="is_important">True</property>
|
|
Packit |
1470ea |
<property name="action_name">win.fullscreen</property>
|
|
Packit |
1470ea |
<property name="label" translatable="yes">Leave Fullscreen</property>
|
|
Packit |
1470ea |
<property name="use_underline">True</property>
|
|
Packit |
1470ea |
<property name="stock_id">gtk-leave-fullscreen</property>
|
|
Packit |
1470ea |
</object>
|
|
Packit |
1470ea |
<packing>
|
|
Packit |
1470ea |
<property name="expand">False</property>
|
|
Packit |
1470ea |
<property name="homogeneous">True</property>
|
|
Packit |
1470ea |
</packing>
|
|
Packit |
1470ea |
</child>
|
|
Packit |
1470ea |
</object>
|
|
Packit |
1470ea |
</interface>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="code">
|
|
Packit |
1470ea |
<title>Código usado para generar este ejemplo</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Ahora se crea el código siguiente, que añade la barra de herramientas desde el archivo que se acaba de crear.
|
|
Packit |
1470ea |
from gi.repository import Gtk
|
|
Packit |
1470ea |
from gi.repository import Gdk
|
|
Packit |
1470ea |
from gi.repository import Gio
|
|
Packit |
1470ea |
import sys
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyWindow(Gtk.ApplicationWindow):
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self, app):
|
|
Packit |
1470ea |
Gtk.Window.__init__(self, title="Toolbar Example", application=app)
|
|
Packit |
1470ea |
self.set_default_size(400, 200)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a grid to attach the toolbar (see below)
|
|
Packit |
1470ea |
grid = Gtk.Grid()
|
|
Packit |
1470ea |
self.add(grid)
|
|
Packit |
1470ea |
# we have to show the grid (and therefore the toolbar) with show(),
|
|
Packit |
1470ea |
# as show_all() would show also the buttons in the toolbar that we want to
|
|
Packit |
1470ea |
# be hidden (such as the leave_fullscreen button)
|
|
Packit |
1470ea |
grid.show()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a builder to add the UI designed with Glade to the grid:
|
|
Packit |
1470ea |
builder = Gtk.Builder()
|
|
Packit |
1470ea |
# get the file (if it is there)
|
|
Packit |
1470ea |
try:
|
|
Packit |
1470ea |
builder.add_from_file("toolbar_builder.ui")
|
|
Packit |
1470ea |
except:
|
|
Packit |
1470ea |
print("file not found")
|
|
Packit |
1470ea |
sys.exit()
|
|
Packit |
1470ea |
# and attach it to the grid
|
|
Packit |
1470ea |
grid.attach(builder.get_object("toolbar"), 0, 0, 1, 1)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# two buttons that will be used later in a method
|
|
Packit |
1470ea |
self.fullscreen_button = builder.get_object("fullscreen_button")
|
|
Packit |
1470ea |
self.leave_fullscreen_button = builder.get_object(
|
|
Packit |
1470ea |
"leave_fullscreen_button")
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# create the actions that control the window, connect their signal to a
|
|
Packit |
1470ea |
# callback method (see below), add the action to the window:
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# undo
|
|
Packit |
1470ea |
undo_action = Gio.SimpleAction.new("undo", None)
|
|
Packit |
1470ea |
undo_action.connect("activate", self.undo_callback)
|
|
Packit |
1470ea |
self.add_action(undo_action)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# and fullscreen
|
|
Packit |
1470ea |
fullscreen_action = Gio.SimpleAction.new("fullscreen", None)
|
|
Packit |
1470ea |
fullscreen_action.connect("activate", self.fullscreen_callback)
|
|
Packit |
1470ea |
self.add_action(fullscreen_action)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# callback for undo
|
|
Packit |
1470ea |
def undo_callback(self, action, parameter):
|
|
Packit |
1470ea |
print("You clicked \"Undo\".")
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# callback for fullscreen
|
|
Packit |
1470ea |
def fullscreen_callback(self, action, parameter):
|
|
Packit |
1470ea |
# check if the state is the same as Gdk.WindowState.FULLSCREEN, which
|
|
Packit |
1470ea |
# is a bit flag
|
|
Packit |
1470ea |
is_fullscreen = self.get_window().get_state(
|
|
Packit |
1470ea |
) & Gdk.WindowState.FULLSCREEN != 0
|
|
Packit |
1470ea |
if is_fullscreen:
|
|
Packit |
1470ea |
self.unfullscreen()
|
|
Packit |
1470ea |
self.leave_fullscreen_button.hide()
|
|
Packit |
1470ea |
self.fullscreen_button.show()
|
|
Packit |
1470ea |
else:
|
|
Packit |
1470ea |
self.fullscreen()
|
|
Packit |
1470ea |
self.fullscreen_button.hide()
|
|
Packit |
1470ea |
self.leave_fullscreen_button.show()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyApplication(Gtk.Application):
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self):
|
|
Packit |
1470ea |
Gtk.Application.__init__(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_activate(self):
|
|
Packit |
1470ea |
win = MyWindow(self)
|
|
Packit |
1470ea |
# show the window - with show() not show_all() because that would show also
|
|
Packit |
1470ea |
# the leave_fullscreen button
|
|
Packit |
1470ea |
win.show()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_startup(self):
|
|
Packit |
1470ea |
Gtk.Application.do_startup(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# actions that control the application: create, connect their signal to a
|
|
Packit |
1470ea |
# callback method (see below), add the action to the application
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# new
|
|
Packit |
1470ea |
new_action = Gio.SimpleAction.new("new", None)
|
|
Packit |
1470ea |
new_action.connect("activate", self.new_callback)
|
|
Packit |
1470ea |
app.add_action(new_action)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# open
|
|
Packit |
1470ea |
open_action = Gio.SimpleAction.new("open", None)
|
|
Packit |
1470ea |
open_action.connect("activate", self.open_callback)
|
|
Packit |
1470ea |
app.add_action(open_action)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# callback for new
|
|
Packit |
1470ea |
def new_callback(self, action, parameter):
|
|
Packit |
1470ea |
print("You clicked \"New\".")
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# callback for open
|
|
Packit |
1470ea |
def open_callback(self, action, parameter):
|
|
Packit |
1470ea |
print("You clicked \"Open\".")
|
|
Packit |
1470ea |
|
|
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 |
|
|
Packit |
1470ea |
<section id="methods">
|
|
Packit |
1470ea |
<title>Métodos útiles para Gtk.Builder</title>
|
|
Packit |
1470ea |
Para ver los métodos útiles de un widget de barra de herramientas, consulte la <link xref="toolbar.py"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Gtk.Builder construye una interfaz desde una definición UI XML.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item>add_from_file(filename) carga y procesa el archivo dado y lo une con el contenido actual del Gtk.Builder. </item>
|
|
Packit |
1470ea |
<item>add_from_string(string) procesa la cadena dada y la une con el contenido actual del Gtk.Builder. </item>
|
|
Packit |
1470ea |
<item>add_objects_from_file(filename, object_ids) es igual a add_from_file() , pero solo carga los objetos con los ID dados en la lista de object_id . </item>
|
|
Packit |
1470ea |
<item>add_objects_from_string(string, object_ids) es lo mismo que add_from_string() , pero sólo carga los objetos con los ID dados en la lista de object_id . </item>
|
|
Packit |
1470ea |
<item>get_object(object_id) obtiene el widget con el ID object_id de los objetos cargados en el constructor. </item>
|
|
Packit |
1470ea |
<item>get_objects() devuelve todos los objetos cargados. </item>
|
|
Packit |
1470ea |
<item>connect_signals(handler_object) conecta las señales a los métodos dados en el handler_object . Este puede ser cualquier objeto que contenga claves o atributos que se llamen como los nombres del manejador de señales dados en la descripción de la interfaz, por ejemplo una clase o un diccionario. En la línea 39 la señal "activate" de la acción undo_action se conecta a la función de retorno de llamada undo_callback() usando action.connect(señal, función de retorno de llamada) . Consulte la <link xref="signals-callbacks.py"/> para una explicación más detallada.
|
|
Packit |
1470ea |
</item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="references">
|
|
Packit |
1470ea |
<title>Referencias de la API</title>
|
|
Packit |
1470ea |
En este ejemplo se usa lo siguiente:
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkGrid.html">GtkGrid</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkBuilder.html">GtkBuilder</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkWidget.html">GtkWidget</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gdk3/unstable/gdk3-Event-Structures.html#GdkEventWindowState">Estructuras de eventos</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</page>
|