Pressing a button in an ETO form crashes rhino

I have a very basic ETO form with a single button which when pressed should print some text. Pressing the button crashes rhino.

import Rhino
import Eto.Drawing as drawing
import Eto.Forms as forms
import rhinoscriptsyntax as rs

class MainWindow(forms.Form):
    def __init__(self):        
        self.Title = "test button"
        self.Padding = drawing.Padding(5)
        self.Resizable = False
        
        self.buttonTest = forms.Button(Text = "test")
        self.buttonTest.Click += self.OnTestButtonClick
        
        layout= forms.DynamicLayout()
        layout.AddRow(self.buttonTest)
        
        self.Content = layout
        
    def OnTestButtonClick():
        print "it works!!"
        
def OpenMainWindow():
    form = MainWindow()
    form.Owner = Rhino.UI.RhinoEtoApp.MainWindow
    form.Show()

if __name__ == '__main__':
    OpenMainWindow()

testButtonCrash.py (778 Bytes)

It seems to be due to the fact that I use a modless form. It works properly if I use a modal dialog.

I was able to make it work with a semi modal dialog (see code below).

import rhinoscriptsyntax as rs
import Rhino.UI

class MainWindow(forms.Dialog[bool]):
    def __init__(self):        
        self.Title = "test button"
        self.Padding = drawing.Padding(5)
        self.Resizable = False
        
        self.buttonTest = forms.Button(Text = "test")
        self.buttonTest.Click += self.OnTestButtonClick
        self.labelTest=forms.Label()
        self.labelTest.Text="this is a test"
        layout= forms.DynamicLayout()
        layout.AddRow(self.buttonTest)
        layout.AddRow(self.labelTest)
        
        self.Content = layout
        
    def OnTestButtonClick(self, sender, e):
        self.labelTest.Text="it works!!"
        
def OpenMainWindow():
    form = MainWindow()
    Rhino.UI.EtoExtensions.ShowSemiModal(form, Rhino.RhinoDoc.ActiveDoc, Rhino.UI.RhinoEtoApp.MainWindow)    

if __name__ == '__main__':
    OpenMainWindow()

1 Like