From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michele Lindroos Newsgroups: gmane.lisp.guile.user Subject: G-Golf - Help with ListView needed Date: Sat, 4 Mar 2023 11:09:14 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2910"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Mar 04 10:09:58 2023 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pYNtu-0000cS-64 for guile-user@m.gmane-mx.org; Sat, 04 Mar 2023 10:09:58 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pYNtV-0000ic-82; Sat, 04 Mar 2023 04:09:33 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pYNtR-0000gl-Es for guile-user@gnu.org; Sat, 04 Mar 2023 04:09:29 -0500 Original-Received: from mail-vs1-xe2a.google.com ([2607:f8b0:4864:20::e2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pYNtP-00061n-Cb for guile-user@gnu.org; Sat, 04 Mar 2023 04:09:28 -0500 Original-Received: by mail-vs1-xe2a.google.com with SMTP id f23so4552768vsa.13 for ; Sat, 04 Mar 2023 01:09:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677920966; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=PRAeDiRtnWP2fQDT1oJ8fBkRyQtYmPJP20hG8XVHCmc=; b=l/KkdwK20kOhEWdO/EoBmu5hMyiI/vi4PywEgb/0na8bDbxoGdIRZoXOpFU5v9pS8z oTfJnXtBrre48qG7js8n1gyAfk+VMfmJy7pf6M0D/O6vVajR1HgiVwwF5dcNugIB9Ply 17opGZapQs/ar83S/OgHcOUDkLlQE0bJTMgfBTsF7B6RRm3jT6+5Lg38D8XhtIKTDTGd a+sRZDnNJcO91yjDAircZjUvNqLYM1XBrPoWO6BwwU0GX4Tb387+aeAY+KwDrcPqSxFE tOs+keZhx6jX/d7ewMUWZoo81znkEvrDYjE6eK9nGJ8TwxtzzXjRfBrdf4/dIThTMQrq B1zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677920966; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PRAeDiRtnWP2fQDT1oJ8fBkRyQtYmPJP20hG8XVHCmc=; b=QPYp7Ck0N1idtbw5jGwTTfy4IIvn5gztjnzHN+qpiG0+bVdEq81pQkS/f9q1fNzpmR BYXEipKkIrQidnx/V1U0AyjGmelkBVeI6YE7RW2eBKVgR/d6BXmIDiMhIYs1UhylMTHW ak3hI5BegV8ICvT3G3kr6e0VmQpHERy0UxRpQiZ29s8vj/8qtpegilFcNXY5UbH+6TTu 5gSIOU4nnJj+c542hk18HHxX3FxEvQdhaTKhp6iqAyjBBRxz2aFgprFL5GzFtN/Ubd5g G289po6qNmEsbMdosV23/srO8chlLUqb42flg2AUmT7vGhfnt57vJ6IvfVOBAl4vYH0n sXWQ== X-Gm-Message-State: AO0yUKUJfzCYhJtv7tZzitfU/dTyCNLV6y1k35N9s/JcxSKN0MVcbjFK C04H932Qopgigp9vA6dhSnsl/3PldCYKow8h6un3IZQBvTyCNQ== X-Google-Smtp-Source: AK7set/bZ41uHqwkLXGmtEh0l6FHmpGK5TlXO8kQlVC5BOdidfUOWRMFADkNleNlWb1+V/hhzGXOSIdzwhSHJJLaPJc= X-Received: by 2002:a67:e94c:0:b0:421:c4a7:872b with SMTP id p12-20020a67e94c000000b00421c4a7872bmr1050297vso.6.1677920965689; Sat, 04 Mar 2023 01:09:25 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::e2a; envelope-from=keelefi@gmail.com; helo=mail-vs1-xe2a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:18922 Archived-At: Hello Guilers! 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. There are plenty of code samples online written in C. I've added at the bottom of the e-mail a code sample I tried and it works on my machine as expected. I tried to rewrite the code sample in guile scheme using g-golf. However, I don't get any elements drawn. Also, I get no error messages. I don't know where to look for solutions. Have I failed in translating the C code to scheme? Or is there some other problem? Any help is appreciated! BR, Michele $ cat list1.c #include static void setup_cb (GtkSignalListItemFactory *self, GtkListItem *listitem, gpointer user_data) { GtkWidget *lb = gtk_label_new (NULL); gtk_list_item_set_child (listitem, lb); /* Because gtk_list_item_set_child sunk the floating reference of lb, releasing (unref) isn't necessary for lb. */ } static void bind_cb (GtkSignalListItemFactory *self, GtkListItem *listitem, gpointer user_data) { GtkWidget *lb = gtk_list_item_get_child (listitem); /* Strobj is owned by the instance. Caller mustn't change or destroy it. */ GtkStringObject *strobj = gtk_list_item_get_item (listitem); /* The string returned by gtk_string_object_get_string is owned by the instance. */ gtk_label_set_text (GTK_LABEL (lb), gtk_string_object_get_string (strobj)); } static void unbind_cb (GtkSignalListItemFactory *self, GtkListItem *listitem, gpointer user_data) { /* There's nothing to do here. */ } static void teardown_cb (GtkSignalListItemFactory *self, GtkListItem *listitem, gpointer user_data) { /* There's nothing to do here. */ /* GtkListItem instance will be destroyed soon. You don't need to set the child to NULL. */ } static void app_activate (GApplication *application) { GtkApplication *app = GTK_APPLICATION (application); GtkWidget *win = gtk_application_window_new (app); gtk_window_set_default_size (GTK_WINDOW (win), 600, 400); GtkWidget *scr = gtk_scrolled_window_new (); gtk_window_set_child (GTK_WINDOW (win), scr); char *array[] = { "one", "two", "three", "four", NULL }; /* sl is owned by ns */ /* ns and factory are owned by lv. */ /* Therefore, you don't need to care about their destruction. */ GtkStringList *sl = gtk_string_list_new ((const char * const *) array); GtkNoSelection *ns = gtk_no_selection_new (G_LIST_MODEL (sl)); GtkListItemFactory *factory = gtk_signal_list_item_factory_new (); g_signal_connect (factory, "setup", G_CALLBACK (setup_cb), NULL); g_signal_connect (factory, "bind", G_CALLBACK (bind_cb), NULL); /* The following two lines can be left out. The handlers do nothing. */ g_signal_connect (factory, "unbind", G_CALLBACK (unbind_cb), NULL); g_signal_connect (factory, "teardown", G_CALLBACK (teardown_cb), NULL); GtkWidget *lv = gtk_list_view_new (GTK_SELECTION_MODEL (ns), factory); gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scr), lv); gtk_window_present (GTK_WINDOW (win)); } /* ----- main ----- */ #define APPLICATION_ID "com.github.ToshioCP.list1" int main (int argc, char **argv) { GtkApplication *app; int stat; app = gtk_application_new (APPLICATION_ID, G_APPLICATION_FLAGS_NONE); g_signal_connect (app, "activate", G_CALLBACK (app_activate), NULL); stat =g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); return stat; } $ cat gtk-signal-list-item-factory.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 "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" "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 #:default-width 600 #:default-height 400 #:application app)) (scr (make )) (array '("one" "two" "three" "four")) (sl (make #:strings array)) (ns (make #:model sl)) (signal-list-item-factory (make )) (lv (make #:model ns #:factory signal-list-item-factory))) (connect signal-list-item-factory 'setup (lambda (factory item) (let* ((lb (make ))) (set-child item lb)))) (connect signal-list-item-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 #:application-id "keele.g-golf.gtk-signal-list-item-factory"))) (connect app 'activate activate) (let ((status (g-application-run app args))) (exit status))))