chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] gtk2.egg


From: Andre Kuehne
Subject: Re: [Chicken-users] gtk2.egg
Date: Tue, 13 Feb 2007 20:52:59 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20061109)

Tony Sidaway wrote:
$ svn co https://galinha.ucpel.tche.br/svn/chicken-eggs/gtk2

(login anonymous, leave the password response empty)

This may be of interest to GUI enthusiasts.

At least for me gtk2 is the one big missing egg!

The interesting part of the code, to me, is what is built on top of
the wrapped library.  g+ is a very clean, Scheme-like GUI library that
keeps the fussiness of the underlying C implementation well away from
the Chicken code.

Here for instance, in g+, is a GTK OptionMenu object containing an
embedded button and a nested menu, with the signal handlers embedded
in the menu structure.

(g+option-menu
 (g+menu
   (g+menu-item "First"
     (g+signal 'activate
       (lambda (i) (print "Chose 1"))))
   (g+menu-item*
     (g+button "Hello"
       (g+signal 'clicked
         (lambda _ (print "Why, hello!"))))
     (g+menu
       (g+menu-item "hi1"
         (g+signal 'activate
           (lambda (i) (print "Chose 2"))))
       (g+menu-item "hi2")))
   (g+menu-item "Third"
     (g+signal 'activate
       (lambda (i) (print "Chose 3"))))))

This is an egg from code originally produced by Tony Garnock-Jones
(tonyg) in 2002.  The code rotted a bit over the years, and I spent a
few days in January cleaning it up so it builds and runs on my Ubuntu
system.  Tony G responded to my licensing request yesterday and
permitted me to upload the updated code.  I've packaged it as an egg.

Great!

The main part of the code is a pretty straightforward wrap of libgtk2
and libglade.  The only unusual thing is that a bespoke wrap program
is used instead of SWIG, and relies on "defs" files that are published
by the (Python) PyGTK project.

I have no experience with writing glue-code, just curious. What's the
advantage over SWIG? Does this approach make it easier to stay compatible
with new gtk versions, since PyGTK is guaranteed to be?

This egg is NOT related to the gtk egg produced by Alejandro Forero
Cuervo and Manuel Alejandro CerĂ³n Estrada.  That other project was
based on SWIG bindings and seems to have stalled.

There are issues with this egg as it stands at present.  It is
definitely not usable for anything serious yet.

Firstly, libgtk+ is absolutely huge and this is an attempt to wrap it
all.  The build process is an absolute beast and takes ages to run on
my system.  It should probably be split up into bite-sized chunks.

On my system (1.73GHz Pentium M, 512MB) it took 3 1/2 minutes
to compile. Compared to the xlib egg it's a snap!

There are UNIX dependencies in the build process, most notably the
shell script "extract-all-types" which really should be converted to
chicken.

Attached is a drop-in-replacement for "extract-all-types".

Additionally the script excludes "gdk_window_get_type".
Otherwise i get this compile error:

wrap.c: In function `code_2':
wrap.c:53: error: too few arguments to function `gdk_window_get_window_type'

I guess for the same reason "gtk_gadget_get_type" is excluded in the
original version of "extract-all-types".

There are also probably some strong gtk-2.0 version dependencies.  It
builds on my Ubuntu system with Ubuntu's stock gtk 2.8.20 build.  It
also expects libglade.  I cannot make promises about which other
versions of GTK it will run on, and if you want to build it without
libglade support you'll have to tweak the code a bit.

Besides the error mentioned above, it compiles against my gtk+ 2.10.6.

However most sample-apps crash:

> csi gtk2-explore.scm
Version 2.5 - linux-unix-gnu-x86 - [ dload ptables applyhook ]
** (gtkchicken:3545): WARNING **: Unknown gtype in gtype-from-name: GtkTreeIter
Error: unbound variable: gtk-tree-store-append

> csi gtk2-test+.scm
** (gtkchicken:3547): WARNING **: Unknown gtype in gtype-from-name: GtkTreeIter
Error: unbound variable: gtk-arrow-new

> csi gtk2-test-liststore+.scm
** (gtkchicken:3554): WARNING **: Unknown gtype in gtype-from-name: GtkTreeIter
Error: unbound variable: gtk-list-store-append

> csi gtk2-test-treestore+.scm
** (gtkchicken:3558): WARNING **: Unknown gtype in gtype-from-name: GtkTreeIter
Error: unbound variable: gtk-tree-store-append

And so on.

However these apps do work:

  gtk2-test-drawingarea.scm
  gtk2-test-gobject.scm
  gtk2-test-libglade.scm

The wrapping system doesn't correctly handle variable argument lists
with a NULL sentinel, despite the gtk headers signalling the usage
clearly.

Some of the demo programs fail mysteriously.  Tony G and I think it's
a pointer wrapping problem, and I'll be working on fixing that.

Further bug reports would be most welcome.  Please include details of
your system and the version of libgtk you're using.


gtk+ version 2.10.6
chicken-version 2.5 - linux-unix-gnu-x86 - [ dload ptables applyhook ]


Best Regards
Andre Kuehne

#! /bin/sh
#|
exec csi -s $0 "$@"
|#

(use posix
     srfi-1
     utils)

(define exclude-list '("#define"
                       "visibility(\"hidden\")"
                       "gtk_gadget_get_type"
                       "gdk_window_get_type"))

(define include-regexp (regexp (conc ".*[^a-zA-Z_]("
                                     (cdr (assoc "SEARCH_REGEX"
                                                 (current-environment)))
                                     ")")))
(define exclude-regexp (regexp (string-intersperse (map regexp-escape 
exclude-list)
                                                   "|")))

(define (handle-line line)
  (if (not (string-match exclude-regexp line))
      (let ((match-groups (string-match include-regexp line)))
        (if (list? match-groups)
            (write-line (list-ref match-groups 1))))))

(define (handle-file filepath)
  (if (file-exists? filepath)
      (with-input-from-file filepath
        (lambda ()
          (do ((line (read-line) (read-line)))
              ((eq? line #!eof))
            (handle-line line))))
      (error "file does not exist" filepath)))

(define (handle-directory dirpath)
  (if (directory? dirpath)
      (for-each handle-file
                (find-files dirpath ".*\\.h"))))

(define (handle-arguments args)
  (write-line (conc "extract-all-types.scm: " (string-intersperse args))
              (current-error-port))
  (for-each handle-directory
            (map (lambda (x) (substring x 2))
                 (grep "^-I" args))))

(handle-arguments (drop (argv) 3))

reply via email to

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