A simpler guile-gtk interface



I have started writing a new guile-gtk interface over the existing one.  The 
goal is to simplify the code and make it more transparent.

As an example, the new code to create a top-level window with a label in it is 
as follows:
  (gtk-widget-show
   (gtk-top-level
    ((title "Top-level title"))
    (gtk-label "here is a label")))

Attributes of widgets are specified in a property-list-like way.
Child widgets are automatically inserted into parents and realized.

A more extensive example is given below, along with the equivalent code using the current interface.

What I have now can be had from http://www.mv.com/ipusers/karaya/simple-gtk/simple-gtk.scm. Since this is the product of a few hours work, coverage is limited and random.

The reason I'm announcing it is to elicit comments, criticism, and code.  I'd also like to know if anyone else is doing anything similar and better, so I don't waste my time on something inferior.

				Jeff

Herewith an example.  This may also be found at http://www.mv.com/ipusers/karaya/simple-gtk/gtk-test.scm.

(load "simple-gtk.scm")

(define (callback message)
  (lambda () (display message) (newline)))

(define (dialog-box-spiffy)
  (gtk-widget-show
   (gtk-top-level
    ((title "Top-level title"))
    (gtk-table
     ((rows 5) (cols 5))
     ((gtk-label "A box with lots of buttons") 0 5 0 1)
     ((gtk-button ((label "top button") 
		   (click-cb (callback "Top button pressed"))))
      1 4 1 2)
     ((gtk-button ((label "middle button") 
		   (click-cb (callback "Middle button pressed"))))
      1 4 2 3)
     ((gtk-button ((label "bottom button") 
		   (click-cb (callback "Bottom button pressed"))))
      1 4 3 4)
     ((gtk-button ((label "OK") (click-cb (callback "OK button pressed"))))
      1 2 4 5)
     ((gtk-button ((label "Cancel") 
		   (click-cb (callback "Cancel button pressed"))))
      3 4 4 5)))))

(define (dialog-box-grotty)
  (let ((top (gtk-window-new 'toplevel))
	(table (gtk-table-new 5 5 #t))
	(label (gtk-label-new "A box with lots of buttons"))
	(top-button (gtk-button-new-with-label "top button"))
	(middle-button (gtk-button-new-with-label "middle button"))
	(bottom-button (gtk-button-new-with-label "bottom button"))
	(ok-button (gtk-button-new-with-label "OK"))
	(cancel-button (gtk-button-new-with-label "Cancel")))
    (gtk-signal-connect top-button "clicked" (callback "Top button pressed"))
       (gtk-signal-connect middle-button "clicked" 
			   (callback "Middle button pressed"))
       (gtk-signal-connect bottom-button "clicked" 
			   (callback "Bottom button pressed"))
       (gtk-signal-connect ok-button "clicked" 
			   (callback "OK button pressed"))
       (gtk-signal-connect cancel-button "clicked" 
			   (callback "Cancel button pressed"))
       (gtk-table-attach table label 0 5 0 1)
       (gtk-widget-show label)
       (gtk-table-attach table top-button 1 4 1 2)
       (gtk-widget-show top-button)
       (gtk-table-attach table middle-button 1 4 2 3)
       (gtk-widget-show middle-button)
       (gtk-table-attach table bottom-button 1 4 3 4)
       (gtk-widget-show bottom-button)
       (gtk-table-attach table ok-button 1 2 4 5)
       (gtk-widget-show ok-button)
       (gtk-table-attach table cancel-button 3 4 4 5)
       (gtk-widget-show cancel-button)
       (gtk-container-add top table)
       (gtk-widget-show table)
       (gtk-window-set-title top "Top-level title")       
       (gtk-widget-show top)))




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