fsfe-uk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fsfe-uk] An ignorant question?


From: Roger Leigh
Subject: Re: [Fsfe-uk] An ignorant question?
Date: 13 Jun 2003 00:05:14 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Chris Croughton <address@hidden> writes:

> On Tue, Jun 10, 2003 at 09:01:33PM +0100, Roger Leigh wrote:
> 
> > Chris Croughton <address@hidden> writes:
> > 
> > > Glade doesn't seem to work properly without Gnome
> > 
> > Glade comes in two flavours, one is plain GTK+, the other has GNOME
> > support.  Neither are dependent on any particular WM.
> 
> Hmm, perhaps it's an older version of Glade that just doesn't work,
> period.  For instance, when I place a button (or anything else for that
> matter) on a created window it immediately expands to fill the whole
> of that window and can't be changed by anything I do.

This is the correct behaviour.  A GtkWindow can only contain one
widget, since it is also a GtkContainer (a thing that can hold another
thing).  You need to add a GtkVBox, GtkHBox or GtkTable first.  These
are vertical and horizontal rows and grids of containers,
respectively.  You can then add your widgets to these, which can be
more boxes.

This method of making an interface means that it is made up of a bunch
of little boxes that all pack inside each other.  This makes it simple
to resize the interface, or cope with different font sizes, screen
widths etc.  This wouldn't be possible if the widgets were put in
fixed positions on a form.

> it's not a lot of effort to
> > set up the hotkeys, focus movement through dialogues and so on.  If
> > you are forced to use the mouse, it's badly designed, IMHO.
> 
> Well, not quite IMO.  There are some things which are pretty silly using
> the keyboard (or horribly slow), like some interactive graphics work,
> just as there are some which are silly using the mouse (entering keys
> for example).  But everything else should be able to be done with both,
> not necessarily exactly as easily but not difficult.

Yes.  For things like graphics and CAD, you can't use a keyboard, but
it should be possible to use it for everything that doesn't require
pixel-perfect pointing.

> > Learning a "proper" language and GUI toolkit will seem rather
> > difficult at first, but the quality of the work you will be doing will
> > (potentially!) be of a much higher standard.
> 
> I don't know whether you consider C++ to be a 'proper' language.  I can
> switch to C, Fortran, Pascal (spit!), Perl (double spit!), Awk or even
> CORAL-66 or ALGOL (but please not!) if you prefer.  Or even COBOL,
> although I haven't written a COBOL program for about 28 years.

By "proper", I meant something with functions and structures.  I
consider C, C++ and Perl to be "proper", even though I detest Perl.
Since a UI requires object-orientation to be useful (GTK+ uses
GObject), it helps to have a good language that can support it
properly.

> In general, though, if I want menu and form type interfaces I'll use
> (n)curses, which work almost anywhere (certainly anything with terminal
> and POSIX.1 emulation).  It's only on the rare occasions that it would
> be nice to see a load of changing data as graphics that I need a GUI.
> 
> But it's usually faster for me to knock up a small server app in VB to
> display the data, and have the acual program send it the data, than to
> mess about with graphics interfaces under X.

I don't doubt that this is true.

> > If you want to do something "right now", you're out of luck--you'll
> > need to invest some time into learning the fundamentals of your chosen
> > toolkit.  I'd suggest getting GTK+ (2.2), Qt (3.x), gtkmm (2.x), or
> > whatever takes your fancy, and work your way through the tutorials and
> > docs.  In a few weeks, you'll be up to writing seriously complex UIs.
> 
> You mean the sort of thing I wrote within half an hour in VB, having
> never seen VB before (and it bears very little resemblance to Dartmouth
> BASIC or even CP/M MSBASIC)?

Yes.  VB is easy, and I would be lying if I said GTK+ was not
difficult, since you have to get around the object/type system and its
widget packing design before you can do anything with it.  Once
everything clicks, it's a doddle.

(I first looked at GTK+ about three years ago, and I didn't understand
it at all.  Learning C++/OO stuff last year certainly helped me yet to
grips with it when I started using it earlier this year.)

> > As an example of a simple sort-of-RAD application, see
> > http://www.whinlatter.uklinux.net/gtk/ogcalc.c.  This took about six
> > hours to write, being unfamiliar with GTK+.  I used Glade to design
> > the interface, then constructed it by hand.  If you used Glade to do
> > all the interface, all you would need to do is write the callbacks and
> > load the interface--this would take a matter of minutes.
> 
> Hmm, as far as I can see (and I haven't tried compiling or running it
> yet) it calculates how drunk and heavy you really are (%ABV and OG)
> based on your glasses prescription (RI), how heavy you feel (PG) and a
> corrective factor <g>.  More probably, it's something to do with
> fermentation.  But the comments don't say...

;-) I've attached a commented version.  I hope this is an improvement!

gcc -o ogcalc ogcalc.c `pkg-config --cflags --libs gtk+-2.0`
builds it, BTW.

> (I don't see from that code how the window or the widgets in it are
> positioned.  Is something missing, or is it just buried in the code
> somewhere?)

The widgets pack inside each other, so you start like this

+-----+
|     | A window
|     |
+-----+

and pack Boxes into that, which are nested, ultimately containing
widgets, like this:

+---------------------------+
|+-------------------------+|
||+-+-----+-+-----+-+-----+||
|||L|Entry|L|Entry|L|Entry|||
||+-+-----+-+-----+-+-----+||
|+-------------------------+|
||+-+---------+-+---------+||
|||L| Result  |L| Result  |||
||+-+---------+-+---------+||
|+-------------------------+|
|+-------------------------+|
||-------------------------||
|+-------------------------+|
|+-------------------------+|
||+-------+-------+-------+||
||| Quit  | Reset | Calc  |||
||+-------+-------+-------+||
|+-------------------------+|
+---------------------------+

This is a simplified view of what the program look like.  You can see
that if you resize the window, the boxes would "stretch" to fit.  Some
could be of fixed width, some variable.  If you follow the main()
function in the listing, you can construct it yourself in Glade to
make it yourself.

> And my idea of a good database is usually a flat ASCII file searched
> with grep or awk (I keep thinking I ought to learn MySQL but I don't
> have any application I need it for).

[Sharp intake of breath]
(I use PostgreSQL!)

The work I'm currently doing uses (binary) flat files, and manually
doing an outer join and sorting using two keys, using this BASIC-like
4GL is a nightmare.  Over 1000 LOC, when it could be done in a single
SQL statement!!


-- 
Roger Leigh

                Printing on GNU/Linux?  http://gimp-print.sourceforge.net/
                GPG Public Key: 0x25BFB848 available on public keyservers

Attachment: ogcalc.c.gz
Description: GTK+ ABV calculator (simple GTK+ tutorial program)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]