Skip to content

Commit c1d5dce

Browse files
author
Philip Guo
committed
launch of 2.0!
1 parent 6336df2 commit c1d5dce

File tree

5 files changed

+85
-19
lines changed

5 files changed

+85
-19
lines changed

TODO

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,9 @@ line of code immediately below each annotation.
141141
perhaps deploy online on WebFaction, since they offer both Python 2.X
142142
and Python 3.X on their servers.
143143

144+
---
145+
2011-09-22
146+
147+
- Make the 'Edit code' window display in the same place as the read-only
148+
code display column, in order to prevent abrupt jumping.
149+

edu-python.css

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ span {
9191

9292
#pyInputPane {
9393
text-align: center;
94-
margin-bottom: 40px;
94+
margin-bottom: 35px;
9595
}
9696

9797
table#stackHeapTable td {
@@ -440,7 +440,9 @@ div.globalFrame {
440440
background-color: #ffffff;
441441
margin-bottom: 15px;
442442
padding: 2px;
443-
padding-left: 8px;
443+
padding-left: 6px;
444+
padding-right: 6px;
445+
padding-bottom: 4px;
444446
font-size: 11pt;
445447
}
446448

@@ -470,11 +472,23 @@ div.inactiveStackFrameHeader {
470472
td.stackFrameVar {
471473
text-align: right;
472474
padding-right: 8px;
473-
min-width: 120px; /* to prevent excess jittering as new variables are added*/
475+
padding-top: 3px;
476+
padding-bottom: 3px;
477+
min-width: 130px; /* to prevent excess jittering as new variables are added*/
474478
}
475479

476480
td.stackFrameValue {
477481
text-align: left;
482+
border-bottom: 1px solid #aaaaaa;
483+
border-left: 1px solid #aaaaaa;
484+
485+
padding-top: 3px;
486+
padding-left: 3px;
487+
padding-bottom: 3px;
488+
}
489+
490+
.stackFrameVarTable tr {
491+
478492
}
479493

480494
div.stackFrame .stackFrameVarTable {

edu-python.js

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ function highlightCodeLine(curLine, visitedLinesSet, hasError, isTerminated) {
153153

154154
// relies on curTrace and curInstr globals
155155
function updateOutput() {
156+
// update based on experimental checkbox ...
157+
useJsPlumbRendering = $("#useJsPlumbCheckbox").prop("checked");
158+
156159
var curEntry = curTrace[curInstr];
157160
var hasError = false;
158161

@@ -388,10 +391,20 @@ function renderDataStructuresVersion1(curEntry, vizDiv) {
388391

389392
// The "2.0" version of renderDataStructures, which renders variables in
390393
// a stack and values in a separate heap, with data structure aliasing
391-
// explicitly represented via line connectors.
394+
// explicitly represented via line connectors (thanks to jsPlumb lib).
392395
//
393396
// This version was originally created in September 2011
394397
function renderDataStructuresVersion2(curEntry, vizDiv) {
398+
399+
// before we wipe out the old state of the visualization, CLEAR all
400+
// the click listeners first
401+
$(".stackFrameHeader").unbind();
402+
403+
// VERY VERY IMPORTANT --- and reset ALL jsPlumb state to prevent
404+
// weird mis-behavior!!!
405+
jsPlumb.reset();
406+
407+
395408
$(vizDiv).html(''); // CLEAR IT!
396409

397410
// create a tabular layout for stack and heap side-by-side
@@ -567,6 +580,7 @@ function renderDataStructuresVersion2(curEntry, vizDiv) {
567580
// from bottom to top, so that we can hopefully prevent objects from
568581
// jumping around
569582

583+
570584
orderedGlobals.reverse(); // so that we can iterate backwards
571585

572586
$.each(orderedGlobals, function(i, varname) {
@@ -648,6 +662,7 @@ function renderDataStructuresVersion2(curEntry, vizDiv) {
648662
var enclosingStackFrameID = enclosingStackFrame.attr('id');
649663

650664
var allConnections = jsPlumb.getConnections();
665+
//console.log('allConnections: ' + allConnections);
651666
for (var i = 0; i < allConnections.length; i++) {
652667
var c = allConnections[i];
653668

@@ -686,7 +701,7 @@ function renderDataStructuresVersion2(curEntry, vizDiv) {
686701

687702
// 'click' on the top-most stack frame if available,
688703
// or on "Global variables" otherwise
689-
if (curEntry.stack_locals != undefined && curEntry.stack_locals.length) {
704+
if (curEntry.stack_locals != undefined && curEntry.stack_locals.length > 0) {
690705
$('#stack_header0').trigger('click');
691706
}
692707
else {
@@ -1008,6 +1023,7 @@ $(document).ready(function() {
10081023
$("#editCodeLink").click(function() {
10091024
$("#pyInputPane").show();
10101025
$("#pyInputPane").css('border-bottom', '2px dashed #bbbbbb');
1026+
updateOutput();
10111027
return false; // to prevent page reload
10121028
});
10131029

@@ -1134,20 +1150,44 @@ $(document).ready(function() {
11341150
return false;
11351151
});
11361152

1137-
if (useJsPlumbRendering) {
1138-
// set some sensible defaults
1139-
jsPlumb.Defaults.Endpoint = ["Dot", {radius:3}];
1140-
//jsPlumb.Defaults.Endpoint = ["Rectangle", {width:3, height:3}];
1141-
jsPlumb.Defaults.EndpointStyle = {fillStyle: lightGray};
1142-
jsPlumb.Defaults.Anchors = ["RightMiddle", "LeftMiddle"];
1143-
jsPlumb.Defaults.Connector = [ "Bezier", { curviness:15 }]; /* too much 'curviness' causes lines to run together */
1144-
jsPlumb.Defaults.PaintStyle = {lineWidth:1, strokeStyle: lightGray};
1145-
1146-
jsPlumb.Defaults.EndpointHoverStyle = {fillStyle: pinkish};
1147-
jsPlumb.Defaults.HoverPaintStyle = {lineWidth:2, strokeStyle: pinkish};
1148-
}
1153+
1154+
// set some sensible jsPlumb defaults
1155+
jsPlumb.Defaults.Endpoint = ["Dot", {radius:3}];
1156+
//jsPlumb.Defaults.Endpoint = ["Rectangle", {width:3, height:3}];
1157+
jsPlumb.Defaults.EndpointStyle = {fillStyle: lightGray};
1158+
jsPlumb.Defaults.Anchors = ["RightMiddle", "LeftMiddle"];
1159+
jsPlumb.Defaults.Connector = [ "Bezier", { curviness:15 }]; /* too much 'curviness' causes lines to run together */
1160+
jsPlumb.Defaults.PaintStyle = {lineWidth:1, strokeStyle: lightGray};
1161+
1162+
jsPlumb.Defaults.EndpointHoverStyle = {fillStyle: pinkish};
1163+
jsPlumb.Defaults.HoverPaintStyle = {lineWidth:2, strokeStyle: pinkish};
1164+
11491165

11501166
// select an example on start-up:
11511167
$("#tutorialExampleLink").trigger('click');
1168+
1169+
1170+
// disable controls initially ...
1171+
$("#vcrControls #jmpFirstInstr").attr("disabled", true);
1172+
$("#vcrControls #jmpStepBack").attr("disabled", true);
1173+
$("#vcrControls #jmpStepFwd").attr("disabled", true);
1174+
$("#vcrControls #jmpLastInstr").attr("disabled", true);
1175+
1176+
1177+
// set keyboard event listeners ...
1178+
$(document).keydown(function(k) {
1179+
if (k.keyCode == 37) { // left arrow
1180+
if (!$("#vcrControls #jmpStepBack").attr("disabled")) {
1181+
$("#jmpStepBack").trigger('click');
1182+
k.preventDefault(); // don't horizontally scroll the display
1183+
}
1184+
}
1185+
else if (k.keyCode == 39) { // right arrow
1186+
if (!$("#vcrControls #jmpStepFwd").attr("disabled")) {
1187+
$("#jmpStepFwd").trigger('click');
1188+
k.preventDefault(); // don't horizontally scroll the display
1189+
}
1190+
}
1191+
});
11521192
});
11531193

example-code/towers_of_hanoi.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def TowerOfHanoi(n, a, b, tmp):
88
b.append(a.pop())
99
TowerOfHanoi(n-1, tmp, b, a)
1010

11-
stack1 = [5,4,3,2,1]
11+
stack1 = [4,3,2,1]
1212
stack2 = []
1313
stack3 = []
1414

index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@
6868

6969
<textarea id="pyInput" cols="55" rows="20" wrap="off"></textarea>
7070

71-
<p><button id="executeBtn" class="bigBtn" type="button">Visualize execution</button></p>
71+
<p>
72+
73+
<button id="executeBtn" class="bigBtn" type="button">Visualize execution</button>
74+
75+
<br/><br/><input type="checkbox" id="useJsPlumbCheckbox"/> Draw connector diagrams (experimental)
76+
77+
</p>
7278

7379
<p style="margin-top: 25px;">Try these small examples:<br/>
7480

0 commit comments

Comments
 (0)