GTK 和 Guile

关于 Guile

GNU Guile 是 Scheme 编程语言的一个实现,支持该语言报告的第五版和大部分第六版,以及许多实现请求。

它包含一个字节码和 JIT 本机代码编译器,被设计为 GNU 项目的标准扩展语言。

关于 G-Golf

G-Golf 是一个 Guile 对象库,用于用 Scheme 开发现代 GNOME 应用程序。 它包含一个到 GObject Introspection API 的直接绑定,以及用于导入 GNOME 库并在 Guile 的面向对象编程系统 GOOPS 中提供 GObject 类(和方法)的更高层功能。

你好,世界

#! /bin/sh
# -*- mode: scheme; coding: utf-8 -*-
exec guile -e main -s "$0" "$@"
!#

;; This Hello World is fairly elaborate and highlights many features of G-Golf,
;; such as being able to require specific versions of modules or importing
;; classes by name.  It is taken directly from the G-Golf source tree.

(eval-when (expand load eval)
  (use-modules (oop goops))

  (default-duplicate-binding-handler
    '(merge-generics replace warn-override-core warn last))

  (use-modules (g-golf))

  (g-irepository-require "Gtk" #:version "4.0")
  (for-each (lambda (name)
              (gi-import-by-name "Gtk" name))
      '("Application"
        "ApplicationWindow"
        "Box"
        "Label"
        "Button")))


(define (activate app)
  (let ((window (make <gtk-application-window>
                  #:title "Hello"
                  #:default-width 320
                  #:default-height 240
                  #:application app))
        (box    (make <gtk-box>
                  #:margin-top 6
                  #:margin-start 6
                  #:margin-bottom 6
                  #:margin-end 6
                  #:orientation 'vertical))
        (label  (make <gtk-label>
                  #:label "Hello, World!"
                  #:hexpand #t
                  #:vexpand #t))
        (button (make <gtk-button>
                  #:label "Close")))

    (connect button
	     'clicked
	     (lambda (b)
               (close window)))

    (set-child window box)
    (append box label)
    (append box button)
    (show window)))


(define (main args)
  (let ((app (make <gtk-application>
               #:application-id "org.gtk.example")))
    (connect app 'activate activate)
    (let ((status (g-application-run app (length args) args)))
      (exit status))))

查看更多

发现拼写错误或缺少信息,编辑此页面
阅读关于 如何为本网站贡献 的信息。