|
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="scrolledwindow.py" xml:lang="fr">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">ScrolledWindow (Python)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.py#scrolling"/>
|
|
Packit |
1470ea |
<link type="next" xref="paned.py"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-05-26" 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>Ajoute des barres de défilement à son élément graphique enfant</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>ScrolledWindow</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/scrolledwindow.png"/>
|
|
Packit |
1470ea |
Une image dans une fenêtre avec barres de défilement.
|
|
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 |
from gi.repository import Gtk
|
|
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__(
|
|
Packit |
1470ea |
self, title="ScrolledWindow Example", application=app)
|
|
Packit |
1470ea |
self.set_default_size(200, 200)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# the scrolledwindow
|
|
Packit |
1470ea |
scrolled_window = Gtk.ScrolledWindow()
|
|
Packit |
1470ea |
scrolled_window.set_border_width(10)
|
|
Packit |
1470ea |
# there is always the scrollbar (otherwise: AUTOMATIC - only if needed
|
|
Packit |
1470ea |
# - or NEVER)
|
|
Packit |
1470ea |
scrolled_window.set_policy(
|
|
Packit |
1470ea |
Gtk.PolicyType.ALWAYS, Gtk.PolicyType.ALWAYS)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# an image - slightly larger than the window...
|
|
Packit |
1470ea |
image = Gtk.Image()
|
|
Packit |
1470ea |
image.set_from_file("gnome-image.png")
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# add the image to the scrolledwindow
|
|
Packit |
1470ea |
scrolled_window.add_with_viewport(image)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# add the scrolledwindow to the window
|
|
Packit |
1470ea |
self.add(scrolled_window)
|
|
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 |
</section>
|
|
Packit |
1470ea |
<section id="methods">
|
|
Packit |
1470ea |
<title>Méthodes utiles pour un élément graphique ScrolledWindow</title>
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item>La méthode set_policy(hscrollbar_policy, vscrollbar_policy) , où chaque argument est l'un des Gtk.Policy.AUTOMATIC, Gtk.Policy.ALWAYS, Gtk.Policy.NEVER , définit laquelle des barres de défilement verticale ou horizontale doit s'afficher. AUTOMATIC les affiche seulement si nécessaire, ALWAYS et NEVER les affichent respectivement toujours ou jamais. </item>
|
|
Packit |
1470ea |
<item>La méthode add_with_viewport(widget) est utilisé pour ajouter l'élément graphique Gtk.Widget widget , sans possibilité de défilement à l'intérieur de la fenêtre. </item>
|
|
Packit |
1470ea |
<item>La méthode set_placement(window_placement) organise le cadrage du contenu de la fenêtre en fonction de ses barres de défilement. Les options possibles des arguments sont : Gtk.CornerType.TOP_LEFT (par défaut, les barres de défilement sont en bas et à droite de la fenêtre), Gtk.CornerType.TOP_RIGHT, Gtk.CornerType.BOTTOM_LEFT, Gtk.CornerType.BOTTOM_RIGHT . </item>
|
|
Packit |
1470ea |
<item>Les méthodes set_hadjustment(ajustement) et set_vadjustment(ajustement) définissent l'ajustement Gtk.Adjustment. C'est la représentation d'une valeur avec une limite inférieure et supérieure, des incréments d'étape et de page, d'une taille de page et est construite sous la forme Gtk.Adjustment(valeur, inferieure, superieure, step_increment, page_increment, page_size) où les champs sont du type float . (Notez que step_increment n'est pas utilisé dans notre exemple et qu'il peut être défini à 0 ). </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
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/GtkScrolledWindow.html">GtkScrolledWindow</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/gtk3-Standard-Enumerations.html">Standard Enumerations</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkImage.html">GtkImage</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</page>
|