Blame platform-demos/pt_BR/grid.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="grid.py" xml:lang="pt-BR">
Packit 1470ea
  <info>
Packit 1470ea
    <title type="text">Grid (Python)</title>
Packit 1470ea
    <link type="guide" xref="beginner.py#layout"/>
Packit 1470ea
    <link type="seealso" xref="label.py"/>
Packit 1470ea
    <link type="next" xref="separator.py"/>
Packit 1470ea
    <revision version="0.2" date="2012-08-01" status="stub"/>
Packit 1470ea
Packit 1470ea
    <credit type="author copyright">
Packit 1470ea
      <name>Tiffany Antopolski</name>
Packit 1470ea
      <email its:translate="no">tiffany.antopolski@gmail.com</email>
Packit 1470ea
      <years>2012</years>
Packit 1470ea
    </credit>
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>Pack widgets in rows and columns</desc>
Packit 1470ea
  
Packit 1470ea
    <mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
Packit 1470ea
      <mal:name>Rafael Ferreira</mal:name>
Packit 1470ea
      <mal:email>rafael.f.f1@gmail.com</mal:email>
Packit 1470ea
      <mal:years>2013</mal:years>
Packit 1470ea
    </mal:credit>
Packit 1470ea
  </info>
Packit 1470ea
Packit 1470ea
  <title>Grid</title>
Packit 1470ea
Packit 1470ea
  <media type="image" mime="image/png" src="media/grid_simple.png"/>
Packit 1470ea
  

Some labels in a grid.

Packit 1470ea
Packit 1470ea
  <links type="section"/>
Packit 1470ea
Packit 1470ea
  <section id="code">
Packit 1470ea
    <title>Code used to generate this example</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__(self, title="Grid Example", application=app)
Packit 1470ea
Packit 1470ea
        # three labels
Packit 1470ea
        label_top_left = Gtk.Label(label="This is Top Left")
Packit 1470ea
        label_top_right = Gtk.Label(label="This is Top Right")
Packit 1470ea
        label_bottom = Gtk.Label(label="This is Bottom")
Packit 1470ea
Packit 1470ea
        # a grid
Packit 1470ea
        grid = Gtk.Grid()
Packit 1470ea
Packit 1470ea
        # some space between the columns of the grid
Packit 1470ea
        grid.set_column_spacing(20)
Packit 1470ea
Packit 1470ea
        # in the grid:
Packit 1470ea
        # attach the first label in the top left corner
Packit 1470ea
        grid.attach(label_top_left, 0, 0, 1, 1)
Packit 1470ea
        # attach the second label
Packit 1470ea
        grid.attach(label_top_right, 1, 0, 1, 1)
Packit 1470ea
        # attach the third label below the first label
Packit 1470ea
        grid.attach_next_to(
Packit 1470ea
            label_bottom, label_top_left, Gtk.PositionType.BOTTOM, 2, 1)
Packit 1470ea
Packit 1470ea
        # add the grid to the window
Packit 1470ea
        self.add(grid)
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
app = MyApplication()
Packit 1470ea
exit_status = app.run(sys.argv)
Packit 1470ea
sys.exit(exit_status)
Packit 1470ea
Packit 1470ea
  </section>
Packit 1470ea
Packit 1470ea
  <section id="methods">
Packit 1470ea
    <title>Useful methods for a Grid widget</title>
Packit 1470ea
Packit 1470ea
    <list>
Packit 1470ea
      <item>

To attach a widget child in position left, top in a slot of given width, height use attach(child, top, left, width, height). If a widget sibling is already in place, we can also use attach_next_to(child, sibling, side, width, height), where side is one of Gtk.PositionType.LEFT, Gtk.PositionType.RIGHT, Gtk.PositionType.TOP, Gtk.PositionType.BOTTOM.

</item>
Packit 1470ea
      <item>

insert_row(position) and insert_column(position) do exactly what they say; children which are attached at or below this position are moved one row down, and children which span across this position are grown to span the new row. insert_next_to(sibling, side) inserts a row or column at the specified position. The new row or column is placed next to sibling, on the side determined by side; if side is Gtk.PositionType.TOP or Gtk.PositionType.BOTTOM, a row is inserted, if side is Gtk.PositionType.LEFT or Gtk.PositionType.RIGHT, a column is inserted.

</item>
Packit 1470ea
      <item>

set_row_homogeneous(True) and set_column_homogeneous(True) ensure that (respectively) every row or every column has the same width or height.

</item>
Packit 1470ea
      <item>

set_row_spacing(spacing) and set_column_spacing(spacing) force a spacing between (respectively) rows or columns. The value of spacing can be between 0, which is the default value, and 32767.

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

In this sample we used the following:

Packit 1470ea
    <list>
Packit 1470ea
      <item>

<link href="http://developer.gnome.org/gtk3/unstable/GtkApplication.html">GtkApplication</link>

</item>
Packit 1470ea
      <item>

<link href="http://developer.gnome.org/gtk3/unstable/GtkApplicationWindow.html">GtkApplicationWindow</link>

</item>
Packit 1470ea
      <item>

<link href="http://developer.gnome.org/gtk3/unstable/GtkLabel.html">GtkLabel</link>

</item>
Packit 1470ea
      <item>

<link href="http://developer.gnome.org/gtk3/unstable/GtkImage.html">GtkImage</link>

</item>
Packit 1470ea
      <item>

<link href="http://developer.gnome.org/gtk3/unstable/GtkGrid.html">GtkGrid</link>

</item>
Packit 1470ea
    </list>
Packit 1470ea
  </section>
Packit 1470ea
</page>