Skip to content

Commit d403073

Browse files
Working simulator
1 parent c553710 commit d403073

File tree

6 files changed

+65
-100
lines changed

6 files changed

+65
-100
lines changed

editor.html

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,9 @@
6666
<link rel="stylesheet" type="text/css" href="static/css/vex-theme-wireframe.css" />
6767
<link rel="stylesheet" type="text/css" href="static/css/font-awesome.min.css">
6868
<link rel="icon" href="static/img/favicon.ico">
69-
<script src="lib/cm/codemirror.js"></script>
70-
<script src="lib/cm/active-line.js"></script>
71-
<script src="lib/cm/python.js"></script>
72-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
73-
<script src="lib/lib.js"></script>
74-
<script src="lib/skulpt/skulpt.min.js"></script>
75-
<script src="lib/skulpt/skulpt-stdlib.js"></script>
76-
<script src="lib/jq/jquery.ui.touch-punch.min.js"></script>
77-
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
78-
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
7969
</head>
8070
<body>
81-
<script type="text/javascript" src="microbit-sim.js"></script>
71+
<iframe id="sim-iframe" src="about:blank" width="320px" height="257px" frameborder="0" style="position: absolute; bottom: 20px; right: 20px; z-index: 10;"></iframe>
8272
<script type="application/javascript">
8373
<!-- VERSION INFORMATION -->
8474
VERSION = "0.1.0";
@@ -172,7 +162,7 @@ <h2><i class="fa fa-unlock-alt"></i> <strong>{{ title }}</strong></h2>
172162
<path d="m 185.96612,110.36806 41.029,41.029 0,-72.834699 27.352,0 0.001,72.834699 41.029,-41.029 0,31.911 -54.706,54.706 -54.705,-54.706 0,-31.911 z m 98.203,181.9 c 0,-9.128 7.406,-16.539 16.541,-16.539 9.146,0 16.535,7.411 16.535,16.539 0,9.131 -7.389,16.548 -16.535,16.548 -9.135,0 -16.541,-7.417 -16.541,-16.548 z m -121.494,0.003 c 0,-9.129 7.413,-16.542 16.548,-16.542 9.129,0 16.537,7.413 16.537,16.542 0,9.131 -7.408,16.547 -16.537,16.547 -9.135,0 -16.548,-7.416 -16.548,-16.547 z m 16.544,-81.93 122.554,0.202 c 45.667,0 82.285,36.553 82.285,81.732 0,45.179 -36.757,81.934 -81.937,81.934 l -122.902,0 c -45.177,0 -81.934395,-36.755 -81.934395,-81.934 0,-45.179 36.757395,-81.934 81.934395,-81.934 z m -49.164,81.934 c 0,27.105 22.059,49.164 49.164,49.164 l 122.902,0 c 27.107,0 49.159,-22.059 49.159,-49.164 0,-27.112 -22.052,-49.164 -49.159,-49.164 l -122.902,0 c -27.105,0 -49.164,22.052 -49.164,49.164 z" id="path3341" inkscape:connector-curvature="0" style="fill:currentColor"></path>
173163
</svg>
174164
</div>
175-
<div class="roundlabel">Download<a href="test.html">Run me!!!!!!!!</a></div>
165+
<div class="roundlabel">Download</div>
176166
</a>
177167
<a href="#" class="roundbutton" id="command-save"
178168
tabindex="2"
@@ -200,6 +190,13 @@ <h2><i class="fa fa-unlock-alt"></i> <strong>{{ title }}</strong></h2>
200190
</div>
201191
<div class="roundlabel">Blockly</div>
202192
</a>
193+
<a href="#" class="roundbutton" id="command-sim"
194+
tabindex="12">
195+
<div class="roundsymbol">
196+
<i class="fa fa-arrow-circle-right"></i>
197+
</div>
198+
<div class="roundlabel">Sim</div>
199+
</a>
203200
<a href="#" class="roundbutton hidden" id="command-snippet"
204201
tabindex="5"
205202
title="Click to select a snippet (code shortcut)">
@@ -700,6 +697,7 @@ <h2><i class="fa fa-unlock-alt"></i> <strong>{{ title }}</strong></h2>
700697
<sep></sep>
701698
<category name="Variables" colour="330" custom="VARIABLE"></category>
702699
</xml>
700+
:1040A0000123037210BDC046ACCF020008B5043036
703701
<div id="firmware" style="display: none;">:020000040000FA
704702
:1000000000400020ED530100295401002B54010051
705703
:1000100000000000000000000000000000000000E0
@@ -1735,7 +1733,6 @@ <h2><i class="fa fa-unlock-alt"></i> <strong>{{ title }}</strong></h2>
17351733
:1040700074E0020010B5041C0C201FF0E9FA034B99
17361734
:10408000446003600023037210BDC046ACCF020041
17371735
:1040900010B5041C0C201FF0DBFA034B44600360D6
1738-
:1040A0000123037210BDC046ACCF020008B5043036
17391736
:1040B000002200F0F5FC002805D10449044823F053
17401737
:1040C0001EFFFCF7A8F8406808BDC046A2490300DF
17411738
:1040D000F0FD020008B5024B08C01FF0E9FC08BD66

index simulator.html

Lines changed: 0 additions & 47 deletions
This file was deleted.

