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

Re: GUI stuff



On Wed, Feb 17, 1999 at 04:34:19PM +0000, George Richard Russell was heard to say:
> 
> > On Tue, 16 Feb 1999, David Webster wrote:
> > I am wanting to start some GUI development but I am having a hard time
> > figuring out just what the GUI development is?  I see that the GTK
> > libaraires are the base C++ GUI class libraries, but I also see stuff
> > like Gnome and qt* and Glib, and other stuff.  Is there any online
> > documentation that sorts all this stuff out?  What are the compliments
> > in the Linux/X11 world to MFC/IOCL in the Win32 world?  What about
> > resource editors and stuff like that???
> >
> I am a KDE user and enthusiast, so my biases are pretty obvious. I also
> really 
> hate C as a language :-(

  Ok, I guess someone needs to recommend the 'other' stuff to him.  I'm
going to leave out the rest of your message in an attempt not to make this
an argument between us, though. ;)

  To the first writer:

  It looks like you're just starting X programming.  The first thing you
should realize (if you don't already) is what the library situation in
X is.  Basically, there's a low-level interface to the X server called Xlib,
but almost no-one uses it because it's hard to get anything done.  To provide
a more convenient programing environment, 'widget sets' are wrapped around
the X libraries; these widget sets are what actually draw the buttons, menus,
and so on that you see on the screen.  There have been a number of widget sets
in the past--Athena, Motif, etc, but currently the two most popular (and
probably the two best) are Qt and GTK+.  Qt was developed by TrollTech and
has historically had some licensing issues (which may be resolved, but I don't
want to go there.  If you're new to X you are also mercifully unaware of the
Widget Set Holy Wars...), while GTK+ was developed for the GIMP (GTK+ stands
for GIMP ToolKit)  Take anything I say about Qt with a grain of salt, simply
because I don't program for it and so I'm not up on the latest news.  In fact,
for that reason I'm going to avoid talking about it at all.

  GTK+ is an object-oriented toolkit implemented in C.  However, you can write
programs for it in C++, Ada, Perl, Scheme, and Python (go to
http://www.gtk.org/language-bindings.html for a more complete list), to name
a few.  GTK+ is based on GDK (which also has language bindings, at least to
C++), the General Drawing Kit, and Glib, the General (?) Library.  GDK is
a wrapper library around Xlib which abstracts the windowing system, while
Glib provides a bunch of general utility functions--either sane replacements
for broken native functions (eg g_malloc, g_fprints) or functions that
implement commonly useful data structures (hash tables for example).  All
the libraries and dependencies are licensed under the LGPL.

  As I mentioned, GTK+ is object-oriented but done in C.  A lot of people
think this is stupid.  I suggest that you at least try it out, and
give GTK-- (the C++ bindings) a spin if you like C++ work.  You can do
pretty much everything that you'd want to do in C++ using GTK--, including
deriving new widgets and so on.  The only real problem is that it's difficult
for people using C to use the new widgets you create.  That might not be an
issue for you, however, or you could find a way to wrap C++ widgets in C
and be a hero. :-)  I personally find it to be really fun to program in, in C
or in C++.  Some sample code:

----------- C++ (from an attempt at a LILO config program I was writing)

lilo_image_win::lilo_image_win():
  Gtk_Window(GTK_WINDOW_TOPLEVEL),
  basic_label("Basic options")

{
  should_delete=false;
  add(&pages);
  pages.append_page(basic_options,basic_label);
  basic_options.show();
  pages.show();
}
------------
  This widget inherited from the Gtk_Window object; you can see the call to the
ancestor contructor there.  basic_label is a label object that was labelling
a text entry if I remember correctly.  pages is a Gtk_Notebook object.
basic_options is the widget which will be displayed in the page for Basic
Options; there's no Advanced Options page because I didn't have time to finish
the project. :-)

-------------- C (from Freeciv's GTK+ client, not stock code..locally modified)

    dialog = gtk_dialog_new();
    gtk_signal_connect( GTK_OBJECT(dialog),"delete_event",
        GTK_SIGNAL_FUNC(connect_deleted_callback),NULL );

    notebook=gtk_notebook_new();

    gtk_box_pack_start( GTK_BOX( GTK_DIALOG( dialog )->vbox ), notebook, TRUE, TRUE, 10 );

    frame = gtk_frame_new( "Freeciv Server Selection" );
    label = gtk_label_new( "Connect" );

    gtk_notebook_append_page( GTK_NOTEBOOK( notebook ), frame, label );
----------------

  This does something similar but in C.  gtk_dialog_new() is the constructor
for a 'dialog' object.  The dialog object is a convenience that GTK+ provides;
it's a normal window with some layout objects already contained in it that are
useful for creating dialogs (stuff on top, buttons along the bottom).  The
signal_connect call adds a callback, a notebook is constructed and packed
into the vbox (vertical box) in the dialog.  The frame is one of those gray
boxes with a title in the upper-left :); the title is "Freeciv...".  The
label is used as the title of the notebook tab for that item.

  If you decide to use GTK+, get the latest version from http://www.gtk.org.
It's labeled 'unstable' but is working flawlessly (as far as I can see) and I
think may even be in a freeze.

  Some features of GTK+ include a 'containers-everywhere' attitude, in that
almost any widget can contain an arbitrary widget (for example, buttons can
have text, images, or some bizarre FooWidget that you wrote as their label),
a rather strong (IMO) layout system (most of the time you just specify
geometrical relationships and let the library work things out), near-total
themability (http://gtk.themes.org for some examples, quite good since the
default look isn't especially pretty), and most of the other bells and whistles
you'd expect from a modern widget set.

  The main deficit of GTK+ is that documentation on writing programs can be
difficult to find.  The links from the GTK+ homepage--in particular, the
tutorial--will probably be enough to get a feel for the general layout of
things.  I think there are some efforts going on to document the more advanced
stuff but I'm not sure what their status is.

  I think that probably the best way to evaluate GTK+, though, is to try
it.  http://www.gtk.org.  If you decide you don't like it, the other choices
are Qt or perhaps Lesstif. (I'd recommend Qt after GTK)

  Daniel


Reply to: