unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: David Pirotte <david@altosw.be>
To: Andy Tai <atai@atai.org>
Cc: guile-user@gnu.org
Subject: Re: G-Golf - how to access gtk APIS that take lists of arguments ending with null ptr
Date: Tue, 19 Jul 2022 14:48:50 -0300	[thread overview]
Message-ID: <20220719144850.623ae092@aicha> (raw)
In-Reply-To: <CAJsg1E_e5UDMouoF=gqzCptywYoBbLSvBsGqmi540bAq_iPjyw@mail.gmail.com>

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

Hello,

> How to call gtk APIs such as

> (gtk+ 3)

> gint
> gtk_tree_view_insert_column_with_attributes
>                                (GtkTreeView *tree_view,
>                                 gint position,
>                                 const gchar *title,
>                                 GtkCellRenderer *cell,
>                                 ...);

You don't. Rather, you define the column(s) and call add-attribute,
below, a quick example (no 'style', and in a real an large application
code, you'd separate the making and 'populating' of the store ...

David

;; drop this in a 'tree-store' or 'tree-store.scm' file
;; 	chmod a+x tree-store[.scm]
;; 	./tree-store[.scm]


#! /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 "3.0")
  (for-each (lambda (item)
              (gi-import-by-name "Gtk" item))
      '("Window"
        "VBox"
        "TreeStore"
        "TreeView"
        "TreeViewColumn"
        "CellRendererText"
        "init"
        "main"
        "main_quit")))

;; This example also shows the use of a none rendered 'object column
type.

(define (main args)
 (gtk-init 0 #f)
 (let* ((window (make <gtk-window>))
        (vbox (make <gtk-vbox>))
        (store (gtk-tree-store-new 3 '(int string object)))
        (treeview (make <gtk-tree-view> #:model store))
	(column1 (make <gtk-tree-view-column> #:title "Column 1"))
	(renderer1 (make <gtk-cell-renderer-text>))
	(column2 (make <gtk-tree-view-column> #:title "Column 2"))
	(renderer2 (make <gtk-cell-renderer-text>)))

   (connect window
	    'delete-event
	    (lambda (window event)
              (gtk-widget-destroy window)
              #f)) ;; do not stop the event propagation

   (connect window
            'destroy
	    (lambda (window)
	      (gtk-main-quit)
              #f)) ;; do not stop the event propagation

   (pack-start column1 renderer1 #f)
   (add-attribute column1 renderer1 "text" 0)
   (append-column treeview column1)

   (pack-start column2 renderer2 #f)
   (add-attribute column2 renderer2 "text" 1)
   (append-column treeview column2)

   (let ((iter1 (append store #f))
         (iter2 (append store #f)))
     (set-value store iter1 0 1)
     (set-value store iter1 1 "Hello ...")
     (set-value store iter1 2 column1)
     
     (set-value store iter2 0 2)
     (set-value store iter2 1 "... world!")
     (set-value store iter2 2 column2))

   (add window vbox)
   (add vbox treeview)
   (show-all window)
   (gtk-main)))

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

      reply	other threads:[~2022-07-19 17:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19 16:38 G-Golf - how to access gtk APIS that take lists of arguments ending with null ptr Andy Tai
2022-07-19 17:48 ` David Pirotte [this message]

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=20220719144850.623ae092@aicha \
    --to=david@altosw.be \
    --cc=atai@atai.org \
    --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).