| 1 |
|
| 2 |
<!DOCTYPE html> |
| 3 |
<html lang="en"> |
| 4 |
<head> |
| 5 |
<meta charset="utf-8"> |
| 6 |
<title>Android test suite</title> |
| 7 |
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css"> |
| 8 |
<script> |
| 9 |
document.cookie = 'testCookie1=value1; expires=Thu, 18 Dec 2133 12:00:00 UTC;'; |
| 10 |
document.cookie = 'testCookie2=value2; expires=Thu, 18 Dec 2133 12:00:00 UTC;'; |
| 11 |
document.cookie = 'testJson=' + JSON.stringify({key: 'value', number: 42}) + '; expires=Thu, 18 Dec 2133 12:00:00 UTC;'; </script> |
| 12 |
</script> |
| 13 |
|
| 14 |
<body> |
| 15 |
<div id="mocha"></div> |
| 16 |
<script src="https://unpkg.com/mocha/mocha.js"></script> |
| 17 |
<script src="https://unpkg.com/[email protected]/chai.js"></script> |
| 18 |
<script>mocha.setup('bdd')</script> |
| 19 |
<script>mocha.timeout(10000)</script> |
| 20 |
<script>expect = chai.expect</script> |
| 21 |
<script src="index.js"></script> |
| 22 |
|
| 23 |
<script src="tests/test-events.js"></script> |
| 24 |
<script src="tests/test-js-api.js"></script> |
| 25 |
<script src="tests/test-state.js"></script> |
| 26 |
<script src="tests/test-window.js"></script> |
| 27 |
|
| 28 |
<script> |
| 29 |
if (window.pywebview && Object.keys(window.pywebview.api).length > 0) { |
| 30 |
mocha.run(); |
| 31 |
} else { |
| 32 |
window.addEventListener('pywebviewready', mocha.run); |
| 33 |
} |
| 34 |
</script> |
| 35 |
|
| 36 |
<div id="test-area" style="visibility: hidden;"></div> |
| 37 |
|
| 38 |
<div style="margin: 20px;"> |
| 39 |
<button id="toggle-eval-button" onclick="togglePythonEvaluator()" style="padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 5px; cursor: pointer; font-size: 14px;">Show Python Code Evaluator</button> |
| 40 |
</div> |
| 41 |
|
| 42 |
<div id="python-eval-section" style="margin: 20px; padding: 20px; border: 1px solid #ccc; border-radius: 5px; display: none;"> |
| 43 |
<h3>Python Code Evaluator</h3> |
| 44 |
<div style="margin-bottom: 10px;"> |
| 45 |
<label for="python-code">Enter Python code:</label> |
| 46 |
<br> |
| 47 |
<textarea id="python-code" rows="6" cols="80" style="width: 100%; font-family: monospace; margin-top: 5px;" placeholder="Enter your Python code here..."></textarea> |
| 48 |
</div> |
| 49 |
<div style="margin-bottom: 10px;"> |
| 50 |
<button id="eval-button" onclick="evaluatePythonCode()" style="padding: 8px 16px; background-color: #007acc; color: white; border: none; border-radius: 3px; cursor: pointer;">Execute Code</button> |
| 51 |
<button onclick="clearResult()" style="padding: 8px 16px; background-color: #666; color: white; border: none; border-radius: 3px; cursor: pointer; margin-left: 10px;">Clear Result</button> |
| 52 |
</div> |
| 53 |
<div> |
| 54 |
<label for="result-area">Result:</label> |
| 55 |
<br> |
| 56 |
<div id="result-area" style="width: 100%; min-height: 100px; padding: 10px; border: 1px solid #ddd; background-color: #f9f9f9; font-family: monospace; white-space: pre-wrap; margin-top: 5px;"></div> |
| 57 |
</div> |
| 58 |
</div> |
| 59 |
|
| 60 |
<script> |
| 61 |
document.cookie = 'testCookie1=value1; expires=Thu, 18 Dec 2133 12:00:00 UTC;'; |
| 62 |
async function evaluatePythonCode() { |
| 63 |
const codeTextArea = document.getElementById('python-code'); |
| 64 |
const resultArea = document.getElementById('result-area'); |
| 65 |
const evalButton = document.getElementById('eval-button'); |
| 66 |
|
| 67 |
const code = codeTextArea.value.trim(); |
| 68 |
|
| 69 |
if (!code) { |
| 70 |
resultArea.textContent = 'Please enter some Python code to execute.'; |
| 71 |
resultArea.style.color = '#999'; |
| 72 |
return; |
| 73 |
} |
| 74 |
|
| 75 |
// Check if pywebview API is available |
| 76 |
if (!window.pywebview || !window.pywebview.api || !window.pywebview.api.eval) { |
| 77 |
resultArea.textContent = 'Error: pywebview.api.eval is not available. Make sure you are running this in a pywebview environment.'; |
| 78 |
resultArea.style.color = 'red'; |
| 79 |
return; |
| 80 |
} |
| 81 |
|
| 82 |
try { |
| 83 |
// Disable button during execution |
| 84 |
evalButton.disabled = true; |
| 85 |
evalButton.textContent = 'Executing...'; |
| 86 |
|
| 87 |
// Clear previous result |
| 88 |
resultArea.textContent = 'Executing...'; |
| 89 |
resultArea.style.color = '#666'; |
| 90 |
|
| 91 |
// Execute the Python code |
| 92 |
const result = await window.pywebview.api.eval(code); |
| 93 |
|
| 94 |
// Display the result |
| 95 |
resultArea.textContent = `Result: ${JSON.stringify(result, null, 2)}`; |
| 96 |
resultArea.style.color = 'green'; |
| 97 |
|
| 98 |
} catch (error) { |
| 99 |
// Display error |
| 100 |
resultArea.textContent = `Error: ${error.message || error}`; |
| 101 |
resultArea.style.color = 'red'; |
| 102 |
} finally { |
| 103 |
// Re-enable button |
| 104 |
evalButton.disabled = false; |
| 105 |
evalButton.textContent = 'Execute Code'; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
function clearResult() { |
| 110 |
document.getElementById('result-area').textContent = ''; |
| 111 |
document.getElementById('result-area').style.color = '#000'; |
| 112 |
} |
| 113 |
|
| 114 |
function togglePythonEvaluator() { |
| 115 |
const evalSection = document.getElementById('python-eval-section'); |
| 116 |
const toggleButton = document.getElementById('toggle-eval-button'); |
| 117 |
|
| 118 |
if (evalSection.style.display === 'none') { |
| 119 |
evalSection.style.display = 'block'; |
| 120 |
toggleButton.textContent = 'Hide Python Code Evaluator'; |
| 121 |
toggleButton.style.backgroundColor = '#dc3545'; |
| 122 |
} else { |
| 123 |
evalSection.style.display = 'none'; |
| 124 |
toggleButton.textContent = 'Show Python Code Evaluator'; |
| 125 |
toggleButton.style.backgroundColor = '#28a745'; |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
// Allow Ctrl+Enter to execute code |
| 130 |
document.getElementById('python-code').addEventListener('keydown', function(event) { |
| 131 |
if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') { |
| 132 |
event.preventDefault(); |
| 133 |
evaluatePythonCode(); |
| 134 |
} |
| 135 |
}); |
| 136 |
</script> |
| 137 |
|
| 138 |
<div> |
| 139 |
|
| 140 |
</div> |
| 141 |
</html> |