|
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="fr">
|
|
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>Rapporte les messages d'information d'importance mineure pour l'utilisateur</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Luc Rebert,</mal:name>
|
|
Packit |
1470ea |
<mal:email>traduc@rebert.name</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011</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>Alain Lojewski,</mal:name>
|
|
Packit |
1470ea |
<mal:email>allomervan@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011-2012</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>Luc Pionchon</mal:name>
|
|
Packit |
1470ea |
<mal:email>pionchon.luc@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011</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>Bruno Brouard</mal:name>
|
|
Packit |
1470ea |
<mal:email>annoa.b@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011-12</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>Luis Menina</mal:name>
|
|
Packit |
1470ea |
<mal:email>liberforce@freeside.fr</mal:email>
|
|
Packit |
1470ea |
<mal:years>2014</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>Barre de statut</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/statusbar.png"/>
|
|
Packit |
1470ea |
Cette barre de statut vous informe si vous cliquez sur le bouton ou si vous appuyez sur n'importe quelle touche (et sur quelle touche).
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<links type="section"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="code">
|
|
Packit |
1470ea |
<title>Code utilisé pour générer cet exemple</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>La méthode Gdk.keyval_name(event.keyval) convertit la valeur des touches event.keyval en noms symboliques. Les noms et les valeurs correspondantes des touches se trouvent <link href="http://git.gnome.org/browse/gtk+/tree/gdk/gdkkeysyms.h">ici</link>. À titre d'exemple, GDK_KEY_BackSpace devient la chaîne « Retour arrière » . </note>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="methods">
|
|
Packit |
1470ea |
<title>Méthodes utiles pour un élément graphique BarreDeStatut</title>
|
|
Packit |
1470ea |
In line 17 the signal "clicked" is connected to the callback function button_clicked_cb() using widget.connect(signal, callback function) . See <link xref="signals-callbacks.py"/> for a more detailed explanation.
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item>La fonction pop(context_id) efface le premier message de la pile de la barre de statut avec le context_id donné. </item>
|
|
Packit |
1470ea |
<item>La méhode remove_all(context_id) efface tous les messages de la pile de la barre de statut ayant l'identifiant context_id donné. </item>
|
|
Packit |
1470ea |
<item>La méthode remove(context_id, message_id) efface le message de la pile de la barre de statut avec le context_id donné. Le message_id est renvoyé par push(context_id, lemessage) quand il pousse le message dans la barre des statut. </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="references">
|
|
Packit |
1470ea |
<title>Références API</title>
|
|
Packit |
1470ea |
Dans cet exemple, les éléments suivants sont utilisés :
|
|
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 - Key Values</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</page>
|