Human UI close window on button click within window

Hello,

I am wondering whether it is possible to have a “close” button inside a Human UI window to close that same window (i.e. change the “show window” toggle to false)? My intention is that I have a button in another Human UI window that the user can click to open the secondary window, and then hit “close” within the secondary window to hide it again.

I have tried the following definition, and the “Close” button works to close the window, but the problem is that when the window closes the button gets stuck on “True” and does not send the unclick “False” (presumably because the window closes before the unclick).

I’ve tried adding a data dam or a python sleep component to delay the closing of the window until the unclick event has happened, but those methods don’t work. Data dam only sends through the data that exists at the end of the dam interval, so by the time the delay is over the button is unclicked and it only sends through the false. The python sleep method stops all computation so the same problem exists as without it (the button stays pressed during the pause and window closes immediately after the True is sent at the end of the pause). I’m quite a newby with python so forgive me if those things are obvious.

Appreciate any suggestions - thanks!

closeWindow.gh (10.6 KB)

hi,
a bastard solution with data input and data output…

Thank you. I got that to work with the button connected only through the 1 stream on the stream filter. However, it slows down my script significantly (especially with multiple data out/in loops in the file).

If there is a more direct solution that would be great.

Anything new on that subject ?

In case anyone looking for alternatives, you can use two boolean buttons to represent wasRun and wasCancelled states. In my Window, I use Accept to modify wasRun and Cancel to modify wasCancelled.

There are 3 possible states to toggle Show in the Launch Window component:

  1. Default state: wasRun == False && wasCancelled == False
  2. Accept state: wasRun == True && wasCancelled == False
  3. Cancel state: wasRun == False && wasCancelled == True

You can use python component to evaluate the boolean states of the buttons and use the output to toggle the Launch Window Component.

wasRun = y
wasCancelled = x

if wasRun == False and wasCancelled == False:
    toggle = True
elif wasRun == False and wasCancelled == True:
    toggle = False
else:
    toggle = False

a = toggle

You can also extend this ‘gate’ like deciding what data pass through when user click Accept or terminate the program when user click Cancel.
Close Window Sample.gh (27.9 KB)