example-07-menu.scm 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "Gio" "ApplicationFlags")
  19. (gir:load-by-name "Gio" "Menu") ; GMenu
  20. (gir:load-by-name "Gio" "MenuItem")
  21. (gir:load-by-name "Gtk" "Application")
  22. (gir:load-by-name "Gtk" "ApplicationWindow")
  23. (gir:load-by-name "Gtk" "init")
  24. (gir:load-by-name "Gtk" "Widget") ; show-all
  25. ;; For a more compact import consider this way of writing imports, taken from
  26. ;; the examples of the guile-gi repository:
  27. ;; (import (srfi srfi-26))
  28. ;; (for-each
  29. ;; (cute load-by-name "Gtk" <>)
  30. ;; '("ApplicationWindow" "Application" "Container" "Window" "Widget"))
  31. ;; initialize GTK
  32. (init!)
  33. (define app:activate
  34. (λ (app)
  35. ;; ApplicationWindow has a constructur.
  36. (define window
  37. (gi:make <GtkApplicationWindow>
  38. ;; Set some values for the window.
  39. #:application app
  40. #:default-height 200
  41. #:default-width 200
  42. #:title "Example"))
  43. (build-menu app window)
  44. ;; Show the windows of the application.
  45. (show-all window)))
  46. (define build-menu
  47. (λ (app window)
  48. (define menu (gi:make <GMenu>))
  49. (define exit-item
  50. (gi:make <GMenuItem>
  51. ;; #:text "test"
  52. #|#:label "Exit" #:translatable "yes" #:action "app.exit"|#))
  53. (append-item menu exit-item)
  54. 123))
  55. (define main
  56. (λ ()
  57. application:new
  58. (let ([app (gi:make <GtkApplication>
  59. #:application-id "org.gtk.example"
  60. #:flags (number->application-flags 0))])
  61. (gi:connect app activate app:activate)
  62. (exit
  63. ;; Call application:run. If there are no arguments in
  64. ;; the command line args, this will send the `activate'
  65. ;; signal.
  66. (run app (gi:command-line))))))
  67. (main)
  68. ;; GMenu *menu, *section;
  69. ;; menu = g_menu_new ();
  70. ;; section = g_menu_new ();
  71. ;; g_menu_append (section, "Incendio", "app.incendio");
  72. ;; g_menu_append_section (menu, "Offensive Spells", section);
  73. ;; g_object_unref (section);
  74. ;; section = g_menu_new ();
  75. ;; item = g_menu_item_new ("Expelliarmus", "app.expelliarmus");
  76. ;; g_menu_item_set_icon (item, defensive_icon);
  77. ;; g_menu_append_item (section, item);
  78. ;; g_menu_append_section (menu, "Defensive Charms", section);
  79. ;; g_object_unref (section);