How to Position Eto Form in rhino?

I am working on my first Eto form in python, (thank you McNeel for posting examples! rhino-developer-samples/rhinopython at 6 · mcneel/rhino-developer-samples · GitHub )

I have been able to get started by adding a webview to one of the examples. I’m stuck trying to figure out how to position the form in the rhino window? This is what I have now. It works, I just don’t know how to position it…to somewhere besides the center of the window. (pretty sure this is the relevant bit)

 def WebViewerExample():
     dialog = SampleWebViewDialog();
     rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)

whole thing is here if it helps.

 import Rhino
 import scriptcontext
 import System
 import System.Drawing as sd
 import Rhino.UI
 import Eto.Drawing as drawing
 import Eto.Forms as forms

 # Using SampleEtoRoomNumber dialog Example as guide
 class SampleWebViewDialog(forms.Dialog[bool]):
     def __init__(self):
         self.Title = 'Web View Test'
         self.Padding = drawing.Padding(10)
         self.Resizable = True

         self.DefaultButton = forms.Button(Text = 'OK')
         self.DefaultButton.Click += self.OnOKButtonClick

         self.AbortButton = forms.Button(Text = 'Cancel')

         self.m_webview = forms.WebView()
         self.m_webview.Size = drawing.Size(400, 600)
         self.m_webview.Url = System.Uri('http://developer.rhino3d.com/guides/rhinopython/')

         layout = forms.DynamicLayout()
         layout.Spacing = drawing.Size(5, 5)
         layout.BeginVertical()
         layout.AddRow(self.m_webview)
         layout.EndVertical()
         layout.AddRow(None) # spacer

         layout.BeginVertical()
         layout.AddRow(self.DefaultButton, self.AbortButton)
         layout.EndVertical()

         self.Content = layout

     def OnCloseButtonClick(self, sender, e):
         self.Close(False)

     def OnOKButtonClick(self, sender, e):
         self.Close(True)

 def WebViewerExample():
     dialog = SampleWebViewDialog();
     rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)


 if __name__ == "__main__":
     WebViewerExample()

Hi @chanley,

This should do it:

dialog = SimpleEtoDialog()
dialog.Location = drawing.Point(5, 5)
dialog.ShowModal()

– Dale

Thank you @dale! Works perfectly. Are there any examples, (existing or planned), that describe how to make a form that allows interaction with Rhino while the form is active/open? I think that is what is being referred to here?:

The other dialog types, semi-modal and modeless, are beyond the scope of this guide, but may be useful in future projects

Thanks again for all the help McNeel gives to us!

Should have searched a little more before posting my question. Definitely pushing/accelerating the pace of me learning a bit about Eto Forms!

I believe you are referring to a modeless form. Here is an example:

https://github.com/mcneel/rhino-developer-samples/blob/6/rhinopython/SampleEtoModelessForm.py

– Dale

4 Likes

That is exactly what I was looking for!

1 Like

Four years later. …
Still find it amazing.
Thanks a lot

Position Eto Form in rhino
Does the panel have memory?

How to make the panel have memory? When I move the panel to another place, the next time it appears in the last position, can you write a case for me

if "P" in sc.sticky:
    a.Location = sc.sticky["P"]
rc = a.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
sc.sticky["P"] = a.Location