Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Feb 9, 2025
1 parent 35de6cb commit 8e18c98
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
3 changes: 1 addition & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
- fix datetime bug in xlwings
- allow to run whole module instead of single script
- store pyodide version in xml
- only store editor content if not empty/default
- requirements.txt file vs editor
- own repo
Expand Down Expand Up @@ -29,3 +27,4 @@
- is it a problem that everything is running in the same Pyodide session?
- use a worker
- handle DuplicateName when re-registring custom functions
- allow to run whole module instead of single script?
11 changes: 8 additions & 3 deletions app/lite/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ def flush(self):


# Print Python and Pyodide versions
print(f"Python version: {platform.python_version()}")
print(f"Pyodide version: {pyodide_js.version}")
print(f"xlwings version: {xw.__version__}")
html_output = HtmlOutput("output")
with (
contextlib.redirect_stdout(html_output),
contextlib.redirect_stderr(html_output),
):
print(
f"Python {platform.python_version()} | Pyodide {pyodide_js.version} | xlwings {xw.__version__}"
)


async def custom_functions_call(data, module_string=None):
Expand Down
15 changes: 7 additions & 8 deletions app/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const monacoEditor = {
requirements: {
name: "requirements.txt",
isActive: false,
defaultContent: "# Add your requirements here\n",
defaultContent: "",
},
},

Expand All @@ -20,9 +20,7 @@ const monacoEditor = {
scripts: [],
selectedScript: "",
scriptButtonText() {
return this.scripts.length
? `▶ ${this.selectedScript}`
: "▶ Select Script";
return this.scripts.length ? `${this.selectedScript}` : "(no script)";
},
selectScript() {
this.selectedScript = this.$el.textContent;
Expand Down Expand Up @@ -64,7 +62,9 @@ const monacoEditor = {
return { active: this.isTabActive(this.$el.dataset.tab) };
},
},

buttonDisabled() {
return this.isRunning || this.scripts.length === 0;
},
isRunning: false,
spinner: {
[":class"]() {
Expand Down Expand Up @@ -193,10 +193,12 @@ const monacoEditor = {

async saveContent(filename) {
const content = editorInstance.getValue();
let pyodide = await xlwings.pyodideReadyPromise;
// Store
await Excel.run(async (context) => {
const settings = context.workbook.settings;
settings.add(filename, content);
settings.add("pyodideVersion", pyodide.version);
await context.sync();
console.log(`${filename} stored`);
this.isSaved = true;
Expand All @@ -210,7 +212,6 @@ const monacoEditor = {
JSON.stringify(meta),
rendered_custom_functions_code,
);
let pyodide = await xlwings.pyodideReadyPromise;
await pyodide.FS.writeFile(
"custom-functions-wrappers.js",
globalThis.liteCustomFunctionsCode(content),
Expand All @@ -220,8 +221,6 @@ const monacoEditor = {
// Install requirements.txt TODO: factor out
if (config.onLite) {
if (filename === "requirements.txt") {
let pyodide = await xlwings.pyodideReadyPromise;

// Setup output redirect
const outputDiv = document.querySelector("#output");
outputDiv.innerHTML = "";
Expand Down
8 changes: 5 additions & 3 deletions app/templates/examples/hello_world/taskpane_hello.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ <h1 class="my-3 px-3">xlwings Lite <span class="badge bg-warning text-dark">Prev
{# Run button #}
<div class="btn-group">
{# Run button #}
<button type="button" class="btn btn-primary btn-sm ps-4 pe-1" @click="run" :disabled="isRunning">
<button type="button" class="btn btn-primary btn-sm ps-4 pe-1" @click="run" :disabled="buttonDisabled">
<span class="me-1"></span>
<span x-text="scriptButtonText"></span>
<span x-bind="spinner" class="spinner-border spinner-border-sm"></span>
</button>
Expand All @@ -22,7 +23,8 @@ <h1 class="my-3 px-3">xlwings Lite <span class="badge bg-warning text-dark">Prev
type="button"
class="btn btn-primary btn-sm dropdown-toggle dropdown-toggle-split"
data-bs-toggle="dropdown"
aria-expanded="false">
aria-expanded="false"
:disabled="buttonDisabled">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
Expand Down Expand Up @@ -61,7 +63,7 @@ <h1 class="my-3 px-3">xlwings Lite <span class="badge bg-warning text-dark">Prev
</div>
<div class="resizer" x-ref="resizer"></div>
<div x-ref="output-container" style="height: 150px;" class="d-flex flex-column">
<div class="px-3 py-2 flex-grow-1" id="output" x-ref="output">Output Console</div>
<div class="px-3 py-2 flex-grow-1" id="output" x-ref="output"></div>
</div>
</div>
</div>
Expand Down

0 comments on commit 8e18c98

Please sign in to comment.