Skip to content

Commit 5d885f9

Browse files
author
Philip Guo
committed
added more lessons stuff
1 parent 79248d9 commit 5d885f9

4 files changed

Lines changed: 81 additions & 23 deletions

File tree

‎v3/css/opt-lessons.css‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ h2 {
2323

2424
body {
2525
background-color: white;
26+
2627
font-family: verdana, arial, helvetica, sans-serif;
28+
2729
font-size: 10pt;
2830

2931
max-width: 900px;
@@ -38,13 +40,22 @@ div#lessonHeader {
3840

3941
div#lessonTitle {
4042
font-size: 16pt;
41-
margin-bottom: 10pt;
43+
margin-bottom: 15pt;
4244
}
4345

44-
div#lessonExposition {
45-
font-size: 12pt;
46+
div#lessonDescription {
47+
font-size: 11pt;
48+
line-height: 1.5em;
4649
}
4750

51+
div#lessonNarration {
52+
font-size: 11pt;
53+
min-height: 25px;
54+
margin-bottom: 8px;
55+
line-height: 1.5em;
56+
}
57+
58+
4859
a,
4960
a:visited,
5061
a:hover {
@@ -91,4 +102,3 @@ button.bigBtn {
91102
padding-top: 12px;
92103
margin-top: 5px;
93104
}
94-

‎v3/js/opt-lessons.js‎

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,20 @@ var backend_script = 'exec'; // URL of backend script, which must eventually cal
3333

3434
var myVisualizer = null; // singleton ExecutionVisualizer instance
3535

36+
var lessonScript = null;
37+
var metadataJSON = null;
38+
3639
function parseLessonFile(dat) {
3740
var toks = dat.split('======');
38-
var lessonScript = toks[0].rtrim();
39-
var metadataJSON = $.parseJSON(toks[1]);
40-
console.log(lessonScript);
41-
console.log(metadataJSON);
41+
42+
// globals
43+
lessonScript = toks[0].rtrim();
44+
metadataJSON = $.parseJSON(toks[1]);
45+
46+
$('#lessonTitle').html(metadataJSON.title);
47+
$('#lessonDescription').html(metadataJSON.description);
48+
49+
document.title = metadataJSON.title + ' - Online Python Tutor (v3)';
4250

4351
$.get(backend_script,
4452
{user_script : lessonScript},
@@ -60,7 +68,8 @@ function parseLessonFile(dat) {
6068
else {
6169
myVisualizer = new ExecutionVisualizer('pyOutputPane',
6270
dataFromBackend,
63-
{embeddedMode: true});
71+
{embeddedMode: true,
72+
updateOutputCallback: updateLessonNarration});
6473

6574
myVisualizer.updateOutput();
6675

@@ -71,9 +80,28 @@ function parseLessonFile(dat) {
7180
"json");
7281
}
7382

83+
function updateLessonNarration(myViz) {
84+
var curInstr = myViz.curInstr;
85+
86+
assert(metadataJSON);
87+
88+
var annotation = metadataJSON[curInstr + 1]; // adjust for indexing diffs
89+
if (annotation) {
90+
$('#lessonNarration').html(annotation);
91+
}
92+
else {
93+
$('#lessonNarration').html('');
94+
}
95+
96+
// hack from John DeNero to ensure that once a div grows it height, it
97+
// never shrinks again
98+
$('#lessonNarration').css('min-height', $('#lessonNarration').css('height'));
99+
}
100+
74101
$(document).ready(function() {
75102

76-
$.get("lessons/aliasing.txt", parseLessonFile);
103+
//$.get("lessons/aliasing.txt", parseLessonFile);
104+
$.get("lessons/dive-into-python-311.txt", parseLessonFile);
77105

78106
// log a generic AJAX error handler
79107
$(document).ajaxError(function() {

‎v3/lesson.html‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
-->
3131

3232
<head>
33-
<title>Online Python Tutor (v3)</title>
33+
<title></title>
3434

3535
<!-- requirements for pytutor.js -->
3636
<script type="text/javascript" src="js/d3.v2.min.js"></script>
@@ -43,14 +43,6 @@
4343
<script type="text/javascript" src="js/pytutor.js"></script>
4444
<link rel="stylesheet" href="css/pytutor.css"/>
4545

46-
47-
<!-- requirements for opt-lessons.js -->
48-
49-
<!-- codemirror.net online code editor -->
50-
<script type="text/javascript" src="js/codemirror/codemirror.js"></script>
51-
<link type="text/css" href="css/codemirror.css" rel="stylesheet" />
52-
<script type="text/javascript" src="js/codemirror/python.js"></script>
53-
5446
<script type="text/javascript" src="js/opt-lessons.js"></script>
5547
<link rel="stylesheet" href="css/opt-lessons.css"/>
5648

@@ -60,13 +52,13 @@
6052

6153
<div id="lessonHeader">
6254

63-
<div id="lessonTitle">Set Intersection and Union</div>
64-
65-
<div id="lessonExposition">Let's say you have several sets of people
66-
that you want to union and intersect ...</div>
55+
<div id="lessonTitle"></div>
56+
<div id="lessonDescription"></div>
6757

6858
</div>
6959

60+
<div id="lessonNarration"></div>
61+
7062
<div id="pyOutputPane">
7163
</div>
7264

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
li = ["a", "b", "mpilgrim", "z", "example"]
2+
slice1 = li[1:3]
3+
slice2 = li[1:-1]
4+
slice3 = li[0:3]
5+
li.append("new")
6+
li.insert(2, "new")
7+
li.extend(["two", "elements"])
8+
======
9+
{
10+
"title": "Basic List Operations",
11+
12+
"description": "This lesson was derived from Section 3.2 of <a href='http://www.diveintopython.net/native_data_types/lists.html'>Dive Into Python</a>.",
13+
14+
"2": "First, you define a list of five elements. Note that they retain their original order. This is not an accident. A list is an ordered set of elements enclosed in square brackets.",
15+
16+
"3": "You can get a subset of a list, called a \"slice\", by specifying two indices. The return value is a new list containing all the elements of the list, in order, starting with the first slice index (in this case <code>li[1]</code>), up to but not including the second slice index (in this case <code>li[3]</code>).",
17+
18+
"4": "Slicing works if one or both of the slice indices is negative. If it helps, you can think of it this way: reading the list from left to right, the first slice index specifies the first element you want, and the second slice index specifies the first element you don't want. The return value is everything in between.",
19+
20+
"5": "Lists are zero-based, so <code>li[0:3]</code> returns the first three elements of the list, starting at <code>li[0]</code>, up to but not including <code>li[3]</code>.",
21+
22+
"6": "<code>append</code> adds a single element to the end of the list.",
23+
24+
"7": "<code>insert</code> inserts a single element into a list. The numeric argument is the index of the first element that gets bumped out of position. Note that list elements do not need to be unique; there are now two separate elements with the value '<code>new</code>', <code>li[2]</code> and <code>li[6]</code>.",
25+
26+
"8": "<code>extend</code> concatenates lists. Note that you do not call <code>extend</code> with multiple arguments; you call it with one argument, a list. In this case, that list has two elements."
27+
28+
}

0 commit comments

Comments
 (0)