[racket] Racket/GUI

From: Stephen De Gabrielle (stephen.degabrielle at acm.org)
Date: Thu Mar 28 09:29:41 EDT 2013

Brilliant thanks.
Stephen

On Thursday, March 28, 2013, Diogo F. S. Ramos wrote:

> Stephen De Gabrielle <stephen.degabrielle at acm.org <javascript:;>> writes:
>
> >     You can use the FFI to pull in more Gtk, Win32, or Cocoa widgets
> >     on the
> >     corresponding platform. The `get-handle' and `get-client-handle'
> >     methods of a `window<%>' provide access to the underlying GUI
> >     toolkit's
> >     object, which lets you mix `racket/gui' windows and naive widgets.
> >
> > I'm fascinated by this, I'm having trouble locating an example where
> > it is used to bring in a native control.
>
> The following code brings up a toggle button from GTK+.
>
> Hope this helps. :^)
>
>
> #lang racket/gui
>
> (require ffi/unsafe)
>
> (define gtk-toggle-button-new-with-label
>   (get-ffi-obj "gtk_toggle_button_new_with_label"
>                #f
>                (_fun _string -> _pointer)))
> (define gtk-container-add
>   (get-ffi-obj "gtk_container_add"
>                #f
>                (_fun _pointer _pointer -> _void)))
> (define gtk-widget-show
>   (get-ffi-obj "gtk_widget_show"
>                #f
>                (_fun _pointer -> _void)))
>
> (define win (new frame% (label "hello, world")))
>
> (define toggle (gtk-toggle-button-new-with-label "toggle me"))
> (gtk-widget-show toggle)
> (gtk-container-add (send win get-client-handle) toggle)
>
> (send win show #t)
>


-- 

--
Stephen De Gabrielle
stephen.degabrielle at acm.org
Telephone +44 (0)20 85670911
Mobile        +44 (0)79 85189045
http://www.degabrielle.name/stephen
----
Professor: Oh God! I clicked without reading!
Cubert: And I slightly modified something I own!
Professor: We're monsters!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130328/a2e686ca/attachment.html>

Posted on the users mailing list.