Book Annotation - Pro PHP-GTK - Listing 6-3 - Five rows and Two columns would suffice

I have been learning PHP-GTK. I was reading ‘Pro PHP-GTK’ a book by Scott Mattocks, published by Apress (2006) and had come to study Listing 6-3 on pages 99 and 100 in Chapter 6.  Its the bit about using tables for laying out the application’s widgets.

Listing 6-3 Diagram Showing how the tables are created then attached to togetherAlthough the code is correct and it produces the layout as expected, I found the use of a five-row, three- column table to be slightly confusing. You can actually use a five-row, two-column table instead and the layout will appear exactly the same. As far as I can tell, the extra column on the right of the table serves no purpose - it never holds any widgets.

You can ’see’ the effect of the 3rd column by modifying and then running the code in Listing 6-3 of the book. Try passing a boolean TRUE value as the third argument to the line that instantiates the first table (see below). When the code is run, you will see all the cells displayed the same size (homogeneously) which reveals the third, erroneous, column.

$table = new GtkTable(5,3,TRUE);

I decided to create the first table with five rows and two columns instead of three. By doing this, I  found it a lot easier to get to grips with understanding how the attach method, and its whopping 9 arguments, behave.

Personally, I found the attach method quite confusing:

  • The left attach and top attach arguments use a zero-based index to represent the position of their cells.
  • The right attach and bottom attach arguments use a one-based index to represent the position of their cells.

But, its the zero-based grid-lines of the table (and not the cells, columns and rows between them) that the attach method really cares about. Its much simpler to think in terms of grid-lines rather than columns and rows.

I found that sketching a diagram of the table and labelling the grid-lines with their index numbers made things a little clearer. However, the first time that I tried doing my sketch, I drew the sub-table in so that it spanned over 2 columns of the outer table. Obviously, this little error on my part lead to all sorts of brain-frizzing double-takes.

I should add that despite these annotations and errata, the book is superb and I would recommend it to any PHP programmer who wishes to make the language more useful by an order of magnitude. Its a liberating read.

See more about :

Leave a Reply