2013-09-19

Programming - part 1: Gtktables

After not having blogged for months (and being embarrassed after
the large number of blogs from last year) I decided to blog again,
And I also decided, after not having done so in a serious (more or less)
manner for several years, to work on a programming project,
and maybe actually get it doing what I wanted to, in other words, finish it.

I am a Linux geek, so I am using the Gnome and Gtk
libraries to create my masterpiece ( :) ).

I program in c mostly, when I am programming
large projects.

One of the problems I ran accross was understanding tables.

Consider this actual c source code:

GtkWidget * table;

table = gtk_table_new(5,3,FALSE);

This is easy enough to understand: in simple terms, make a table called
(strangely enough) table. It is to be 5 rows high and 3 columns wide,
the "FALSE" indicates that it is to be "not homogeneous" (cells won't
have their size set by the size of the largest element contained in the
table).

Easy

BUT

The table documentation and all the tutorials I could find (two tutorials)
were driving me batty. Determining how to place widgets/text/whatever
in specific cells was, confusing, to say the least.

Here is an example attach command:

gtk_table_attach(GTK_TABLE(table),label,1,2,1,2,GTK_FILL,
                                                                    GTK_FILL,0,0);

OK - what did it mean??

First of all, the gtk_table_attach command places an item in a table cell.

Here is how the docs described it:

void                gtk_table_attach      (GtkTable *table,
                                           GtkWidget *child,
                                           guint left_attach,
                                           guint right_attach,
                                           guint top_attach,
                                           guint bottom_attach,
                                           GtkAttachOptions xoptions,
                                           GtkAttachOptions yoptions,
                                           guint xpadding,
                                           guint ypadding);


The docs followed with a simple example:

To make a button occupy the lower right cell of a 2x2 table, use

1 
2 
3 
4 
5 
gtk_table_attach (table, button,
                  1, 2, // left, right attach
                  1, 2, // top, bottom attach
                  xoptions, yoptions,
                  xpadding, ypadding);
 

HUH???

To my tired mind, the instructions were a little hazy.

The actual confusing bits were: 

guint left_attach,
guint right_attach,
guint top_attach,
guint bottom_attach,

For anyone else running into this, here is how I eventually came to
understand it. Consider this table:

3 columns wide.
5 rows high.
Notice, I have placed a
number at the end of each
dividing line, both vertically
and horizontally.


With example placements in each cell. (Tables in gtk are
always numbered starting at zero.)

Notice the repeating number patterns?

So, taking the number in the first cell on the top left as an example,
the first digit (0) represents the first vertical line on the left side of
the cell. The second digit (1) represents the first vertical line on the
right side of the cell.

OK so far?

The third digit (0) represents the line on the top of the cell.
The fourth digit (1) represents the line on the bottom of the cell.

Therefore this:

gtk_table_attach(GTK_TABLE(table),label,1,2,1,2,GTK_FILL,
                                                                    GTK_FILL,0,0);

means place a label into the table cell second from the left and second from
the top. To place an object (widget/text/whatever) in the very first cell
top row, top left the attach command would look like this:

gtk_table_attach(GTK_TABLE(table),label,0,1,0,1,GTK_FILL,
                                                                    GTK_FILL,0,0);

Hope that saves someone a bit of time.

じゃまた

2013-02-22

History

While I am not sure I agree with this quote
(Often attributed to Mark Twain) I certainly
find it interesting, at least:

History does not repeat itself, but it does rhyme.

じゃまた
2013-01-31

Is it Really a Diet?

OK, a friend is doing this weird thing she calls a diet,
which contains things like "Cilantro Lime Chickpea Salad"
or "Quinoa Spinach Breakfast Bars" this sounds more like
a yuppie coffee bar menu than a diet to me, I am sure
there is lots of strange stuff to enjoy, and while margarine
may not be healthy, it's the only realistic alternative
for people like me, who is not only mildly gluten
intolerant but very lactose intolerant, so don't bother
suggesting butter to me, AT ALL! I cannot eat it without
being sick for a couple of hours afterwards.

Here is a portion of a realistic diet menu:

Green salad - skip the croutons and use low-cal dressing.
back off on the spuds - especially in potato salad. 
In fact, cut back on the starch, it turns to sugar which
translates into no weight loss.
Eat your veggies, carrots (raw is good) peas, broccoli, cauliflour.
Protein - white meat or fish is best.
Fruit, no milk, no sugar on top.

Ordinary foods may seem boring, but they can
be spiced up, in a healthy fashion, without being
something off a yuppie menu which looks, sounds and
tastes totally bizarre.

Curry on the meat and rice (brown if you can stand it -
I despise brown rice in all its forms) is a good topper.

Try that.

Blog Archive

Contributors

CatWalker

CatWalker
CatWalker at 29