Skip to content

Commit 952b7e6

Browse files
committed
forgot to add the example edits
1 parent eed670f commit 952b7e6

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

examples/sending-raw/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@
55
<title>Title</title>
66
</head>
77
<body>
8+
<h1>Hello there!</h1>
89

10+
<script src="/webui.js"></script>
11+
<script type="application/javascript">
12+
function myJavaScriptFunc(rawData) {
13+
// `rawData` should be a Uint8Array variable
14+
console.log("rawData: ", rawData)
15+
16+
// Create a Blob from the raw data, specifying the MIME type as 'image/png'
17+
const blob = new Blob([rawData], { type: 'image/png' });
18+
19+
// Generate a URL for the Blob
20+
const imageUrl = URL.createObjectURL(blob);
21+
22+
// Create an <img> element and set its src attribute to the Blob URL
23+
const img = document.createElement('img');
24+
img.src = imageUrl;
25+
26+
// Add the img element to the body of the html
27+
document.body.appendChild(img);
28+
console.log("Image has been added to the page.");
29+
}
30+
</script>
931
</body>
1032
</html>

examples/sending-raw/main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from webui import webui
2+
3+
def main():
4+
# Create an instance of a Window object
5+
my_window = webui.Window()
6+
7+
# Open an image file and read it in as byte data.
8+
with open("./webui_python.png", 'rb') as file:
9+
raw_bytes: bytes = file.read()
10+
11+
# Open the window using the html file in the project while getting the appropriate browser for the user.
12+
my_window.show_browser("index.html", my_window.get_best_browser())
13+
14+
#print(raw_bytes)
15+
# Send over the byte data from the picture to the javascript function we have in the html.
16+
my_window.send_raw("myJavaScriptFunc", raw_bytes)
17+
18+
# waits for all windows to close before terminating the program.
19+
webui.wait()
20+
21+
if __name__ == "__main__":
22+
main()
23+
24+

0 commit comments

Comments
 (0)