|
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="progressbar.py" xml:lang="fr">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">ProgressBar (Python)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.py#display-widgets"/>
|
|
Packit |
1470ea |
<link type="next" xref="spinbutton.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>Un élément graphique qui matérialise visuellement la progression.</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 progression</title>
|
|
Packit |
1470ea |
<media type="video" mime="application/ogv" src="media/progressbar.ogv">
|
|
Packit |
1470ea |
<tt:tt xmlns:tt="http://www.w3.org/ns/ttml">
|
|
Packit |
1470ea |
<tt:body>
|
|
Packit |
1470ea |
<tt:div begin="0s" end="6s">
|
|
Packit |
1470ea |
<tt:p>L'appui sur n'importe quelle touche démarre et arrête la barre de progression (ProgressBar).</tt:p>
|
|
Packit |
1470ea |
</tt:div>
|
|
Packit |
1470ea |
</tt:body>
|
|
Packit |
1470ea |
</tt:tt>
|
|
Packit |
1470ea |
</media>
|
|
Packit |
1470ea |
Pour démarrer ou arrêter cette barre de progression, appuyez sur n'importe 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 GLib
|
|
Packit |
1470ea |
from gi.repository import Gtk
|
|
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="ProgressBar Example", application=app)
|
|
Packit |
1470ea |
self.set_default_size(220, 20)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a progressbar
|
|
Packit |
1470ea |
self.progress_bar = Gtk.ProgressBar()
|
|
Packit |
1470ea |
# add the progressbar to the window
|
|
Packit |
1470ea |
self.add(self.progress_bar)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# the method self.pulse is called each 100 milliseconds
|
|
Packit |
1470ea |
# and self.source_id is set to be the ID of the event source
|
|
Packit |
1470ea |
# (i.e. the bar changes position every 100 milliseconds)
|
|
Packit |
1470ea |
self.source_id = GLib.timeout_add(100, self.pulse)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# event handler
|
|
Packit |
1470ea |
# any signal from the keyboard controls if the progressbar stops/starts
|
|
Packit |
1470ea |
def do_key_press_event(self, event):
|
|
Packit |
1470ea |
# if the progressbar has been stopped (therefore source_id == 0 - see
|
|
Packit |
1470ea |
# "else" below), turn it back on
|
|
Packit |
1470ea |
if (self.source_id == 0):
|
|
Packit |
1470ea |
self.source_id = GLib.timeout_add(100, self.pulse)
|
|
Packit |
1470ea |
# if the bar is moving, remove the source with the ID of source_id
|
|
Packit |
1470ea |
# from the main context (stop the bar) and set the source_id to 0
|
|
Packit |
1470ea |
else:
|
|
Packit |
1470ea |
GLib.source_remove(self.source_id)
|
|
Packit |
1470ea |
self.source_id = 0
|
|
Packit |
1470ea |
# stop the signal emission
|
|
Packit |
1470ea |
return True
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# source function
|
|
Packit |
1470ea |
# the progressbar is in "activity mode" when this method is called
|
|
Packit |
1470ea |
def pulse(self):
|
|
Packit |
1470ea |
self.progress_bar.pulse()
|
|
Packit |
1470ea |
# call the function again
|
|
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 |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="methods">
|
|
Packit |
1470ea |
<title>Méthodes utiles pour un élément graphique barre de progression</title>
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item>Contrairement à pulse() , qui fait avancer ou reculer la barre, si nous voulons que notre barre de progression se remplisse par fractions (un nombre flottant float compris entre 0.0 et 1.0 inclus) toujours dans le même sens, nous utilisons la méthode set_fraction(fraction) . </item>
|
|
Packit |
1470ea |
<item>To set a text and show it (superimposed over the bar) use set_text("text") and set_show_text(True) . If a text is not set and set_show_text(True) the text will be the percentage of the work that has been completed. </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/GtkProgressBar.html">GtkProgressBar</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html">GLib - The Main Event Loop</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gdk/stable/gdk-Keyboard-Handling">Gdk - Key Values</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</page>
|