Blame platform-demos/gl/scrolledwindow.py.page

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="gl">
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>Engade barras de desprazamento no seu widget fillo</desc>
Packit 1470ea
  
Packit 1470ea
    <mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
Packit 1470ea
      <mal:name>Fran Dieguez</mal:name>
Packit 1470ea
      <mal:email>frandieguez@gnome.org</mal:email>
Packit 1470ea
      <mal:years>2012-2013.</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
  

Unha imaxe dunha xanela con desprazamento.

Packit 1470ea
Packit 1470ea
  <links type="section"/>
Packit 1470ea
Packit 1470ea
  <section id="code">
Packit 1470ea
    <title>Código usado para xerar este exemplo</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étodos útiles para o widget ScrollWindow</title>
Packit 1470ea
    <list>
Packit 1470ea
      <item>

set_policy(hscrollbar_policy, vscrollbar_policy) where each of the arguments is one of Gtk.Policy.AUTOMATIC, Gtk.Policy.ALWAYS, Gtk.Policy.NEVER regulates whether the horizontal and vertical scrollbars should appear: with AUTOMATIC they appear only if needed, ALWAYS and NEVER are self-explanatory.

</item>
Packit 1470ea
      <item>

add_with_viewport(widget) is used to add the Gtk.Widget widget without native scrolling capabilities inside the window.

</item>
Packit 1470ea
      <item>

set_placement(window_placement) sets the placement of the contents with respect to the scrollbars for the scrolled window. The options for the argument are Gtk.CornerType.TOP_LEFT (default: the scrollbars are on the bottom and on the right of the window), Gtk.CornerType.TOP_RIGHT, Gtk.CornerType.BOTTOM_LEFT, Gtk.CornerType.BOTTOM_RIGHT.

</item>
Packit 1470ea
      <item>

set_hadjustment(adjustment) and set_vadjustment(adjustment) set the Gtk.Adjustment adjustment. This is the representation of a value with a lower and upper bound, together with step and page increments, and a page size, and it is constructed as Gtk.Adjustment(value, lower, upper, step_increment, page_increment, page_size) where the fields are of type float. (Note that step_increment is not used in this case, it can be set to 0.)

</item>
Packit 1470ea
    </list>
Packit 1470ea
  </section>
Packit 1470ea
  <section id="references">
Packit 1470ea
    <title>API References</title>
Packit 1470ea
    

Neste exemplo empregaremos o seguinte:

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>