1- /*
1+ // Python Tutor: https://github.com/pgbovine/OnlinePythonTutor/
2+ // Copyright (C) Philip Guo (philip@pgbovine.net)
3+ // LICENSE: https://github.com/pgbovine/OnlinePythonTutor/blob/master/LICENSE.txt
24
3- Online Python Tutor
4- https://github.com/pgbovine/OnlinePythonTutor/
5+ // TODO: using myVisualizer here borrowed from opt-frontend-common.js is
6+ // very dicey and dangerous due to scoping issues!
57
6- Copyright (C) Philip J. Guo (philip@pgbovine.net)
8+ // use Webpack to automatically package up these dependencies
79
8- Permission is hereby granted, free of charge, to any person obtaining a
9- copy of this software and associated documentation files (the
10- "Software"), to deal in the Software without restriction, including
11- without limitation the rights to use, copy, modify, merge, publish,
12- distribute, sublicense, and/or sell copies of the Software, and to
13- permit persons to whom the Software is furnished to do so, subject to
14- the following conditions:
10+ require ( '../css/opt-frontend.css' ) ;
11+ require ( '../css/opt-live.css' ) ;
1512
16- The above copyright notice and this permission notice shall be included
17- in all copies or substantial portions of the Software.
13+ var optCommon = require ( './opt-frontend-common.js' ) ;
14+ var pytutor = require ( './pytutor.js' ) ;
15+ var assert = pytutor . assert ;
1816
19- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17+ // just punt and use global script dependencies
18+ require ( "script!./ace/src-min-noconflict/ace.js" ) ;
19+ require ( 'script!./ace/src-min-noconflict/mode-python.js' ) ;
20+ require ( 'script!./ace/src-min-noconflict/mode-javascript.js' ) ;
21+ require ( 'script!./ace/src-min-noconflict/mode-typescript.js' ) ;
22+ require ( 'script!./ace/src-min-noconflict/mode-c_cpp.js' ) ;
23+ require ( 'script!./ace/src-min-noconflict/mode-java.js' ) ;
24+ require ( 'script!./ace/src-min-noconflict/mode-ruby.js' ) ;
2625
27- */
2826
2927// OPT live programming prototype started on 2016-05-30
3028// first launched as a "Live Programming Mode" button on main OPT site
@@ -57,14 +55,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5755*/
5856
5957
60- // Pre-reqs:
61- // - pytutor.js
62- // - jquery.ba-bbq.min.js
63- // - jquery.ba-dotimeout.min.js // for event debouncing: http://benalman.com/code/projects/jquery-dotimeout/examples/debouncing/
64- // - opt-frontend-common.js
65- // should all be imported BEFORE this file
66-
67-
6858// these scripts override the versions defined in opt-frontend-common.js
6959
7060// backend scripts to execute (Python 2 and 3 variants, if available)
@@ -128,6 +118,7 @@ function removeAllGutterDecorations() {
128118}
129119
130120function updateStepLabels ( ) {
121+ var myVisualizer = optCommon . getVisualizer ( ) ;
131122 assert ( myVisualizer ) ;
132123 myVisualizer . updateCurPrevLines ( ) ; // do this first to update the right fields
133124
@@ -167,6 +158,7 @@ function updateStepLabels() {
167158 . unbind ( 'click' )
168159 . click ( function ( ) {
169160 var userInput = ruiDiv . find ( '#raw_input_textbox' ) . val ( ) ;
161+ var myVisualizer = optCommon . getVisualizer ( ) ;
170162 // advance instruction count by 1 to get to the NEXT instruction
171163 myVisualizer . executeCodeWithRawInputFunc ( userInput , myVisualizer . curInstr + 1 ) ;
172164 } ) ;
@@ -236,6 +228,7 @@ function updateStepLabels() {
236228}
237229
238230function optliveFinishSuccessfulExecution ( ) {
231+ var myVisualizer = optCommon . getVisualizer ( ) ;
239232 assert ( myVisualizer ) ;
240233 $ ( "#pyOutputPane,#vcrControls" ) . show ( ) ;
241234 doneExecutingCode ( ) ;
@@ -259,6 +252,7 @@ function optliveFinishSuccessfulExecution() {
259252 // was changed by a user-initiated event, then this code should be
260253 // executed ...
261254 if ( evt . originalEvent ) {
255+ var myVisualizer = optCommon . getVisualizer ( ) ;
262256 myVisualizer . renderStep ( ui . value ) ;
263257 }
264258 //updateStepLabels(); // I don't think we need this anymore
@@ -331,6 +325,7 @@ function optliveFinishSuccessfulExecution() {
331325 uh . push ( [ args . myViz . curInstr , curTs ] ) ;
332326 }
333327
328+ var myVisualizer = optCommon . getVisualizer ( ) ;
334329 $ ( '#executionSlider' ) . slider ( 'value' , myVisualizer . curInstr ) ; // update slider
335330 updateStepLabels ( ) ;
336331
@@ -348,6 +343,7 @@ function optliveHandleUncaughtExceptionFunc(trace) {
348343 if ( errorLineNo !== undefined && errorLineNo != NaN ) {
349344 removeAllGutterDecorations ( ) ;
350345
346+ var myVisualizer = optCommon . getVisualizer ( ) ;
351347 if ( myVisualizer ) {
352348 toggleSyntaxError ( true ) ;
353349 myVisualizer . redrawConnectors ( ) ;
@@ -390,6 +386,7 @@ function initAceEditor(height) {
390386 resize : function ( evt , ui ) {
391387 pyInputAceEditor . resize ( ) ; // to keep Ace internals happy
392388 $ ( "#pyInputPane" ) . width ( $ ( "#codeInputPane" ) . width ( ) ) ; // to keep parent happy
389+ var myVisualizer = optCommon . getVisualizer ( ) ;
393390 if ( myVisualizer ) {
394391 myVisualizer . redrawConnectors ( ) ; // to keep visualizations happy
395392 }
@@ -451,8 +448,10 @@ function optliveExecuteCodeAndCreateViz(codeToExec,
451448 }
452449 }
453450 else {
451+ var myVisualizer = optCommon . getVisualizer ( ) ;
454452 prevVisualizer = myVisualizer ;
455- myVisualizer = new ExecutionVisualizer ( outputDiv , dataFromBackend , frontendOptionsObj ) ;
453+ var v = new ExecutionVisualizer ( outputDiv , dataFromBackend , frontendOptionsObj ) ;
454+ optCommon . setVisualizer ( v ) ;
456455 handleSuccessFunc ( ) ;
457456 }
458457
@@ -496,6 +495,7 @@ function optliveExecuteCodeAndCreateViz(codeToExec,
496495 assert ( false ) ;
497496 }
498497
498+ var myVisualizer = optCommon . getVisualizer ( ) ;
499499 // submit update history of the "previous" visualizer whenever you
500500 // run the code and hopefully get a new visualizer back
501501 //
@@ -602,45 +602,49 @@ function optliveExecuteCodeFromScratch() {
602602}
603603
604604$ ( document ) . ready ( function ( ) {
605- genericOptFrontendReady ( ) ;
605+ optCommon . genericOptFrontendReady ( ) ;
606606
607607 $ ( '#legendDiv' )
608608 . append ( '<svg id="prevLegendArrowSVG"/> line that has just executed' )
609609 . append ( '<p style="margin-top: 4px"><svg id="curLegendArrowSVG"/> next line to execute</p>' ) ;
610610
611611 d3 . select ( 'svg#prevLegendArrowSVG' )
612612 . append ( 'polygon' )
613- . attr ( 'points' , SVG_ARROW_POLYGON )
614- . attr ( 'fill' , lightArrowColor ) ;
613+ . attr ( 'points' , pytutor . SVG_ARROW_POLYGON )
614+ . attr ( 'fill' , pytutor . lightArrowColor ) ;
615615
616616 d3 . select ( 'svg#curLegendArrowSVG' )
617617 . append ( 'polygon' )
618- . attr ( 'points' , SVG_ARROW_POLYGON )
619- . attr ( 'fill' , darkArrowColor ) ;
618+ . attr ( 'points' , pytutor . SVG_ARROW_POLYGON )
619+ . attr ( 'fill' , pytutor . darkArrowColor ) ;
620620
621621 $ ( '#cumulativeModeSelector,#heapPrimitivesSelector,#textualMemoryLabelsSelector,#pythonVersionSelector' ) . change ( function ( ) {
622- setAceMode ( ) ;
622+ optCommon . setAceMode ( ) ;
623623 // force a re-execute on a toggle switch
624624 optliveExecuteCodeFromScratch ( ) ;
625625 } ) ;
626626
627- setAceMode ( ) ; // set syntax highlighting at the end
627+ optCommon . setAceMode ( ) ; // set syntax highlighting at the end
628628 $ ( "#pyOutputPane" ) . show ( ) ;
629629
630630
631631 $ ( "#jmpFirstInstr" ) . click ( function ( ) {
632+ var myVisualizer = optCommon . getVisualizer ( ) ;
632633 if ( myVisualizer ) { myVisualizer . renderStep ( 0 ) ; }
633634 } ) ;
634635
635636 $ ( "#jmpLastInstr" ) . click ( function ( ) {
637+ var myVisualizer = optCommon . getVisualizer ( ) ;
636638 if ( myVisualizer ) { myVisualizer . renderStep ( myVisualizer . curTrace . length - 1 ) ; }
637639 } ) ;
638640
639641 $ ( "#jmpStepBack" ) . click ( function ( ) {
642+ var myVisualizer = optCommon . getVisualizer ( ) ;
640643 if ( myVisualizer ) { myVisualizer . stepBack ( ) ; }
641644 } ) ;
642645
643646 $ ( "#jmpStepFwd" ) . click ( function ( ) {
647+ var myVisualizer = optCommon . getVisualizer ( ) ;
644648 if ( myVisualizer ) { myVisualizer . stepForward ( ) ; }
645649 } ) ;
646650} ) ;
0 commit comments