SCdF
SCdF

Reputation: 59408

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

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?

Upvotes: 5

Views: 397

Answers (2)

Dave Ray
Dave Ray

Reputation: 40005

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. :)

Upvotes: 4

Ankur
Ankur

Reputation: 33637

You cannot do that if you don't have that function reference. What you can do is use *1 special vara in REPL, which basically stores the result of last executed expression, to remove the handlers from the REPL.

Upvotes: 0

Related Questions