Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove listeners from an object in Seesaw if I haven't kept the return function?

Tags:

clojure

seesaw

To add a listener to a UI element in Seesaw you do this:

(listen ui-element :action (fn [_] (...)))

listen attaches a listener that calls the provided function when :action is triggered on `ui-element1. It also returns a function. If you execute that function it removes the listener that was added with the original call.

I've been prototyping UIs in the REPL using Seesaw, and I haven't kept the return values from listen.

If I don't have the returned function, how can I remove listeners?

like image 465
SCdF Avatar asked Oct 05 '22 01:10

SCdF


1 Answers

You can manually remove listeners in the following crude way:

user=> (def b (button :text "HI"))
user=> (listen b :action #(alert % "HI!"))
user=> (-> (frame :content b) pack! show!)
; click the button, see the alert
; manually remove listeners
user=> (doseq [l (.getActionListeners b)] (.removeActionListener b l))
; click the button, nothing happens

You could put this in a helper function and use it whenever. Having this built-in somehow to seesaw.event or seesaw.dev would also be nice. Patches welcomed. :)

like image 198
Dave Ray Avatar answered Oct 13 '22 11:10

Dave Ray