Skip to content

Commit

Permalink
deploy: 3277c11
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanguage committed Dec 28, 2023
1 parent aaa1be3 commit a11cfcd
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
await restart();
}

async insertHtml(htmlSrc, width = "50%", height = "400px") {
async insertHtml(htmlSrc, width = "100%", height = "400px") {
const term = window.term;
const encoded = encodeURIComponent(htmlSrc);
const iframe = document.createElement("iframe");
Expand Down
113 changes: 113 additions & 0 deletions python-editor.imjoy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<config lang="json">
{
"name": "PyEditor",
"type": "web-worker",
"tags": [],
"ui": "",
"version": "0.1.2",
"cover": "",
"description": "A Script Editor for Python",
"icon": "extension",
"inputs": null,
"outputs": null,
"api_version": "0.1.8",
"env": "",
"permissions": [],
"requirements": [],
"dependencies": []
}
</config>

<script lang="javascript">
class ImJoyPlugin {
async setup() {
api.log('initialized')
let pycon = await api.getWindow("web-python-console")
if (!pycon) {
pycon = await api.createWindow({
src: 'https://nanguage.github.io/web-python-console/',
name: 'web-python-console',
w: 30,
h: 40,
})
}
this.pycon = pycon
}

async run(ctx) {
let pluginInEditor, stopped, editorWindow;
const config = {lang: 'python'}
const pycon = this.pycon
config.templates = [
{
name: "Matplotlib demo",
url: "https://nanguage.github.io/web-python-console/test_matplotlib.py",
lang: 'python',
},
{
name: "Altair plot demo",
url: "https://nanguage.github.io/web-python-console/test_altair.py",
lang: 'python',
},
]
config.ui_elements = {
save: {
_rintf: true,
type: 'button',
label: "Save",
visible: false,
icon: "content-save",
callback(content) {
console.log(content)
}
},
run: {
_rintf: true,
type: 'button',
label: "Run",
icon: "play",
visible: true,
shortcut: 'Shift-Enter',
async callback(content) {
try {
editorWindow.setLoader(true);
api.showProgress(0);
pycon.exec(content)
} catch (e) {
api.showMessage("Failed to run script, error: " + e.toString());
} finally {
editorWindow.setLoader(false);
api.showProgress(100);
}
}
},
export: {
_rintf: true,
type: 'button',
label: "Export",
icon: "file-download-outline",
visible: true,
async callback(content) {
const isHTML = content.trim().startsWith('<')
if(isHTML){
const fileName = (pluginInEditor && pluginInEditor.config.name && pluginInEditor.config.name + '.imjoy.html') || config.name + '.imjoy.html' || "myPlugin.imjoy.html";
await api.exportFile(content, fileName);
}
else{
const fileName = await api.prompt("Save as", "script.py")
if(fileName) await api.exportFile(content, fileName);
}
}
}
}
editorWindow = await api.createWindow({
src: 'https://if.imjoy.io',
name: (ctx && ctx.data && ctx.data.name) ||'Python Script Editor',
config,
data: {code: ctx && ctx.data && ctx.data.code}
})
}
}

api.export(new ImJoyPlugin())
</script>
2 changes: 1 addition & 1 deletion test_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Z = np.sin(np.sqrt(X**2 + Y**2))

# Create the plot
plt.figure(figsize=(10, 8))
plt.figure(figsize=(5, 4))
plt.contourf(X, Y, Z, cmap='viridis')
plt.colorbar()

Expand Down

0 comments on commit a11cfcd

Please sign in to comment.