MCPcopy Index your code
hub / github.com/RustPython/RustPython / do_button

Function do_button

wasm/notebook/snippets/python-js-css/javascript.js:12–26  ·  view source on GitHub ↗
(callback)

Source from the content-addressed store, hash-verified

10 },
11 add_button(buttonText, cb) {
12 const do_button = (callback) => {
13 const btn = document.createElement('button');
14 btn.innerHTML = buttonText;
15 btn.addEventListener('click', () => {
16 try {
17 // python functions passed to js have a signature
18 // of ([args...], {kwargs...}) => any
19 callback([], {});
20 } catch (err) {
21 // puts the traceback in the error box
22 handlePyError(err);
23 }
24 });
25 pushNotebook(btn);
26 };
27
28 if (cb == null) {
29 // to allow using as a decorator

Callers 1

add_buttonFunction · 0.85

Calls 2

createElementMethod · 0.80
callbackFunction · 0.50

Tested by

no test coverage detected