guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: G-Golf - Help with ListView needed


From: David Pirotte
Subject: Re: G-Golf - Help with ListView needed
Date: Mon, 6 Mar 2023 01:07:58 -0300

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: pgpJsYt83oyx1.pgp
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]