Skip to content

Commit cb5cb55

Browse files
committed
bam
1 parent 82d4bbc commit cb5cb55

5 files changed

Lines changed: 29 additions & 26 deletions

File tree

‎v5-unity/js/iframe-embed.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
99
*/
1010

11-
var pytutor = require('./pytutor.ts');
12-
var assert = pytutor.assert;
13-
1411
require('../css/opt-frontend.css');
1512

1613
// need to directly import the class for typechecking to work

‎v5-unity/js/opt-frontend-common.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ declare var codeopticonSession: string; // FIX later when porting Codeopticon
2626
require('./lib/diff_match_patch.js');
2727
require('./lib/jquery.ba-dotimeout.min.js');
2828

29-
var pytutor = require('./pytutor.ts');
30-
var assert = pytutor.assert;
31-
29+
// need to directly import the class for type checking to work
30+
import {ExecutionVisualizer, assert, htmlspecialchars} from './pytutor.ts';
3231

3332
// these settings are all customized for my own server setup,
3433
// so you will need to customize for your server:
@@ -89,7 +88,7 @@ const langSettingToJsonpEndpoint = {
8988
export abstract class AbstractBaseFrontend {
9089
sessionUUID: string = generateUUID(); // remains constant throughout one page load ("session")
9190

92-
myVisualizer; // singleton ExecutionVisualizer instance from pytutor.ts
91+
myVisualizer: ExecutionVisualizer;
9392
originFrontendJsFile: string; // "abstract" -- must override in subclass
9493

9594
// 'edit' or 'display'. also support 'visualize' for backward
@@ -203,7 +202,7 @@ export abstract class AbstractBaseFrontend {
203202
logEventCodeopticon(obj) { } // NOP
204203

205204
setFronendError(lines) {
206-
$("#frontendErrorOutput").html(lines.map(pytutor.htmlspecialchars).join('<br/>'));
205+
$("#frontendErrorOutput").html(lines.map(htmlspecialchars).join('<br/>'));
207206
}
208207

209208
clearFrontendError() {
@@ -288,7 +287,7 @@ export abstract class AbstractBaseFrontend {
288287
this.isExecutingCode = false;
289288
}
290289

291-
// execute codeToExec and create a new pytutor.ExecutionVisualizer
290+
// execute codeToExec and create a new ExecutionVisualizer
292291
// object with outputDiv as its DOM parent
293292
executeCodeAndCreateViz(codeToExec,
294293
pyState,
@@ -326,10 +325,10 @@ export abstract class AbstractBaseFrontend {
326325
frontendOptionsObj.runTestCaseCallback(trace);
327326
} else {
328327
// success!
329-
this.myVisualizer = new pytutor.ExecutionVisualizer(outputDiv, dataFromBackend, frontendOptionsObj);
328+
this.myVisualizer = new ExecutionVisualizer(outputDiv, dataFromBackend, frontendOptionsObj);
330329
// SUPER HACK -- slip in backendOptionsObj as an extra field
331330
// NB: why do we do this? for more detailed logging?
332-
this.myVisualizer.backendOptionsObj = backendOptionsObj;
331+
(this.myVisualizer as any).backendOptionsObj = backendOptionsObj;
333332
this.finishSuccessfulExecution(); // TODO: should we also run this if we're calling runTestCaseCallback?
334333
}
335334

‎v5-unity/js/opt-frontend.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
- also implement these options and stdin support too:
1212
var optionNames = ['showStringsAsObjects', 'showAllFields', 'disableNesting'];
1313
14-
[probably do this in the FRONTEND and not in pytutor.js]
15-
1614
- test logging via viz_interaction.py and updateHistory
1715
1816
- we're referring to top-level CSS selectors on the page; maybe use a
@@ -52,9 +50,7 @@ require('script!./lib/socket.io-client/socket.io.js');
5250
// need to directly import the class for type checking to work
5351
import {AbstractBaseFrontend, generateUUID, supports_html5_storage} from './opt-frontend-common.ts';
5452
import {OptTestcases, redSadFace, yellowHappyFace} from './opt-testcases.ts';
55-
56-
var pytutor = require('./pytutor.ts');
57-
var assert = pytutor.assert;
53+
import {ExecutionVisualizer, assert, htmlspecialchars} from './pytutor.ts';
5854

5955
require('../css/opt-frontend.css');
6056
require('../css/opt-testcases.css');
@@ -852,7 +848,7 @@ export class OptFrontendWithTestcases extends OptFrontend {
852848

853849
var msg = trace[0].exception_msg;
854850
var trimmedMsg = msg.split(':')[0];
855-
$('#outputTd_' + id).html(pytutor.htmlspecialchars(trimmedMsg));
851+
$('#outputTd_' + id).html(htmlspecialchars(trimmedMsg));
856852
} else {
857853
// scan through the trace to find any exception events. report
858854
// the first one if found, otherwise assume test is 'passed'
@@ -1133,8 +1129,8 @@ $(document).ready(function() {
11331129
assert(mod == 'display' || mod == 'visualize' /* deprecated */);
11341130
var myArgs = optFrontend.getAppState();
11351131
delete myArgs.mode;
1136-
(myArgs as any).codeDivWidth = optFrontend.myVisualizer.DEFAULT_EMBEDDED_CODE_DIV_WIDTH;
1137-
(myArgs as any).codeDivHeight = optFrontend.myVisualizer.DEFAULT_EMBEDDED_CODE_DIV_HEIGHT;
1132+
(myArgs as any).codeDivWidth = ExecutionVisualizer.DEFAULT_EMBEDDED_CODE_DIV_WIDTH;
1133+
(myArgs as any).codeDivHeight = ExecutionVisualizer.DEFAULT_EMBEDDED_CODE_DIV_HEIGHT;
11381134

11391135
var domain = "http://pythontutor.com/"; // for deployment
11401136
var embedUrlStr = $.param.fragment(domain + "iframe-embed.html", myArgs, 2 /* clobber all */);

‎v5-unity/js/opt-live.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
require('../css/opt-frontend.css');
99
require('../css/opt-live.css');
1010

11-
var optCommon = require('./opt-frontend-common.ts');
11+
// need to directly import the class for type checking to work
12+
import {AbstractBaseFrontend, generateUUID, supports_html5_storage} from './opt-frontend-common.ts';
13+
1214
var pytutor = require('./pytutor.ts');
1315
var assert = pytutor.assert;
1416

@@ -57,6 +59,14 @@ declare var jsonp_endpoint: string;
5759
*/
5860

5961

62+
export class OptLiveFrontend extends AbstractBaseFrontend {
63+
originFrontendJsFile: string = 'opt-live.js';
64+
pyInputAceEditor; // Ace editor object that contains the user's code
65+
66+
67+
}
68+
69+
6070
// TODO: refactor me below
6171

6272
// TODO: overriding backend_script from opt-frontend-common.js is also dicey, ergh
@@ -88,9 +98,6 @@ var ruby_backend_script = 'LIVE_exec_ruby.py';
8898
var c_backend_script = 'LIVE_exec_c.py';
8999
var cpp_backend_script = 'LIVE_exec_cpp.py';
90100

91-
92-
var originFrontendJsFile = 'opt-live.js';
93-
94101
var prevVisualizer = null; // the visualizer object from the previous execution
95102

96103
var aceEditorWidth = '550px';

‎v5-unity/js/pytutor.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ var rightwardNudgeHack = true; // suggested by John DeNero, toggle with global
6565

6666
// the main event!
6767
export class ExecutionVisualizer {
68-
static curVisualizerID: number = 1;
69-
static DEFAULT_EMBEDDED_CODE_DIV_WIDTH: number = 350;
70-
static DEFAULT_EMBEDDED_CODE_DIV_HEIGHT: number = 400;
68+
static curVisualizerID = 1;
69+
70+
static DEFAULT_EMBEDDED_CODE_DIV_WIDTH = 350;
71+
static DEFAULT_EMBEDDED_CODE_DIV_HEIGHT = 400;
7172

7273
params: any = {};
7374
curInputCode: string;
@@ -94,6 +95,9 @@ export class ExecutionVisualizer {
9495

9596
curInstr: number = 0;
9697

98+
updateHistory: any[];
99+
creationTime: number;
100+
97101
// API for adding a hook, created by David Pritchard
98102
// keys, hook names; values, list of functions
99103
pytutor_hooks: {string?: any[]} = {};

0 commit comments

Comments
 (0)