I’m new to playing around with Eto Forms and Rhino UI and I want to place an Eto Web View in a Rhino Panel. I’m scripting in python.
By modifying a McNeel sample python file, I am showing a webview in a modeless Eto form. This is the file attached and code sample below.
Now, I would like to host the webview in a Rhino UI panel so that it can be docked while the user is working in Rhino. I saw the Rhino.UI.Panels.RegisterPanel( … ) method as pointed out on the forms here Add Panels - Rhino Developer - McNeel Forum. But I can’t figure out how to get this to work. The first argument it wants is a plugin and I don’t know how to make the eto webview into a ‘plugin’, you can see my failed attempt commented out in the code.
EtoModelessHTML_02.py (3.5 KB)
Thanks in advance for the help!
################################################################################
# MODIFIED EXAMPLE FILE
# SampleEtoModelessForm.py
# https://github.com/mcneel/rhino-developer-samples/blob/6/rhinopython/SampleEtoModelessForm.py
################################################################################
import System
import Rhino
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import scriptcontext as sc
################################################################################
# SampleEtoModelessForm class
################################################################################
class SampleEtoModelessForm(forms.Form):
# Initializer
def __init__(self):
self.m_selecting = False
# Basic form initialization
self.Initialize()
# Create the form's controls
self.CreateFormContents()
# Basic form initialization
def Initialize(self):
#self.Title = 'Sample Modeless Form'
self.Padding = drawing.Padding(0)
self.Resizable = True
self.Maximizable = False
self.Minimizable = False
self.ShowInTaskbar = False
self.MinimumSize = drawing.Size(600, 600)
# FormClosed event handler
self.Closed += self.OnFormClosed
def CreateWebView(self):
self.m_webview = forms.WebView()
self.m_webview.Url = System.Uri('http://developer.rhino3d.com/guides/rhinopython/')
return self.m_webview
# Create all of the controls used by the form
def CreateFormContents(self):
# Create layout
layout = forms.DynamicLayout()
layout.Padding = drawing.Padding(0)
layout.Spacing = drawing.Size(5, 5)
# Add controls to layout
layout.AddRow(self.CreateWebView())
# Set the content
self.Content = layout
# Form Closed event handler
def OnFormClosed(self, sender, e):
# Dispose of the form and remove it from the sticky dictionary
if sc.sticky.has_key('sample_modeless_form'):
form = sc.sticky['sample_modeless_form']
if form:
form.Dispose()
form = None
sc.sticky.Remove('sample_modeless_form')
################################################################################
# TestSampleEtoModelessForm function
################################################################################
def TestSampleEtoModelessForm():
# See if the form is already visible
if sc.sticky.has_key('sample_modeless_form'):
return
# Create and show form
form = SampleEtoModelessForm()
form.Owner = Rhino.UI.RhinoEtoApp.MainWindow
form.Show()
# Add the form to the sticky dictionary so it
# survives when the main function ends.
sc.sticky['sample_modeless_form'] = form
# Try and host the eto form within a panel but not right....
#panel = Rhino.UI.Panels.RegisterPanel(SampleEtoModelessForm(), forms.Panel, "Sample Panel", System.Drawing.SystemIcons.WinLogo)
################################################################################
# Check to see if this file is being executed as the 'main' python
# script instead of being used as a module by some other python script
# This allows us to use the module which ever way we want.
################################################################################
if __name__ == '__main__':
TestSampleEtoModelessForm()