Skip to content

Commit 9b0a455

Browse files
author
Philip Guo
committed
added Python 2/3 dropdown option
1 parent 59b6fde commit 9b0a455

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

‎v3/js/opt-frontend.js‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,24 @@ $(document).ready(function() {
7575
preseededCode = $.bbq.getState('code'); // yuck, global!
7676
var preseededMode = $.bbq.getState('mode');
7777

78+
79+
// ugh, ugly tristate due to the possibility of being undefined :)
7880
if ($.bbq.getState('cumulative_mode') == 'true') {
79-
$('#cumulativeMode').prop('checked', true);
81+
$('#cumulativeModeSelector').val('yes');
82+
}
83+
else if ($.bbq.getState('cumulative_mode') == 'false') {
84+
$('#cumulativeModeSelector').val('no');
85+
}
86+
// else if it's undefined, don't do anything ...
87+
88+
if ($.bbq.getState('python_version') == '3') {
89+
$('#pythonVersionSelector').val('3');
90+
}
91+
else if ($.bbq.getState('python_version') == '2') {
92+
$('#pythonVersionSelector').val('2');
8093
}
94+
// else if it's undefined, don't do anything ...
95+
8196

8297
// only bother with curInstr when we're visualizing ...
8398
if (!preseededCurInstr && preseededMode == 'visualize') { // TODO: kinda gross hack
@@ -149,7 +164,7 @@ $(document).ready(function() {
149164

150165
$.get(backend_script,
151166
{user_script : pyInputCodeMirror.getValue(),
152-
cumulative_mode: $('#cumulativeMode').prop('checked')},
167+
cumulative_mode: ($('#cumulativeModeSelector').val() == 'yes')},
153168
function(dataFromBackend) {
154169
var trace = dataFromBackend.trace;
155170

@@ -436,7 +451,8 @@ $(document).ready(function() {
436451
{code: pyInputCodeMirror.getValue(),
437452
curInstr: (appMode == 'visualize') ? myVisualizer.curInstr : 0,
438453
mode: appMode,
439-
cumulative_mode: $('#cumulativeMode').prop('checked')
454+
cumulative_mode: ($('#cumulativeModeSelector').val() == 'yes'),
455+
python_version: $('#pythonVersionSelector').val()
440456
},
441457
2);
442458
$('#urlOutput').val(urlStr);

‎v3/tutor.html‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,23 @@
6565

6666
<div id="codeInputPane"></div> <!-- populate with a CodeMirror instance -->
6767

68+
<p style="margin-top: 15px;">
69+
Execute code using
70+
<select id="pythonVersionSelector">
71+
<option value="2">Python 2.7</option>
72+
<option value="3">Python 3.2</option>
73+
</select>
74+
and
75+
<select id="cumulativeModeSelector">
76+
<option value="no">don't display exited functions (default).</option>
77+
<option value="yes">display frames of exited functions.</option>
78+
</select>
79+
</p>
80+
6881
<p>
6982
<button id="executeBtn" class="bigBtn" type="button">Visualize execution</button>
7083
</p>
7184

72-
<p><input type="checkbox" id="cumulativeMode"/>Display exited functions</p>
73-
7485

7586
<p style="margin-top: 25px;">Basic Examples:<br/>
7687

@@ -159,7 +170,7 @@
159170

160171
<p>
161172

162-
This version of Online Python Tutor runs <a
173+
Online Python Tutor supports <a
163174
href="http://www.python.org/doc/2.7/">Python 2.7</a> and <a
164175
href="http://www.python.org/doc/3.2/">Python 3.2</a> with limited module
165176
imports and no file I/O. It is designed for teaching programming, not

0 commit comments

Comments
 (0)