unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: David Pirotte <david@altosw.be>
To: guile-user@gnu.org
Subject: Re: G-Golf - Help with ListView needed
Date: Mon, 6 Mar 2023 01:07:58 -0300	[thread overview]
Message-ID: <20230306010758.454a9bb1@aicha> (raw)
In-Reply-To: <CAEvXz3TpvCsXFMHn3uba7G-CUF4+UZV1amMUCSRYC7N69LZ9jA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3502 bytes --]

Hello Michele,

> I'm trying to learn g-golf. It has been a blast, great technology!
> However, the last few days I've tried to get ListView working and now
> I'm stuck.

Below a working version.

In the C code, you should:

	app = gtk_application_new (APPLICATION_ID, G_APPLICATION_DEFAULT_FLAGS);
	
	/* so, not G_APPLICATION_FLAGS_NONE *?

In the scheme code, there were three problems

1.	you need to import "ListItem"

2.	 you must call the constructor gtk-string-list-new

	(gtk-string-list-new '("one" "two" "three" "four"))
and not
	(make <gtk-string-list> #:strings  '("one" "two" "three"
	"four"))

the later does not fail, but (get-n-items ...) => 0, instead of 4, and
then, the factory signal are never triggered ...

It is not obvious when you may and when you may not, but in the doc,
you'll see 'Readable no, ..., Construct no', Construct-only yes', then
try the constructor instead of the scheme idiomatic 'way' ... [of
course always prefer the scheme idiomatic way when allowed ...].

3.	in your factory 'bind signal callback, you called 

	... 
		(get-child (item))
		(get-item (item))
	...
	
instead of, it should be

	...
		(get-child item)
		(get-item item)
	...

Thanks,
David

#! /bin/sh
# -*- mode: scheme; coding: utf-8 -*-
exec guile -e main -s "$0" "$@"
!#

(eval-when (expand load eval)
    (use-modules (oop goops))

    (default-duplicate-binding-handler
        '(merge-generics replace warn-override-core warn last))

    (use-modules (g-golf))

    (g-irepository-require "Gtk" #:version "4.0")

    #;(for-each (lambda (name)
              (gi-import-by-name "Gdk" name))
        '("Display"))

    (for-each (lambda (name)
              (gi-import-by-name "Gtk" name))
        '("Application"
          "ApplicationWindow"
          "Label"
          "ListView"
          "ListItem"
          "NoSelection"
          "ScrolledWindow"
          "SignalListItemFactory"
          "StringList"
          "StringObject"))

    #;(for-each (lambda (name)
              (gi-import-by-name "Gio" name))
        '("ListStore")))

(define (activate app)
  (let* (#;(display (gdk-display-get-default))
         (window (make <gtk-application-window>
                   #:default-width 600
                   #:default-height 400
                   #:application app))
         (scr (make <gtk-scrolled-window>))
         (lst '("one" "two" "three" "four"))
         #;(sl (make <gtk-string-list> #:strings lst))
         (sl (gtk-string-list-new lst))
         (ns (make <gtk-no-selection> #:model sl))
         (factory (make <gtk-signal-list-item-factory>))
         (lv (make <gtk-list-view>
               #:model ns
               #:factory factory)))

    (connect factory
             'setup
             (lambda (factory item)
               (set-child item
                          (make <gtk-label>))))

    (connect factory
             'bind
             (lambda (factory item)
               (let* ((lb (get-child item))
                      (obj (get-item item)))
                 (set-label lb (get-string obj)))))

    (set-child window scr)
    (set-child scr lv)
    (show window)))

(define (main args)
  (let ((app (make <gtk-application>
               #:application-id "keele.g-golf.gtk-signal-list-item-factory")))
    (connect app 'activate activate)
    (let ((status (g-application-run app args)))
      (exit status))))



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  parent reply	other threads:[~2023-03-06  4:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-04  9:09 G-Golf - Help with ListView needed Michele Lindroos
2023-03-05  2:35 ` David Pirotte
2023-03-06  4:07 ` David Pirotte [this message]
2023-03-06 15:50   ` Michele Lindroos
2023-03-06 22:09     ` David Pirotte
2023-03-07 18:55       ` Michele Lindroos
2023-03-09 22:08         ` David Pirotte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230306010758.454a9bb1@aicha \
    --to=david@altosw.be \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).