|
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="statusbar.py" xml:lang="es">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">Statusbar (Python)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.py#display-widgets"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="signals-callbacks.py"/>
|
|
Packit |
1470ea |
<link type="next" xref="spinner.py"/>
|
|
Packit |
1470ea |
<revision version="0.2" date="2012-06-12" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
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>Enviar mensajes de menor importancia al usuario</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>Statusbar</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/statusbar.png"/>
|
|
Packit |
1470ea |
Esta barra de estado indica si ha pulsado el botón o si ha pulsado una tecla (y qué tecla ha pulsado).
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<links type="section"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="code">
|
|
Packit |
1470ea |
<title>Código usado para generar este ejemplo</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
from gi.repository import Gtk
|
|
Packit |
1470ea |
from gi.repository import Gdk
|
|
Packit |
1470ea |
import sys
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyWindow(Gtk.ApplicationWindow):
|
|
Packit |
1470ea |
# a window
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self, app):
|
|
Packit |
1470ea |
Gtk.Window.__init__(self, title="StatusBar Example", application=app)
|
|
Packit |
1470ea |
self.set_default_size(200, 100)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a label
|
|
Packit |
1470ea |
label = Gtk.Label(label="Press any key or ")
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a button
|
|
Packit |
1470ea |
button = Gtk.Button(label="click me.")
|
|
Packit |
1470ea |
# connected to a callback
|
|
Packit |
1470ea |
button.connect("clicked", self.button_clicked_cb)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# the statusbar
|
|
Packit |
1470ea |
self.statusbar = Gtk.Statusbar()
|
|
Packit |
1470ea |
# its context_id - not shown in the UI but needed to uniquely identify
|
|
Packit |
1470ea |
# the source of a message
|
|
Packit |
1470ea |
self.context_id = self.statusbar.get_context_id("example")
|
|
Packit |
1470ea |
# we push a message onto the statusbar's stack
|
|
Packit |
1470ea |
self.statusbar.push(
|
|
Packit |
1470ea |
self.context_id, "Waiting for you to do something...")
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a grid to attach the widgets
|
|
Packit |
1470ea |
grid = Gtk.Grid()
|
|
Packit |
1470ea |
grid.set_column_spacing(5)
|
|
Packit |
1470ea |
grid.set_column_homogeneous(True)
|
|
Packit |
1470ea |
grid.set_row_homogeneous(True)
|
|
Packit |
1470ea |
grid.attach(label, 0, 0, 1, 1)
|
|
Packit |
1470ea |
grid.attach_next_to(button, label, Gtk.PositionType.RIGHT, 1, 1)
|
|
Packit |
1470ea |
grid.attach(self.statusbar, 0, 1, 2, 1)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# add the grid to the window
|
|
Packit |
1470ea |
self.add(grid)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# callback function for the button clicked
|
|
Packit |
1470ea |
# if the button is clicked the event is signaled to the statusbar
|
|
Packit |
1470ea |
# onto which we push a new status
|
|
Packit |
1470ea |
def button_clicked_cb(self, button):
|
|
Packit |
1470ea |
self.statusbar.push(self.context_id, "You clicked the button.")
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# event handler
|
|
Packit |
1470ea |
def do_key_press_event(self, event):
|
|
Packit |
1470ea |
# any signal from the keyboard is signaled to the statusbar
|
|
Packit |
1470ea |
# onto which we push a new status with the symbolic name
|
|
Packit |
1470ea |
# of the key pressed
|
|
Packit |
1470ea |
self.statusbar.push(self.context_id, Gdk.keyval_name(event.keyval) +
|
|
Packit |
1470ea |
" key was pressed.")
|
|
Packit |
1470ea |
# stop the signal emission
|
|
Packit |
1470ea |
return True
|
|
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 |
win.show_all()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_startup(self):
|
|
Packit |
1470ea |
Gtk.Application.do_startup(self)
|
|
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 |
<note>Gdk.keyval_name(event.keyval) convierte el valor de la tecla event.keyval en un nombre simbólico. Los nombres y los valores de teclas correspondientes pueden encontrarse <link href="http://git.gnome.org/browse/gtk+/tree/gdk/gdkkeysyms.h">aquí</link>, pero por ejemplo GDK_KEY_BackSpace se convierte en la cadena "BackSpace" . </note>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="methods">
|
|
Packit |
1470ea |
<title>Métodos útiles para un widget «Statusbar»</title>
|
|
Packit |
1470ea |
En la línea 17, la señal «clicked» se conecta a la función de retorno de llamada button_clicked_cb() usando widget.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 |
<list>
|
|
Packit |
1470ea |
<item>pop(id_del_contexto) elimina el primer mensaje en la pila de la barra de estado con el id_del_contexto dado. </item>
|
|
Packit |
1470ea |
<item>remove_all(id_del_contexto) elimina todos los mensajes en la pila de la barra de estado con el id_del_contexto dado. </item>
|
|
Packit |
1470ea |
<item>remove(id_del_contexto, id_del_mensaje) elimina el mensaje con el id_del_mensaje dado en la pila de la barra de estado con el id_del_contexto dado. push(id_del_contexto, "el mensaje") devuelve el id_del_mensaje cuando se muestra el mensaje en la barra de estado. </item>
|
|
Packit |
1470ea |
</list>
|
|
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/GtkStatusbar.html">GtkStatusbar</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gdk/stable/gdk-Keyboard-Handling.html">Gdk: valores de teclas</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</page>
|