From 572eb18b57630f991a4ceeb48b10cacf43491113 Mon Sep 17 00:00:00 2001
From: sheepmax <guichardmax@gmail.com>
Date: Thu, 13 Jul 2023 15:09:52 +0200
Subject: [PATCH] Moved build file to root, improved interactive code styling,
 added checks for python command in build file

---
 book/build-lite.sh              |  7 -------
 book/thebe_lite/code.css        | 26 ++++++++++++++++++++++++++
 book/thebe_lite/sphinx-thebe.js | 29 ++++++++++++++++++++++-------
 build-lite.sh                   | 20 ++++++++++++++++++++
 4 files changed, 68 insertions(+), 14 deletions(-)
 delete mode 100755 book/build-lite.sh
 create mode 100644 book/thebe_lite/code.css
 create mode 100755 build-lite.sh

diff --git a/book/build-lite.sh b/book/build-lite.sh
deleted file mode 100755
index aea0d7b7..00000000
--- a/book/build-lite.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh
-
-jupyter-book build ./
-cp thebe_lite/libs/* _build/html -r
-cp thebe_lite/sphinx-thebe.js _build/html/_static
-
-python3 -m http.server --directory _build/html
diff --git a/book/thebe_lite/code.css b/book/thebe_lite/code.css
new file mode 100644
index 00000000..8b13e44b
--- /dev/null
+++ b/book/thebe_lite/code.css
@@ -0,0 +1,26 @@
+.CodeMirror {
+	border: var(--mystnb-source-border-width) var(--mystnb-source-border-color) solid;
+	border-right-width: 0;
+	border-left-width: 0;
+}
+
+.thebe-button, .thebe-launch-button {
+    margin: 3px 3px 3px 3px;
+    border: var(--mystnb-source-border-width) var(--mystnb-source-border-color) solid;
+    border-radius: calc(var(--mystnb-source-border-radius) + 1px);
+    background-color: #fefefe
+}
+
+.thebe-controls { 
+    margin-left: 3px;
+}
+
+.thebe-button:active {
+    background-color: #f2f2f2
+}
+
+.thebelab-busy-spinner,
+.thebe-busy-spinner {
+  width: 20px;
+  height: 20px;
+}
diff --git a/book/thebe_lite/sphinx-thebe.js b/book/thebe_lite/sphinx-thebe.js
index e654d88f..1d175462 100644
--- a/book/thebe_lite/sphinx-thebe.js
+++ b/book/thebe_lite/sphinx-thebe.js
@@ -55,7 +55,7 @@ var configureThebe = () => {
     // Find any cells with an initialization tag and ask thebe to run them when ready
     if (data.status === "ready") {
       $(".thebe-launch-button").each((ii, button) => {
-        button.innerHTML = `Ready!`;
+        button.innerHTML = `Python interaction ready!`;
       });
 
       var thebeInitCells = document.querySelectorAll(
@@ -117,19 +117,34 @@ const loadScriptAsync = async (scriptSource) => {
   });
 };
 
+const loadStyleAsync = async (styleSource) => {
+  const css = document.createElement("link");
+  css.href = styleSource;
+  css.rel = "stylesheet";
+  document.head.appendChild(css);
+
+  return new Promise((resolve, reject) => {
+    css.addEventListener("load", () => {
+      resolve();
+    });
+  });
+};
+
+
 var initThebe = async () => {
   // Load thebe dynamically if it's not already loaded
   if (typeof thebelab === "undefined") {
     console.log("[sphinx-thebe]: Loading thebe...");
-    $(".thebe-launch-button ").text("Loading thebe...");
-
+    $(".thebe-launch-button ").css("display", "none");
+    
     // Provides nice things like a running animation and some padding
     {
-      const thebeCss = document.createElement("link");
-      thebeCss.href = "/thebe.css";
-      thebeCss.rel = "stylesheet";
-      document.head.appendChild(thebeCss);
+      await loadStyleAsync("/thebe.css");
+      await loadStyleAsync("/_static/code.css");
     }
+    
+    $(".thebe-launch-button ").css("display", "block");
+    $(".thebe-launch-button ").text("Loading thebe...");
 
     await loadScriptAsync("/thebe-lite.min.js");
     await loadScriptAsync("/index.js");
diff --git a/build-lite.sh b/build-lite.sh
new file mode 100755
index 00000000..9e81da21
--- /dev/null
+++ b/build-lite.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+jupyter-book build book
+cp book/thebe_lite/libs/* book/_build/html -r
+cp book/thebe_lite/* book/_build/html/_static
+
+if command -v python > /dev/null 2>&1
+then
+	python_command="python"
+else
+	if command -v python3 > /dev/null 2>&1
+	then
+		python_command="python3"
+	else
+		echo "Could not find python, cannot start webserver."
+		exit 1
+	fi
+fi
+
+$python_command -m http.server 8000 --directory book/_build/html
-- 
GitLab