lib/lib.js

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ function animateTitle(txt, id) {
3232
t = setTimeout(onAnimTimeout, 50);
3333

3434
}
35-
3635
// Main PythonIDE object
3736
var PythonIDE = {
3837

3938
// file currently being edited
4039
currentFile: 'mycode.py',
4140

4241
// stores each of the files in the project
43-
files: {'mycode.py':'from microbit import *\ndisplay.scroll("Yo famalam")'},
42+
43+
files: {'mycode.py': decodeURIComponent(window.location.search.substring(6))},
4444

4545
// functions and data needed for running theh python code
4646
python: {
@@ -107,6 +107,7 @@ var PythonIDE = {
107107
// run the code in the editor
108108
// runMode can be "anim" to step through each line of python code or "normal" to run the whole code as fast as possible
109109
runCode: function(runMode) {
110+
console.log(window);
110111
if(PythonIDE.unhandledError)
111112
delete PythonIDE.unhandledError;
112113

@@ -129,9 +130,8 @@ var PythonIDE = {
129130
PythonIDE.runMode = runMode;
130131
PythonIDE.python.outputListeners = [];
131132

132-
var code = PythonIDE.files['mycode.py'];
133-
localStorage.lastRunCode = code;
134-
133+
var code = decodeURIComponent(window.location.search.substring(6));
134+
135135
var html = '';
136136
html += '<div id="headerOut"></div>';
137137
html += '<pre id="consoleOut"><div id="watch"><h2>Variables:</h2></div></pre>';
@@ -231,7 +231,6 @@ var PythonIDE = {
231231
startTime = new Date().getTime();
232232
var p = new Promise(function(resolve, reject) {
233233
setTimeout(function() {
234-
PythonIDE.showHint("Limiting speed to avoid crashing the browser: " + (lineCount * 10) + " lines per second");
235234
lineCount = 0;
236235
return resolve(susp.resume());
237236
}, 50);
@@ -245,22 +244,20 @@ var PythonIDE = {
245244
}
246245
}
247246

248-
249-
250-
Sk.misceval.callsimAsync(handlers, function() {
251-
return Sk.importMainWithBody("mycode",false,code,true);
252-
}).then(function(module){
253-
PythonIDE.showHint('Program finished running');
254-
if(PythonIDE.continueDebug)
255-
delete PythonIDE.continueDebug;
256-
if(PythonIDE.abortDebug)
257-
delete PythonIDE.abortDebug;
258-
$('#btn_stopRunning').removeClass('visibleButton').addClass('hiddenButton');
259-
if(PythonIDE.whenFinished) {
260-
PythonIDE.whenFinished();
261-
}
262-
}, PythonIDE.handleError);
263-
247+
if (code) {
248+
Sk.misceval.callsimAsync(handlers, function() {
249+
return Sk.importMainWithBody("mycode",false,code,true);
250+
}).then(function(module){
251+
if(PythonIDE.continueDebug)
252+
delete PythonIDE.continueDebug;
253+
if(PythonIDE.abortDebug)
254+
delete PythonIDE.abortDebug;
255+
$('#btn_stopRunning').removeClass('visibleButton').addClass('hiddenButton');
256+
if(PythonIDE.whenFinished) {
257+
PythonIDE.whenFinished();
258+
}
259+
}, PythonIDE.handleError);
260+
}
264261
},
265262

266263
// display errors caught when the python code runs
@@ -274,7 +271,6 @@ var PythonIDE = {
274271
}
275272

276273
var html = '<span class="error">' + err.toString() + '</span>';
277-
PythonIDE.showHint(html);
278274
PythonIDE.python.output(html);
279275
},
280276

python-main.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,6 @@ function web_editor(config) {
352352
dirty = true;
353353
});
354354
}, 1);
355-
// Handles what to do if the name is changed.
356-
$("#script-name").on("input keyup blur", function () {
357-
dirty = true;
358-
});
359-
// Handles what to do if the description is changed.
360-
$("#script-description").on("input keyup blur", function () {
361-
dirty = true;
362-
});
363355
// Describes what to do if the user attempts to close the editor without first saving their work.
364356
window.addEventListener("beforeunload", function (e) {
365357
if (dirty) {
@@ -564,6 +556,19 @@ function web_editor(config) {
564556
};
565557
}
566558

559+
function stripComments(s) {
560+
var re1 = /^\s+|\s+$/g; // Strip leading and trailing spaces
561+
var re2 = /\s*[#;].+$/g; // Strip everything after # or ; to the end of the line, including preceding spaces
562+
return s.replace(re1,'').replace(re2,'');
563+
}
564+
565+
function doSim() {
566+
var sim = $("#sim-iframe");
567+
//sim.src = "simulator.html?code=" + stripComments(encodeURIComponent(EDITOR.getCode()));
568+
sim.attr("src", "simulator.html?code=" + encodeURIComponent(EDITOR.getCode()));
569+
console.log(sim.attr("src") + "kfdslkjfsakj");
570+
}
571+
567572
// This function describes what to do when the snippets button is clicked.
568573
function doSnippets() {
569574
// Snippets are triggered by typing a keyword followed by pressing TAB.
@@ -692,6 +697,9 @@ function web_editor(config) {
692697
$("#command-share").click(function () {
693698
doShare();
694699
});
700+
$("#command-sim").click(function () {
701+
doSim();
702+
});
695703
}
696704

697705
// Extracts the query string and turns it into an object of key/value

static/css/style.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@
2828
cursor: ew-resize;
2929
}
3030

31+
#sim {
32+
display: none;
33+
min-width: 570px;
34+
overflow: auto;
35+
resize: horizontal;
36+
padding-right: 10px;
37+
}
38+
39+
#sim:after {
40+
border-top: 0.5em solid transparent;
41+
border-left: 0.5em solid transparent;
42+
border-right: 0.5em solid #888;
43+
border-bottom: 0.5em solid #888;
44+
position: absolute;
45+
right: 0;
46+
bottom: 0;
47+
content: '';
48+
cursor: ew-resize;
49+
}
50+
3151
/* Re-usable, generic rules */
3252
.hidden {
3353
display: none !important;

test.html

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)