example-01-hello-world.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #! /bin/sh
  2. # -*- mode: scheme; coding: utf-8 -*-
  3. exec guile -e main -s "$0" "$@"
  4. !#
  5. ;;; Example adapted from https://www.gnu.org/software/g-golf/manual/html_node/Scripting.html
  6. (eval-when (expand load eval)
  7. (import (oop goops))
  8. (default-duplicate-binding-handler
  9. '(merge-generics replace warn-override-core warn last))
  10. (import (g-golf))
  11. (for-each (λ (name) (gi-import-by-name "Gtk" name))
  12. '("Application"
  13. "ApplicationWindow"
  14. "Box"
  15. "Label"
  16. "Button")))
  17. (define (activate app)
  18. (let ((window (make <gtk-application-window>
  19. #:title "Hello"
  20. #:default-width 320
  21. #:default-height 240
  22. #:application app))
  23. (box (make <gtk-box>
  24. #:margin-top 6
  25. #:margin-start 12
  26. #:margin-bottom 6
  27. #:margin-end 6
  28. #:orientation 'vertical))
  29. (label (make <gtk-label>
  30. #:label "Hello, World!"
  31. #:hexpand #t
  32. #:vexpand #t))
  33. (button (make <gtk-button>
  34. #:label "Close")))
  35. (connect button
  36. 'clicked
  37. (lambda (b)
  38. (close window)))
  39. (set-child window box)
  40. (append box label)
  41. (append box button)
  42. (show window)))
  43. (define (main args)
  44. (let ((app (make <gtk-application>
  45. #:application-id "org.gtk.example")))
  46. (connect app 'activate activate)
  47. (let ((status (run app 0 '())))
  48. (exit status))))