Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Nov 14, 2024
1 parent 349fd57 commit 2a553a9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
21 changes: 15 additions & 6 deletions app/static/js/core/sheet-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,21 @@ async function registerCellToButton(hyperlinkCellRef, scriptName, xwConfig) {
typeof globalThis.getAuth === "function"
? await globalThis.getAuth()
: "";
await xlwings.runPython(
window.location.origin +
config.appPath +
`/xlwings/custom-scripts-call/${scriptName}`,
{ ...xwConfig, auth: token },
);
if (config.onWasm) {
let body = await xlwings.getBookData(xwConfig);
await pyscriptDone;
let r = await window.custom_scripts_call(body, scriptName);
r = JSON.parse(r);
// let actions = r.toJs();
await xlwings.runActions(r);
} else {
await xlwings.runPython(
window.location.origin +
config.appPath +
`/xlwings/custom-scripts-call/${scriptName}`,
{ ...xwConfig, auth: token },
);
}
} finally {
sheet.getRange(selectedRangeAddress).getOffsetRange(1, 0).select();
await context.sync();
Expand Down
1 change: 1 addition & 0 deletions app/static/js/core/xlwingsjs/xlwings.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function init() {
config.appPath +
"/xlwings/custom-scripts-call/" +
element.getAttribute("xw-click");
// TODO: this is duplicated in sheet-buttons.js
if (config.onWasm) {
let body = await xlwings.getBookData(xwConfig);
await pyscriptDone;
Expand Down
1 change: 1 addition & 0 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
{% if settings.enable_wasm %}
<link rel="stylesheet" href="https://pyscript.net/snapshots/2024.9.2/core.css" />
<script type="module" src="https://pyscript.net/snapshots/2024.9.2/core.js"></script>
<script type="py" src="/wasm/main.py" config="/wasm/pyscript.json"></script>
{% endif %}
{% endblock head %}
</head>
Expand Down
3 changes: 0 additions & 3 deletions app/templates/examples/hello_world/taskpane_hello.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
{% block content %}
<div class="container-fluid pt-3 ps-3">
<h1>Example Task Pane</h1>
{# PyScript Test #}
<script type="py" src="/wasm/main.py" config="/wasm/pyscript.json"></script>
<button type="button" name="test" class="btn btn-primary btn-sm" py-click="test">PyScript Test</button>
<button xw-click="test" xw-config='{"exclude": "MySheet"}' class="btn btn-primary btn-sm" type="button">
WASM
</button>
Expand Down
1 change: 0 additions & 1 deletion app/wasm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
- Check out https://docs.pyscript.net/2024.5.2/user-guide/workers/
TODO:
- support sheet buttons
- make current_user optional
- look into toJS vs json (func vs script)
- run 10000 custom functions
Expand Down
3 changes: 1 addition & 2 deletions app/wasm/pyscript.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"sqlite3",
"pydantic",
"numpy",
"pandas",
"matplotlib"
"pandas"
],
"files": {
"/wasm/custom_functions/__init__.py": "./custom_functions/__init__.py",
Expand Down

0 comments on commit 2a553a9

Please sign in to comment.