Detect Eto.Form closing in Python

Hi Guys,

I’ve been making good progress on using an ETO Form with WebView to build a UI for a Grasshopper based plugin.

What I’m now stuck on is detecting when the Form window is closed - so I can give users the option to open again or close rhino completely.

Here is my current Python code to launch the webview:

import rhinoscriptsyntax as rs
import scriptcontext
import Rhino
import Rhino.UI
import Eto as Eto
import Eto.Drawing as drawing
import Eto.Forms as forms
import time
import System

def OnClose():
rs.MessageBox(“Window was closed”)

my_webview = forms.WebView()
my_webview.Size = drawing.Size(200, 500)
my_webview.Url = System.Uri(‘http://localhost:3456/’)

launcher = Eto.Forms.Form()
launcher.Owner = Rhino.UI.RhinoEtoApp.MainWindow
launcher.Title = “WebView base UI for Grasshopper”
launcher.ClientSize = drawing.Size(480, 640)
launcher.Padding = drawing.Padding(10)
launcher.Resizable = True
launcher.Content = my_webview


Any tip to point me in the right direction?



The form has an event Closed that you can subscribe to.
I think the Python code would have to look something like this

def OnClosed(*args):

launcher.Closed += OnClosed
1 Like

@menno THANK YOU! That is working well - just what I needed.

Much love for the whole McNeel team, that’s two problems sorted for me today, you guys really are great!



I’m not with the McNeel team, but thanks nonetheless :smiling_face:


@menno - thank you directly then - that helped me so much!

Funny that I’m sitting in my office on a Friday evening stoked out on a piece of Python code!



1 Like