Updates from pmp-p
This commit is contained in:
parent
571f60f4a0
commit
ead74c494f
2
.gitignore
vendored
2
.gitignore
vendored
@ -48,7 +48,9 @@ __pycache__/
|
|||||||
######################
|
######################
|
||||||
GNUmakefile
|
GNUmakefile
|
||||||
user.props
|
user.props
|
||||||
|
ports/javascript/node_modules
|
||||||
|
|
||||||
# Generated rst files
|
# Generated rst files
|
||||||
######################
|
######################
|
||||||
genrst/
|
genrst/
|
||||||
|
|
||||||
|
|||||||
@ -104,4 +104,5 @@ test: $(BUILD)/micropython.js $(TOP)/tests/run-tests
|
|||||||
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
|
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
|
||||||
cd $(TOP)/tests && MICROPY_MICROPYTHON=../ports/javascript/node_run.sh ./run-tests
|
cd $(TOP)/tests && MICROPY_MICROPYTHON=../ports/javascript/node_run.sh ./run-tests
|
||||||
|
|
||||||
|
|
||||||
include $(TOP)/py/mkrules.mk
|
include $(TOP)/py/mkrules.mk
|
||||||
|
|||||||
@ -75,7 +75,6 @@
|
|||||||
line-height: normal;
|
line-height: normal;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
|
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
|
||||||
<script src="https://littlevgl.com/bootstrap/js/bootstrap.min.js"></script>
|
<script src="https://littlevgl.com/bootstrap/js/bootstrap.min.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.4/ace.js" type="text/javascript" charset="utf-8"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.4/ace.js" type="text/javascript" charset="utf-8"></script>
|
||||||
@ -83,7 +82,7 @@
|
|||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/xterm/3.13.2/xterm.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/xterm/3.13.2/xterm.min.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/xterm/3.13.2/addons/fit/fit.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/xterm/3.13.2/addons/fit/fit.min.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/lz-string/1.4.4/lz-string.js" type="text/javascript" charset="utf-8"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/lz-string/1.4.4/lz-string.js" type="text/javascript" charset="utf-8"></script>
|
||||||
|
<script src="query.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="flex-container">
|
<div class="flex-container">
|
||||||
@ -99,8 +98,14 @@
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
<input type="button" disabled="disabled" id="run-button" value="Run the script" onclick="runScript();"/>
|
<input type="button" disabled="disabled" id="run-button" value="Run the script" onclick="runScript();"/>
|
||||||
|
|
||||||
|
<!-- HTML input control is disabled currently -->
|
||||||
|
<span style="display: none;">
|
||||||
Copy/paste script here:
|
Copy/paste script here:
|
||||||
<input onClick="this.setSelectionRange(0, this.value.length)" id="script-compressed" oninput="input_change();"/>
|
<input onClick="this.setSelectionRange(0, this.value.length)" id="script-compressed" oninput="input_change();"/>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div id="editor">print("Hello world")</div>
|
<div id="editor">print("Hello world")</div>
|
||||||
<div class="display-objects">
|
<div class="display-objects">
|
||||||
@ -120,12 +125,17 @@
|
|||||||
iframe.contentWindow.document.dispatchEvent(new MouseEvent('mouseup'));
|
iframe.contentWindow.document.dispatchEvent(new MouseEvent('mouseup'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.onmouseup = forward_event;
|
document.onmouseup = forward_event;
|
||||||
function input_change() {
|
function input_change() {
|
||||||
editor.session.setValue(LZString.decompressFromEncodedURIComponent($("#script-compressed").val()));
|
editor.session.setValue(LZString.decompressFromEncodedURIComponent($("#script-compressed").val()));
|
||||||
}
|
}
|
||||||
function editor_change() {
|
function editor_change() {
|
||||||
$("#script-compressed").val(LZString.compressToEncodedURIComponent(editor.getValue()));
|
var script_string = LZString.compressToEncodedURIComponent(editor.getValue());
|
||||||
|
$("#script-compressed").val(script_string);
|
||||||
|
var new_href = update_query_string(window.location.href, "script_direct", script_string);
|
||||||
|
// Create a dummy element to parse the URI with
|
||||||
|
window.history.replaceState({path:new_href}, document.title,new_href);
|
||||||
}
|
}
|
||||||
function runScript() {
|
function runScript() {
|
||||||
var $this = $("#run-button");
|
var $this = $("#run-button");
|
||||||
@ -143,39 +153,52 @@
|
|||||||
|
|
||||||
clear_iframe(iframe);
|
clear_iframe(iframe);
|
||||||
iframe.src = get_iframe_url() + "×tamp=" + new Date().getTime();
|
iframe.src = get_iframe_url() + "×tamp=" + new Date().getTime();
|
||||||
|
iframe.contentWindow.location.href = iframe.src;
|
||||||
|
console.log("Iframe src: " + iframe.src);
|
||||||
}
|
}
|
||||||
function reenableButton() {
|
function reenableButton() {
|
||||||
$("#run-button").removeProp('disabled');
|
$("#run-button").removeProp('disabled');
|
||||||
}
|
}
|
||||||
function get_iframe_url() {
|
function get_iframe_url() {
|
||||||
/* Assemble the URL */
|
/* Assemble the URL */
|
||||||
var newPathname = window.location.href.substr(0, window.location.href.lastIndexOf('/'));
|
var num_url_chars = (window.location.href.indexOf('?'));
|
||||||
newPathname += "/lvgl.html" + (window.location.href.indexOf('?') != -1 ? '&' : '?') + "env=dev";
|
var base_url = window.location.href.substr(0, (num_url_chars == -1) ? undefined : num_url_chars);
|
||||||
console.log(newPathname);
|
var newPathname = base_url.substr(0, base_url.lastIndexOf('/'));
|
||||||
|
newPathname += "/lvgl.html" + '?' + "env=dev";
|
||||||
return newPathname;
|
return newPathname;
|
||||||
}
|
}
|
||||||
function processScriptArg(url){
|
function processScriptArg(url, lzstring){
|
||||||
// read text from URL location
|
var script_passed_handler = function() {
|
||||||
var request = new XMLHttpRequest();
|
console.log("Script passed: " + script_passed);
|
||||||
console.log("GET " + url);
|
if(script_passed)
|
||||||
request.open('GET', url, true);
|
runScript();
|
||||||
request.send(null);
|
else
|
||||||
request.onreadystatechange = function () {
|
reenableButton();
|
||||||
if (request.readyState === 4 && request.status === 200) {
|
script_passed = false;
|
||||||
|
};
|
||||||
|
if(!lzstring) {
|
||||||
|
// read text from URL location
|
||||||
|
var request = new XMLHttpRequest();
|
||||||
|
console.log("GET " + url);
|
||||||
|
request.open('GET', url, true);
|
||||||
|
request.send(null);
|
||||||
|
request.onreadystatechange = function () {
|
||||||
|
if (request.readyState === 4 && request.status === 200) {
|
||||||
|
|
||||||
console.log(request.reponseText);
|
console.log(request.reponseText);
|
||||||
if(request.responseText === undefined)
|
if(request.responseText === undefined)
|
||||||
return;
|
return;
|
||||||
editor.session.getUndoManager().reset();
|
editor.session.getUndoManager().reset();
|
||||||
editor.session.setValue(request.responseText, -1);
|
editor.session.setValue(request.responseText, -1);
|
||||||
console.log("Script passed: " + script_passed);
|
script_passed_handler();
|
||||||
if(script_passed)
|
}
|
||||||
runScript();
|
|
||||||
else
|
|
||||||
reenableButton();
|
|
||||||
script_passed = false;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// decompress LZString
|
||||||
|
editor.session.setValue(LZString.decompressFromEncodedURIComponent(url));
|
||||||
|
script_passed_handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
function getSearchArg(argname) {
|
function getSearchArg(argname) {
|
||||||
/* Run custom script if passed */
|
/* Run custom script if passed */
|
||||||
@ -199,13 +222,11 @@
|
|||||||
editor.session.setMode(new PythonMode());
|
editor.session.setMode(new PythonMode());
|
||||||
iframe = document.getElementById("emscripten-iframe");
|
iframe = document.getElementById("emscripten-iframe");
|
||||||
iframe.src = "about:blank";
|
iframe.src = "about:blank";
|
||||||
|
iframe.contentWindow.location.href = iframe.src;
|
||||||
clear_iframe(iframe);
|
clear_iframe(iframe);
|
||||||
var script = getSearchArg("script");
|
|
||||||
if(script !== undefined && script !== null) {
|
|
||||||
script_passed = true;
|
|
||||||
processScriptArg(script);
|
|
||||||
} else
|
|
||||||
processScriptArg("https://raw.githubusercontent.com/littlevgl/lv_binding_micropython/dev-6.0/examples/advanced_demo.py");
|
|
||||||
Terminal.applyAddon(fit);
|
Terminal.applyAddon(fit);
|
||||||
term = new Terminal();
|
term = new Terminal();
|
||||||
mp_js_stdout = document.getElementById('mp_js_stdout');
|
mp_js_stdout = document.getElementById('mp_js_stdout');
|
||||||
@ -225,6 +246,17 @@
|
|||||||
}, false);
|
}, false);
|
||||||
editor.getSession().on('change', editor_change);
|
editor.getSession().on('change', editor_change);
|
||||||
editor.resize();
|
editor.resize();
|
||||||
|
|
||||||
|
var script = getSearchArg("script");
|
||||||
|
var script_direct = getSearchArg("script_direct");
|
||||||
|
if(script_direct !== undefined && script_direct !== null) {
|
||||||
|
script_passed = true;
|
||||||
|
processScriptArg(script_direct, true);
|
||||||
|
} else if(script !== undefined && script !== null) {
|
||||||
|
script_passed = true;
|
||||||
|
processScriptArg(script);
|
||||||
|
} else
|
||||||
|
processScriptArg("https://raw.githubusercontent.com/littlevgl/lv_binding_micropython/dev-6.0/examples/advanced_demo.py");
|
||||||
});
|
});
|
||||||
$(window).resize(function() {
|
$(window).resize(function() {
|
||||||
editor.resize();
|
editor.resize();
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -76,10 +76,10 @@
|
|||||||
#define MICROPY_EMIT_X64 (0) //BROKEN
|
#define MICROPY_EMIT_X64 (0) //BROKEN
|
||||||
#define MICROPY_EMIT_THUMB (0) //BROKEN
|
#define MICROPY_EMIT_THUMB (0) //BROKEN
|
||||||
#define MICROPY_EMIT_INLINE_THUMB (0)
|
#define MICROPY_EMIT_INLINE_THUMB (0)
|
||||||
#define MICROPY_COMP_MODULE_CONST (0)
|
#define MICROPY_COMP_MODULE_CONST (1)
|
||||||
#define MICROPY_COMP_CONST (1)
|
#define MICROPY_COMP_CONST (1)
|
||||||
#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (1)
|
#define MICROPY_COMP_DOUBLE_TUPLE_ASSIGN (1)
|
||||||
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
|
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (1)
|
||||||
#define MICROPY_MEM_STATS (0) //BROKEN
|
#define MICROPY_MEM_STATS (0) //BROKEN
|
||||||
#define MICROPY_DEBUG_PRINTERS (0)
|
#define MICROPY_DEBUG_PRINTERS (0)
|
||||||
#define MICROPY_ENABLE_GC (1)
|
#define MICROPY_ENABLE_GC (1)
|
||||||
|
|||||||
70
ports/javascript/query.js
Normal file
70
ports/javascript/query.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/**
|
||||||
|
* Add or update a query string parameter. If no URI is given, we use the current
|
||||||
|
* window.location.href value for the URI.
|
||||||
|
*
|
||||||
|
* Based on the DOM URL parser described here:
|
||||||
|
* http://james.padolsey.com/javascript/parsing-urls-with-the-dom/
|
||||||
|
*
|
||||||
|
* @param (string) uri Optional: The URI to add or update a parameter in
|
||||||
|
* @param (string) key The key to add or update
|
||||||
|
* @param (string) value The new value to set for key
|
||||||
|
*
|
||||||
|
* Tested on Chrome 34, Firefox 29, IE 7 and 11
|
||||||
|
*/
|
||||||
|
function update_query_string( uri, key, value ) {
|
||||||
|
|
||||||
|
// Use window URL if no query string is provided
|
||||||
|
if ( ! uri ) { uri = window.location.href; }
|
||||||
|
|
||||||
|
// Create a dummy element to parse the URI with
|
||||||
|
var a = document.createElement( 'a' ),
|
||||||
|
|
||||||
|
// match the key, optional square brackets, an equals sign or end of string, the optional value
|
||||||
|
reg_ex = new RegExp( key + '((?:\\[[^\\]]*\\])?)(=|$)(.*)' ),
|
||||||
|
|
||||||
|
// Setup some additional variables
|
||||||
|
qs,
|
||||||
|
qs_len,
|
||||||
|
key_found = false;
|
||||||
|
|
||||||
|
// Use the JS API to parse the URI
|
||||||
|
a.href = uri;
|
||||||
|
|
||||||
|
// If the URI doesn't have a query string, add it and return
|
||||||
|
if ( ! a.search ) {
|
||||||
|
|
||||||
|
a.search = '?' + key + '=' + value;
|
||||||
|
|
||||||
|
return a.href;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split the query string by ampersands
|
||||||
|
qs = a.search.replace( /^\?/, '' ).split( /&(?:amp;)?/ );
|
||||||
|
qs_len = qs.length;
|
||||||
|
|
||||||
|
// Loop through each query string part
|
||||||
|
while ( qs_len > 0 ) {
|
||||||
|
|
||||||
|
qs_len--;
|
||||||
|
|
||||||
|
// Remove empty elements to prevent double ampersands
|
||||||
|
if ( ! qs[qs_len] ) { qs.splice(qs_len, 1); continue; }
|
||||||
|
|
||||||
|
// Check if the current part matches our key
|
||||||
|
if ( reg_ex.test( qs[qs_len] ) ) {
|
||||||
|
|
||||||
|
// Replace the current value
|
||||||
|
qs[qs_len] = qs[qs_len].replace( reg_ex, key + '$1' ) + '=' + value;
|
||||||
|
|
||||||
|
key_found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we haven't replaced any occurrences above, add the new parameter and value
|
||||||
|
if ( ! key_found ) { qs.push( key + '=' + value ); }
|
||||||
|
|
||||||
|
// Set the new query string
|
||||||
|
a.search = '?' + qs.join( '&' );
|
||||||
|
|
||||||
|
return a.href;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user