Skip to content

Commit

Permalink
adds ltk + pyscript editor
Browse files Browse the repository at this point in the history
  • Loading branch information
abadoni5 committed Aug 21, 2024
1 parent 75a8f88 commit 5656e22
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 8 deletions.
1 change: 1 addition & 0 deletions _sources/index_en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Contents:
lectures/TWP58/toctree_en
lectures/TWP60/toctree_en
lectures/TWP65/toctree_en
lectures/TWP67/toctree_en
quiz/Quiz1_en.rst
quiz/Quiz2_en.rst
quiz/Quiz3_en.rst
Expand Down
1 change: 1 addition & 0 deletions _sources/index_es.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Contenidos:
lectures/TWP58/toctree
lectures/TWP60/toctree
lectures/TWP65/toctree
lectures/TWP67/toctree
quiz/Quiz1.rst
quiz/Quiz2.rst
quiz/Quiz3.rst
Expand Down
55 changes: 55 additions & 0 deletions _sources/lectures/TWP67/TWP67_1_en.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
===
PoC
===

Try These
---------


.. code-block:: python
import numpy as np
import matplotlib.pyplot as plt
from pyscript import display
# Define the domain
N = 55
X = np.linspace(-5, 5, N)
Y = np.sin(X)
# Plotting the values
plt.plot(X, Y, 'b-')
plt.grid(True)
# Display a message
print("The plot is displayed below:")
# Display the plot on the webpage
display(plt, target="output", append=False)
.. code-block:: python
import ltk
# Clear the output div before adding new content
ltk.find("#output").empty()
# Create and append new elements to the output div
(
ltk.VBox(
ltk.HBox(
ltk.Text("Hello"),
ltk.Button(
"World",
lambda event:
ltk.find(".ltk-button, a")
.css("color", "red")
)
.css("color", "blue")
)
)
.appendTo(ltk.find("#output")) # Append to the output div
)
.. raw:: html
:file: ../_static/index1.html
18 changes: 18 additions & 0 deletions _sources/lectures/TWP67/toctree.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
==========
Editor PoC
==========


.. image:: ../img/TWP10_001.jpeg
:height: 14.925cm
:width: 9.258cm
:align: center
:alt:


.. toctree::
:caption: Contenido
:maxdepth: 1
:numbered:

TWP67_1_en.rst
18 changes: 18 additions & 0 deletions _sources/lectures/TWP67/toctree_en.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
==========
Editor PoC
==========


.. image:: ../img/TWP10_001.jpeg
:height: 14.925cm
:width: 9.258cm
:align: center
:alt:


.. toctree::
:caption: Contenido
:maxdepth: 1
:numbered:

TWP67_1_en.rst
90 changes: 90 additions & 0 deletions _sources/lectures/_static/index1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="./mini-coi.js"></script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />

<link
rel="stylesheet"
href="https://pyscript.net/releases/2024.7.1/core.css"
/>
<script
type="module"
src="https://pyscript.net/releases/2024.7.1/core.js"
></script>

<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>
<link
rel="stylesheet"
href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css"
/>

<style>
/* Container for editor and output */
#container {
border: 2px solid #333; /* Dark border */
border-radius: 8px; /* Rounded corners */
padding: 20px; /* Space inside the container */
margin: 20px auto; /* Center the container horizontally and add top/bottom margin */
max-width: 90%; /* Maximum width of the container */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* Subtle shadow */
}

/* Output Div styling */
#output {
border: 1px solid #ccc;
padding: 10px;
margin-top: 10px;
overflow: auto;
resize: both; /* Allows the div to be resizable */
max-width: 100%; /* Ensures it doesn't overflow the viewport */
max-height: 80vh; /* Limits height to 80% of viewport height */
}

/* Clear button styling */
#clear-output-button {
display: block;
margin: 10px auto; /* Center the button horizontally */
padding: 6px 12px; /* Smaller padding */
font-size: 14px; /* Smaller font size */
border: none;
border-radius: 4px;
background-color: #007bff; /* Bootstrap primary color */
color: white;
cursor: pointer;
}

#clear-output-button:hover {
background-color: #0056b3; /* Darker blue on hover */
}
</style>
</head>
<body>
<div id="container">
<script
type="py-editor"
config='{
"packages": ["pyscript-ltk", "matplotlib", "numpy", "pandas", "sympy"],
"files": {
"https://raw.githubusercontent.com/pyscript/ltk/main/ltk/ltk.js": "ltk/ltk.js",
"https://raw.githubusercontent.com/pyscript/ltk/main/ltk/ltk.css": "ltk/ltk.css"
}}'
></script>
<button id="clear-output-button">Clear Display Area</button>

<!-- Output Div -->
<div id="output"></div>
</div>

<script>
// JavaScript function to clear the output div
document
.getElementById("clear-output-button")
.addEventListener("click", function () {
document.getElementById("output").innerHTML = "";
});
</script>
</body>
</html>
28 changes: 28 additions & 0 deletions _sources/lectures/_static/mini-coi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*! coi-serviceworker v0.1.7 - Guido Zuidhof and contributors, licensed under MIT */
/*! mini-coi - Andrea Giammarchi and contributors, licensed under MIT */
(({ document: d, navigator: { serviceWorker: s } }) => {
if (d) {
const { currentScript: c } = d;
s.register(c.src, { scope: c.getAttribute('scope') || '.' }).then(r => {
r.addEventListener('updatefound', () => location.reload());
if (r.active && !s.controller) location.reload();
});
}
else {
addEventListener('install', () => skipWaiting());
addEventListener('activate', e => e.waitUntil(clients.claim()));
addEventListener('fetch', e => {
const { request: r } = e;
if (r.cache === 'only-if-cached' && r.mode !== 'same-origin') return;
e.respondWith(fetch(r).then(r => {
const { body, status, statusText } = r;
if (!status || status > 399) return r;
const h = new Headers(r.headers);
h.set('Cross-Origin-Opener-Policy', 'same-origin');
h.set('Cross-Origin-Embedder-Policy', 'require-corp');
h.set('Cross-Origin-Resource-Policy', 'cross-origin');
return new Response(body, { status, statusText, headers: h });
}));
});
}
})(self);
8 changes: 0 additions & 8 deletions _sources/pycomponent.rst

This file was deleted.

0 comments on commit 5656e22

Please sign in to comment.