unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* G-Golf - how to access gtk APIS that take lists of arguments ending with null ptr
@ 2022-07-19 16:38 Andy Tai
  2022-07-19 17:48 ` David Pirotte
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Tai @ 2022-07-19 16:38 UTC (permalink / raw)
  To: guile-user

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,
                                ...);

with arguments as list of attributes to end with a NULL?

I tried to find this function name and it is not found at guile level
after GI import.

Thanks for info



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: G-Golf - how to access gtk APIS that take lists of arguments ending with null ptr
  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
  0 siblings, 0 replies; 2+ messages in thread
From: David Pirotte @ 2022-07-19 17:48 UTC (permalink / raw)
  To: Andy Tai; +Cc: guile-user

[-- 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 --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-19 17:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).