guile-gtk-general
[Top][All Lists]
Advanced

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

Re: guile-gtk scribble demo


From: Andy Wingo
Subject: Re: guile-gtk scribble demo
Date: Wed, 10 Nov 2004 22:44:55 +0200

Hey gang,

Neat. I've never dealt with styles, gc's, etc, so this is nice.

I translated it to the guile-gnome API and dropped it into the
guile-gnome archive. It's attached. Some of the specific differences are
commented below:

On Thu, 2004-11-04 at 15:51 +0100, Marius Vollmer wrote:
> > (define toplevel-window (gtk-window-new 'toplevel)) ; our toplevel window

In guile-gnome, the style is to create widgets with `make'. You can set
object properties when you initialize the object, and all objects have
default values for their properties. e.g.

(make <gtk-window> #:type 'toplevel)

I find it's a bit easier than remembering argument order. The old
functions are still there, though.

> > ;Note: configure is GTKese for resize
> > (define (configure-handler ev)
> >   (recreate-pixmap))

In guile-gnome, the signal handlers all take the object as the first
parameter, and you have to make sure you return something if the signal
requires it. This is especially true for events -- see the gtk api docs
for that. When a value is needed, #<unspecified> is not allowed.

> >   (let ((widget (gtk-widget-window drawing-area))
> >     (w (gtk-widget-allocation-width drawing-area))
> >     (h (gtk-widget-allocation-height drawing-area)))

I had to add these. GTK2 getters are typically named as gtk-foo-get-bar,
so I named them gtk-widget-get-window. gtk-widget-get-allocation returns
a #[x y width height] vector. Probably should add
gtk-allocation:{x,y,..} getters, but using vector-ref for now.

> >           (inexact->exact (gdk-event-x ev))

Event getters are different. It's gdk-event-TYPE:FIELD. So e.g.
gdk-event-button:x.

> > (gtk-signal-connect drawing-area "configure_event" configure-handler)

Full functions can be abbreviated with generic procedures, e.g.
gtk-widget-show -> show for objects of type <gtk-widget>. `connect' is a
convenient abbreviation for `gtype-instance-signal-connect'. Also, the
signal name is a symbol, with underscores made into dashes.

(connect drawing-area 'configure-event configure-handler)

> > (let ((style (gtk-widget-style toplevel-window)))
> >   (set! fore-gc (gtk-style-fg-gc style 'normal))
> >   (gdk-gc-set-foreground fore-gc "black") ;we draw in black

Well, well. In GTK2 styles and gc's are refcounted objects, so in that
case you actually change the gc for the whole window. Because the style
already has fields for white and black gc's, I punted on this, just
getting the existing gc's.

Cheers, and thanks again for the demo,
-- 
Andy Wingo <address@hidden>
http://ambient.2y.net/wingo/

Attachment: scribble.scm
Description: application/shellscript


reply via email to

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