This would be really useful to dock youtube rhino-tutorials etc.
Hi - Does the Rhino WebBrowser command do what you want?
-wim
Hi Wim.
Im using Rhino 5 for mac and it deosnât seem to have that function. Is there an alternative?
@wim,
Plus this webbrowser is not very useful without activex (or whatever it is called) that supports JavaScript and Flash content.
We do not have plans to add WebBrowser to Rhino for Mac. I donât understand why this is needed.
For example, a browser component with the ability to send json between, say python, and the browser, can be a boon to cross-platform plugin development. Thatâs sketchupâs whole plugin model, basically.
I wrote a sample for doing this for Rhino 5 for Windows a few years ago.
It could probably use some âloveâ to make it work with Rhino 6 for Windows. Not sure what it takes to make this work on macOS.
â Dale
Thanks @jdhill, that is not a use-case I had considered. My understanding was that the WebBrowser command was in Rhino for Windows so that people could discretely watch World Cup games while pretending to work.
Despite the lack of the WebBrowser command in Rhino for Mac, you should still be able to do this with Etoâs WebView.
Nice! Hereâs a proof of concept that works, for letting javascript directly call python methods âŚ
import Rhino
import Eto
class WebDialog(Eto.Forms.Dialog[bool]):
def __init__(self):
self.Title = 'WebDialog'
self.Padding = Eto.Drawing.Padding(10)
self.Resizable = True
self.m_webview = Eto.Forms.WebView()
self.m_webview.Navigated += self.webview_nav
self.Content = self.m_webview
self.show_options()
def webview_nav(self, sender, e):
# Apparently, Url is always 'about:<window.location.href>' on my machine
# (Edge 41.16299.15.0), though I suppose this would require research, to
# see what is the behavior with other browsers.
url = sender.Url.ToString()
url_prefix = 'about:'
url_blank = 'blank'
try:
call = url[len(url_prefix):]
if call != url_blank:
eval('self.' + call)
except:
self.show_error('failed to call: %s' % url)
def style(self):
return '<style>%s</style>' % """
a {
display:block;
margin:4px;
padding:6px;
text-align:center;
cursor:pointer;
background-color:#eee;
}
"""
def script(self):
return '<script>%s</script>' % """
function pyinvoke(method) {
window.location.href = method;
}
"""
def head(self):
return '<head>%s%s</head>' % (self.style(), self.script())
def page(self, body):
self.m_webview.LoadHtml(
'<html><body>%s<body>%s</body></html>' % (self.head(), body)
)
def show_options(self):
self.page("""
<p>choose an option:</p>
<a onclick="pyinvoke('choose_option(0)')">option 0</a>
<a onclick="pyinvoke('choose_option(1)')">option 1</a>
<a onclick="pyinvoke('choose_option(2)')">option 2</a>
""")
def choose_option(self, opt):
opts = ['dead parrot', 'wafer-thin mint', 'flesh wound']
self.page("""
<p>congrats, you get a %s.</p>
<a onclick="pyinvoke('show_options()')">try again</a>
""" % opts[opt])
def show_error(self, msg):
self.page("""
<p>ERROR: %s</p>
<a onclick=pyinvoke('show_options()')">back to options</a>
""" % msg)
if __name__ == "__main__":
WebDialog().ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
Sure, who knows how it works on macos; the basic idea appears to work though, and could be extended â the web browser in dotnet exposed an âobject for scriptingâ that could be accessed by javascript, and I suppose it should be possible to do something similar, by reflecting a chosen an object and creating a corresponding json object to give the page. Eventually, you serialize the whole rhino api to json, so you can javascript rhino. 

