Skip to content

Commit 3fdf6e5

Browse files
committed
more tweaks -- display langDisplayDiv and fix originFrontendJsFile for
iframe-embed.html
1 parent 98869e0 commit 3fdf6e5

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎v3/css/pytutor.css‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,13 @@ div.ExecutionVisualizer div#heapHeader {
529529
margin-bottom: 15px;
530530
}
531531

532+
div.ExecutionVisualizer div#langDisplayDiv {
533+
text-align: center;
534+
margin-top: 2pt;
535+
margin-bottom: 5pt;
536+
}
537+
538+
div.ExecutionVisualizer div#langDisplayDiv,
532539
div.ExecutionVisualizer div#stackHeader,
533540
div.ExecutionVisualizer div#heapHeader {
534541
color: #333333;

‎v3/js/iframe-embed.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3333
// - opt-frontend-common.js
3434
// should all be imported BEFORE this file
3535

36+
var originFrontendJsFile = 'iframe-embed.js';
3637

3738
function NOP() {};
3839

@@ -112,7 +113,7 @@ $(document).ready(function() {
112113
heap_primitives: heapPrimitivesBool,
113114
show_only_outputs: showOnlyOutputsBool,
114115
py_crazy_mode: (pyState == '2crazy'),
115-
origin: 'iframe-embed.js'};
116+
origin: originFrontendJsFile};
116117

117118
var frontendOptionsObj = {startingInstruction: startingInstruction,
118119
embeddedMode: true,

‎v3/js/opt-frontend-common.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,15 @@ function executePythonCode(pythonSourceCode,
12831283
clearFrontendError();
12841284
startExecutingCode();
12851285

1286+
// hacky!
1287+
if (backendScript === python2_backend_script) {
1288+
frontendOptionsObj.lang = 'py2';
1289+
} else if (backendScript === python3_backend_script) {
1290+
frontendOptionsObj.lang = 'py3';
1291+
} else if (backendScript === js_backend_script) {
1292+
frontendOptionsObj.lang = 'js';
1293+
}
1294+
12861295
if (backendScript === js_backend_script) {
12871296
// hack for JS execution! should just be a dummy script for logging only
12881297
$.get(backendScript,

‎v3/js/pytutor.js‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ var curVisualizerID = 1; // global to uniquely identify each ExecutionVisualizer
117117
// granularity instead of line-level granularity (HIGHLY EXPERIMENTAL!)
118118
// hideCode - hide the code display and show only the data structure viz
119119
// tabularView - render a tabular view of ALL steps at once (EXPERIMENTAL)
120-
// lang - to render labels in a style appropriate for other languages.
121-
// e.g., 'js' for JavaScript, 'java' for Java [default is Python]
120+
// lang - to render labels in a style appropriate for other languages,
121+
// and to display the proper language in langDisplayDiv
122+
// e.g., 'py2' for Python 2, 'py3' for Python 3, 'js' for JavaScript
123+
// [default is Python-style labels]
122124
// debugMode - some extra debugging printouts
123125
function ExecutionVisualizer(domRootID, dat, params) {
124126
this.curInputCode = dat.code.rtrim(); // kill trailing spaces
@@ -314,6 +316,7 @@ ExecutionVisualizer.prototype.render = function() {
314316

315317
var codeDisplayHTML =
316318
'<div id="codeDisplayDiv">\
319+
<div id="langDisplayDiv"></div>\
317320
<div id="pyCodeOutputDiv"/>\
318321
<div id="editCodeLinkDiv"><a id="editBtn">Edit code</a></div>\
319322
<div id="executionSlider"/>\
@@ -444,6 +447,18 @@ ExecutionVisualizer.prototype.render = function() {
444447
this.domRoot.find('#editBtn').click(function(){return false;}); // DISABLE the link!
445448
}
446449

450+
if (this.params.lang !== undefined) {
451+
if (this.params.lang === 'js') {
452+
this.domRoot.find('#langDisplayDiv').html('JavaScript (experimental)');
453+
} else if (this.params.lang === 'py2') {
454+
this.domRoot.find('#langDisplayDiv').html('Python 2.7');
455+
} else if (this.params.lang === 'py3') {
456+
this.domRoot.find('#langDisplayDiv').html('Python 3.3');
457+
} else {
458+
this.domRoot.find('#langDisplayDiv').hide();
459+
}
460+
}
461+
447462
if (this.params.allowEditAnnotations !== undefined) {
448463
this.allowEditAnnotations = this.params.allowEditAnnotations;
449464
}

0 commit comments

Comments
 (0)