123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #| GTK Application Templage (Guile Scheme version). |#
- (import (prefix (gi) gi:)
- ;; function of gi repository can be found at:
- ;; https://spk121.github.io/guile-gi/Typelib-Introspection.html
- (prefix (gi repository) gir:))
- ;; (use-typelibs ("GLib" "2.0")
- ;; ("Gio" "2.0")
- ;; ("Gtk" "3.0"))
- ;; Load Gio in version 2.0, but only, if it is not already
- ;; loaded.
- (gir:require "Gio" "2.0")
- ;; Load GTK in version 3.0, but only, if it is not already
- ;; loaded.
- (gir:require "Gtk" "3.0")
- ;; After having loaded the Gio and Gtk libraries, generate
- ;; bindings for the specified types.
- (gir:load-by-name "Gio" "Application") ; activate, run
- (gir:load-by-name "Gio" "ApplicationFlags")
- (gir:load-by-name "Gio" "Menu") ; GMenu
- (gir:load-by-name "Gio" "MenuItem")
- (gir:load-by-name "Gtk" "Application")
- (gir:load-by-name "Gtk" "ApplicationWindow")
- (gir:load-by-name "Gtk" "init")
- (gir:load-by-name "Gtk" "Widget") ; show-all
- ;; For a more compact import consider this way of writing imports, taken from
- ;; the examples of the guile-gi repository:
- ;; (import (srfi srfi-26))
- ;; (for-each
- ;; (cute load-by-name "Gtk" <>)
- ;; '("ApplicationWindow" "Application" "Container" "Window" "Widget"))
- ;; initialize GTK
- (init!)
- (define app:activate
- (λ (app)
- ;; ApplicationWindow has a constructur.
- (define window
- (gi:make <GtkApplicationWindow>
- ;; Set some values for the window.
- #:application app
- #:default-height 200
- #:default-width 200
- #:title "Example"))
- (build-menu app window)
- ;; Show the windows of the application.
- (show-all window)))
- (define build-menu
- (λ (app window)
- (define menu (gi:make <GMenu>))
- (define exit-item
- (gi:make <GMenuItem>
- ;; #:text "test"
- #|#:label "Exit" #:translatable "yes" #:action "app.exit"|#))
- (append-item menu exit-item)
- 123))
- (define main
- (λ ()
- application:new
- (let ([app (gi:make <GtkApplication>
- #:application-id "org.gtk.example"
- #:flags (number->application-flags 0))])
- (gi:connect app activate app:activate)
- (exit
- ;; Call application:run. If there are no arguments in
- ;; the command line args, this will send the `activate'
- ;; signal.
- (run app (gi:command-line))))))
- (main)
- ;; GMenu *menu, *section;
- ;; menu = g_menu_new ();
- ;; section = g_menu_new ();
- ;; g_menu_append (section, "Incendio", "app.incendio");
- ;; g_menu_append_section (menu, "Offensive Spells", section);
- ;; g_object_unref (section);
- ;; section = g_menu_new ();
- ;; item = g_menu_item_new ("Expelliarmus", "app.expelliarmus");
- ;; g_menu_item_set_icon (item, defensive_icon);
- ;; g_menu_append_item (section, item);
- ;; g_menu_append_section (menu, "Defensive Charms", section);
- ;; g_object_unref (section);
|