example-03-empty-window.scm 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #| GTK Application Templage (Guile Scheme version). |#
  2. (import (prefix (gi) gi:)
  3. ;; function of gi repository can be found at:
  4. ;; https://spk121.github.io/guile-gi/Typelib-Introspection.html
  5. (prefix (gi repository) gir:))
  6. ;; (use-typelibs ("GLib" "2.0")
  7. ;; ("Gio" "2.0")
  8. ;; ("Gtk" "3.0"))
  9. ;; Load Gio in version 2.0, but only, if it is not already
  10. ;; loaded.
  11. (gir:require "Gio" "2.0")
  12. ;; Load GTK in version 3.0, but only, if it is not already
  13. ;; loaded.
  14. (gir:require "Gtk" "3.0")
  15. ;; After having loaded the Gio and Gtk libraries, generate
  16. ;; bindings for the specified types.
  17. (gir:load-by-name "Gio" "Application") ; activate, run
  18. (gir:load-by-name "Gtk" "Application")
  19. (gir:load-by-name "Gtk" "ApplicationWindow")
  20. (gir:load-by-name "Gtk" "init")
  21. (gir:load-by-name "Gtk" "Widget") ; show-all
  22. ;; initialize GTK
  23. (init!)
  24. (define app:activate
  25. (λ (app)
  26. ;; ApplicationWindow has a constructur.
  27. (define window
  28. (gi:make <GtkApplicationWindow>
  29. ;; Set some values for the window.
  30. #:application app
  31. #:default-height 200
  32. #:default-width 200
  33. #:title "Example"))
  34. ;; Next widgets are being added to other widgets and
  35. ;; ultimately to the window. This is done using the (add
  36. ;; ...) function.
  37. ;; Show the windows of the application.
  38. (show-all window)))
  39. (define main
  40. (λ ()
  41. ;; Call Gtk's application:new to create a new
  42. ;; <GtkApplication>
  43. (let ([app (gi:make <GtkApplication> #:application-id "org.gtk.example")
  44. #;(application:new
  45. "org.gtk.example"
  46. ;; Application flags govern how the application
  47. ;; behaves. See more at:
  48. ;; https://docs.gtk.org/gio/flags.ApplicationFlags.html.
  49. (list->application-flags '(flags-none)))])
  50. (gi:connect app activate app:activate)
  51. (exit
  52. ;; Call application:run. If there are no arguments in
  53. ;; the command line args, this will send the `activate'
  54. ;; signal.
  55. (run app (gi:command-line))))))
  56. (main)