-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Hello,
I've been messing around with this library in clojure for a little bit now. I've really enjoyed it -- thanks for your work on this! It's been mostly smooth sailing so far, but I just ran into a bit of a roadblock. I'm not sure what level of clojure support you're aiming for, but I did notice #136 so I figured it would be worth asking about.
I'm having issues subclassing Widget related things in this project. I first noticed this after trying to override Widget.snapshot() to play around with GSK. I tried to use clojure's proxy to make my instance, but this caused a crash.
Here's a simplified example to illustrate what I've been seeing. You should be able to paste this into a clojure 1.12 REPL to test it out.
;; Load libs if running on the REPL (clojure >=1.12)
;; remove this and load deps with lien/deps.edn/whatever if not
(add-libs {`org.java-gi/gtk {:mvn/version "0.13.1"}
`org.java-gi/adw {:mvn/version "0.13.1"}})
;; Example code
(ns java-gi-test.override-example
(:import
(org.gnome.adw Application ApplicationWindow HeaderBar)
(org.gnome.gio ApplicationFlags)
(org.gnome.gtk Box Button Orientation)))
(def app (doto (Application. "override" (into-array ApplicationFlags [ApplicationFlags/DEFAULT_FLAGS]))
(.onActivate (reify org.gnome.gio.Application$ActivateCallback
(run [this]
(let [app-window (ApplicationWindow. app)]
(doto app-window
(.setTitle "Override Test")
(.setContent (doto (Box. Orientation/VERTICAL 0)
(.append (HeaderBar.))
(.append (doto (proxy [Button] []
(toString [] "I'm overriding something!"))
(.setLabel "Button!")))))
(.setDefaultSize 300 200)
(.present))))))))
(.run app nil)Not much going on here, we're just making a bare-bones application and putting in an anonymous subclass of Button that overrides toString().
When running it, I'm seeing an error like this in stdout:
(java:376724): java-gi-CRITICAL **: 15:17:12.414: Cannot register type Button$ff19274a: java.lang.IllegalArgumentException: Unsupported property type: ParamSpecBoxed
If you swap the Button proxy out for a regular instance (i.e. replacing (proxy [Button] []...) with (Button.)), the window should open up fine.
A few additional notes:
- The same thing happens you override a different method, or even nothing at all.
- Doing the same thing, but with
Widgetinstead ofButton, I get a similar error, but the "Unsupported property type" isString []. - I also tried out the
proxyfunction withWidget's parent classes. I notice any obvious problems creating them fromGObjects orInitiallyUnowneds.;; These run fine (-> (proxy [org.gnome.gobject.GObject] [] (toString [] "foo")) (.toString) (println)) (-> (proxy [org.gnome.gobject.InitiallyUnowned] [] (toString [] "bar")) (.toString) (println))
- Doing the same thing with an anonymous
Buttonsubclass and a.toString()override works fine in Java, so it seems safe to say that this has something to do with how clojure is creating the object.
I'm not quite sure what to make of all this, but hopefully some of it is useful information...
Using the gen-class function might be an option, but I haven't tested that out yet... I believe it would complicate using these libraries from the REPL, which wouldn't be ideal.