-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy-webview.py
More file actions
65 lines (50 loc) · 2.02 KB
/
py-webview.py
File metadata and controls
65 lines (50 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""py-webview
inputs:
trigger: a boolean toggle should do
points: a random data set i'm only using for this example
html_path: path to your html file (theoretically, you should be able to build out an entire dashboard here)"""
__author__ = "sandy"
import Rhino
import System
import Eto.Drawing as drawing
import Eto.Forms as forms
import json
class SampleEtoWebViewDialog(forms.Dialog[bool]):
def __init__(self, points, html_path):
super().__init__()
self.Title = 'Point Plot'
self.Padding = drawing.Padding(10)
self.Resizable = False
# convert guids to point3d
points_coords = []
for point in points:
points_coords.append([point.X, point.Y])
# load html content
try:
with open(html_path, 'r') as file:
html_template = file.read()
except Exception as e:
Rhino.RhinoApp.WriteLine(f"Error loading HTML file: {e}")
return
# pass data into html
points_json = json.dumps(points_coords)
html_content = html_template.replace('{{points}}', points_json) # you COULD also theoretically replace this section with a string containing the entire html code if for some reason, you want to do that and then call it later using the LoadHtml method
# create webview control
self.m_webview = forms.WebView()
self.m_webview.Size = drawing.Size(620, 620) # set webview size
# load html content
self.m_webview.LoadHtml(html_content)
# create layout
layout = forms.DynamicLayout()
layout.Spacing = drawing.Size(5, 5)
layout.AddRow(self.m_webview)
# create dialog content
self.Content = layout
self.ClientSize = drawing.Size(640, 640) # create dialog size
# webview
def DisplayWebView(points, html_path):
dialog = SampleEtoWebViewDialog(points, html_path)
dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
# call display
if trigger:
DisplayWebView(points, html_path)