Giter Club home page Giter Club logo

Comments (2)

kayprish avatar kayprish commented on July 20, 2024 1

Thank you, I've looked into that issue and the other similar ones before, but I didn't immediately realize they were relevant for my problem, for anyone else facing the same issue, the fix I've ended up using is this one:

;;;; package.lisp

(defpackage #:iip-project
  (:use #:cl))

;;;; iip-project.lisp

(in-package #:iip-project)

(gtk:define-application (:name iip-project
                         :id "org.kayprish.iip-project")
  (cffi:defcallback open-file-callback :void ((file-dialog :pointer)
                                              (result :pointer)
                                              ; data now contains (img-original img-new)
                                              (data :pointer))
    (setf file-dialog (gobj:pointer-object file-dialog 'gtk:file-dialog))
    (setf data        (glib::get-object (cffi:pointer-address data)))
    (funcall
      (gtk::attach-restarts
        (lambda ()
          (alexandria:when-let ((img-original (first data))
                                (img-new      (second data))
                                (gfile        (ignore-errors
                                                (gtk:file-dialog-open-finish file-dialog result))))
            ; here do something with img-original and img-new
            )))))

  (gtk:define-main-window (window (gtk:make-application-window :application gtk:*application*))
    (let ((grid         (gtk:make-grid))
          (file-button  (gtk:make-button :label "Load file"))
          (img-original (gtk:make-image))
          (img-new      (gtk:make-image)))

      (gtk:connect file-button "clicked"
                   (lambda (button)
                     (let ((file-chooser  (gtk:make-file-dialog)))
                       (gtk:file-dialog-open file-chooser
                                             window
                                             nil
                                             (cffi:callback open-file-callback)
                                             ;;; THE FOLLOWING LINE CAUSES THE ERROR
                                             (cffi:make-pointer (glib::put-object (list img-original img-new)))))))

      (setf (gtk:window-child window) grid)

      (gtk:grid-attach grid img-original 0 1 1 1)
      (gtk:grid-attach grid file-button 0 2 1 1)

      (gtk:grid-attach grid img-new 2 1 1 1))
    (unless (gtk:widget-visible-p window)
      (gtk:window-present window))))

I'm closing this issue, thank you very much for the help bohonghuang, and thank you for writing this lovely binding!

from cl-gtk4.

bohonghuang avatar bohonghuang commented on July 20, 2024

user_data can only pass CFFI pointer. For the current workaround, please refer to issue #19.

from cl-gtk4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.