Jan Nieuwenhuizen writes: Hello Mike,
I have isolated a Guile-GI crash in Guimax and put it into the editor example. When I run the editor and press split, I get --8<---------------cut here---------------start------------->8--- $ tools/uninstalled-env tools/guile-gi examples/editor.scm ... buffer-window #<<GtkBox> 22c3f00> key: 65507 key: 65507 key: 65505 buffer-window #<<GtkBox> 22c3a50> ;;; WARNING (make-box children (#<<user-data> widget: #<<GtkBox> 22c3f00> window: #<<GtkScrolledWindow> 22c3d70> view: #<<GtkTextView> 22c3d20> mode-line: #<<GtkLabel> 22c3dc0>> #<<user-data> widget: #<<GtkBox> 22c3a50> window: #<<GtkScrolledWindow> 22c38c0> view: #<<GtkTextView> 22c3870> mode-line: #<<GtkLabel> 22c3910>>)) ui-data #<<user-data> widget: #<<GtkBox> 22c3f00> window: #<<GtkScrolledWindow> 22c3d70> view: #<<GtkTextView> 22c3d20> mode-line: #<<GtkLabel> 22c3dc0>> w= #<<GtkBox> 22c3f00> (editor.scm:14686): Gtk-CRITICAL **: 08:19:03.500: gtk_box_pack: assertion 'GTK_IS_WIDGET (child)' failed ui-data #<<user-data> widget: #<<GtkBox> 22c3a50> window: #<<GtkScrolledWindow> 22c38c0> view: #<<GtkTextView> 22c3870> mode-line: #<<GtkLabel> 22c3910>> w= #<<GtkBox> 22c3a50> (editor.scm:14686): Gtk-CRITICAL **: 08:19:03.500: gtk_container_remove: assertion 'GTK_IS_WIDGET (widget)' failed --8<---------------cut here---------------end--------------->8--- I'm pretty sure this works in the other UI backends, but I could be doing something wrong, of course. Can you help me with this? See attached patch or https://gitlab.com/janneke/guile-gi.git Greetings, janneke
>From d7a94f9282202fa63acc4a9ea6b5a832d58a93d7 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen <[email protected]> Date: Wed, 10 Jul 2019 08:22:08 +0200 Subject: [PATCH] editor: Add window split. --- examples/editor.scm | 107 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 94 insertions(+), 13 deletions(-) diff --git a/examples/editor.scm b/examples/editor.scm index 4ddf437..cd1b569 100644 --- a/examples/editor.scm +++ b/examples/editor.scm @@ -14,46 +14,118 @@ ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <https:;;www.gnu.org/licenses/>. (use-modules (gi) - (ice-9 receive)) + (ice-9 receive) + (srfi srfi-9)) (typelib-load "Gio" "2.0") (typelib-load "Gdk" "3.0") (typelib-load "Gtk" "3.0") (typelib-load "GLib" "2.0") -(typelib-load "WebKit2" "4.0") +(typelib-load "Pango" "1.0") ;; Oddly, the introspection information does not provide a constructor ;; for GtkTextIter. (define (text-iter:new) (make-gstruct <GtkTextIter>)) +(define (rgba:new) + (make-gstruct <GdkRGBA>)) + (define (print-goodbye widget) (display "Goodbye World\n")) (define (key-press widget event) (receive (ok keyval) - (with-object event (get-keyval?)) + (with-object event (get-keyval)) (format #t "key: ~s\n" keyval) #f)) +(define-record-type <user-data> + (make-user-data widget window view mode-line) + user-data? + (widget user-data-widget) + (window user-data-window) ; GI: avoid `children' + (view user-data-view set-user-data-view) + (mode-line user-data-mode-line)) + +(define (make-box children orientation) + (warn 'make-box 'children children) + (let ((box (create <GtkBox> + (orientation (if (eq? orientation 'vertical) + ORIENTATION_VERTICAL + ORIENTATION_HORIZONTAL)) + (spacing 0)))) + (with-object box (set-homogeneous #t)) + (for-each + (lambda (ui-data) + (format (current-error-port) "ui-data ~a\n" ui-data) + (let* ((w (if (user-data? ui-data) (user-data-widget ui-data) ui-data)) + (parent (with-object w (get-parent)))) + (format (current-error-port) "w= ~a\n" w) + (when w + (when parent + (let ((parent (cast parent <GtkBox>))) + (with-object parent (remove w)))) + (with-object box (pack-start w #t #t 0))))) + children) + (with-object box (show-all)) + box)) + +(define (make-buffer-window) + (let ((vbox (create <GtkBox> + (orientation ORIENTATION_VERTICAL) + (spacing 0))) + (ebox (create <GtkEventBox>)) + (bgc (cast (rgba:new) <GdkRGBA>)) + (mode-line (create <GtkLabel>)) + (window (create <GtkScrolledWindow>)) + (view (create <GtkTextView>))) + + (using mode-line + (set-halign ALIGN_START) + (set-markup " :--- guimax") + (set-line-wrap #f)) + (using window (set-policy POLICY_AUTOMATIC POLICY_AUTOMATIC)) + (using bgc (parse? "lightgray")) + (using ebox (override-background-color STATE_NORMAL bgc)) + + (using view (modify-font (font-description-from-string "monospace 18"))) + + (using vbox + (pack-start window #t #t 0) + (pack-start ebox #f #f 0)) + (using ebox (add mode-line)) + (using window (add view)) + + (format (current-error-port) "buffer-window ~a\n" vbox) + (make-user-data vbox window view mode-line))) + (define (activate app) - (let ((window (cast (application-window:new app) <GtkApplicationWindow>)) - (vbox (cast (vbox:new 0 0) <GtkVBox>)) - (editor (cast (text-view:new) <GtkTextView>)) - (button-box (cast (button-box:new 0) <GtkButtonBox>)) - (button (button:new-with-label "Quit")) - (button2 (button:new-with-label "Hello"))) + (let* ((window (cast (application-window:new app) <GtkApplicationWindow>)) + (vbox (cast (vbox:new 0 0) <GtkVBox>)) + (button-box (cast (button-box:new 0) <GtkButtonBox>)) + (button-hello (button:new-with-label "Hello")) + (button-split (button:new-with-label "Split")) + (button-quit (button:new-with-label "Quit")) + (buffer-window (make-buffer-window)) + (editor (user-data-view buffer-window)) + (container (user-data-widget buffer-window))) (with-object editor (add-events EVENT_MASK_KEY_PRESS_MASK) (connect! key-press-event key-press)) - (with-object button-box (add button2) (add button)) - (with-object vbox (add editor) (add button-box)) + (with-object button-box + (add button-hello) + (add button-split) + (add button-quit)) + (with-object vbox + (add container) + (add button-box)) (with-object window (set-title "Window") (set-default-size 200 200) (add vbox)) - (with-object button + (with-object button-quit (connect! clicked print-goodbye) (connect! clicked (lambda x (with-object window (destroy))))) @@ -61,7 +133,7 @@ ;; When the 'hello' button is clicked, write the current contents ;; of the editor to the console, and replace the buffer contents ;; with 'Hello, world'. - (with-object button2 + (with-object button-hello (connect! clicked (lambda x (let ((buffer (with-object editor (get-buffer))) (iter1 (text-iter:new)) @@ -71,6 +143,15 @@ (write txt) (newline)) (with-object buffer (set-text "Hello, world" 12)))))) + (with-object button-split + (connect! clicked (lambda x + (let* ((children (list buffer-window (make-buffer-window))) + (container' (make-box children 'horizontal))) + (with-object vbox + (remove container) + (add container') + (show-all)))))) + (with-object editor (grab-focus)) (with-object window (show-all)))) -- 2.21.0
-- Jan Nieuwenhuizen <[email protected]> | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | AvatarĀ® http://AvatarAcademy.com
