;; Copyright © 2024 Jaidyn Ann ;; ;; This program is free software: you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation, either version 3 of ;; the License, or (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . (import (chicken io) (chicken repl) (chicken string) (chicken time) srfi-18 nrepl qt-light) (define qt-app #f) ;; The object. (define qt-win #f) ;; The object. ;; Start & run the application. (define (init) ;; Set up some global state, prepare the QT app. (set! qt-app (qt:init)) (set! qt-win (create-window)) (init-window qt-win) (let ;; Start QT loop. [(qt-thread (thread-start! qt-loop)) ;; Kick off the remote-REPL… (nrepl-thread (thread-start! (lambda () (nrepl 1234))))] ;; … and also provide a local REPL. (repl) ;; Wait for the QT program, even after stdin is closed off. (thread-join! qt-thread))) ;; Loop through QT’s processing, again and again. (define (qt-loop) (qt:run #t) (qt-loop)) ;; Create the application window. (define (create-window) (qt:widget (window-contents))) ;; Return the UI’s XML, read from “contacts.ui”. ;; We could generate this XML ourselves, and write a nice s-expr front-end, ;; maybe… `o` (define (window-contents) (call-with-input-file "contact.ui" (lambda (in-port) (read-string #f in-port)))) ;; Initialize the window. (define (init-window window) (window-callbacks window) (qt:show window)) ;; Connect callback functions to widgets’ signals. (define (window-callbacks window) (menubar-callbacks window) (textbox-callbacks window)) ;; Connect callback functions to menubar items. (define (menubar-callbacks window) (let* [(menu-file-exit (qt:find window "actionQuit")) (menu-file-save (qt:find window "actionSave"))] ;; We connect to https://doc.qt.io/qt-6/qaction.html#triggered (if menu-file-exit (qt:connect menu-file-exit "triggered()" (qt:receiver exit))) (if menu-file-save (qt:connect menu-file-save "triggered()" (qt:receiver (lambda () (qt:message "Saving is not implemented."))))))) ;; Connect a text-printing callback to each textbox. (define (textbox-callbacks window) (let* [(property-names '("address" "city" "company" "country" "eMail" "fax" "homePhone" "name" "nickname" "state" "url" "workPhone" "zip")) (textboxes ;; The texbox widgets are all named like “countryLineEdit”. (map (lambda (property) (qt:find window (conc property "LineEdit"))) property-names))] ;; Cycle through each textbox, connecting them to a callback that prints ;; their contents each time you type in text. (map (lambda (textbox) ;; We connect to https://doc.qt.io/qt-6/qlineedit.html#textChanged ;; … and print the value of https://doc.qt.io/qt-6/qlineedit.html#text-prop ;; Also enable the File→Save menu-item (since, y’know, the user ;; changed something). It defaults to disabled in the contact.ui file. (if textbox (qt:connect textbox "textChanged(QString)" (qt:receiver (lambda () (let [(menu-file-save (qt:find window "actionSave"))] (if menu-file-save (set! (qt:property menu-file-save "enabled") #t))) (print (qt:property textbox "text"))))))) textboxes))) (init)