Debian Codegraph @

online/flask_templates/visual.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <!-- HTML file to host Blockly in a mobile WebView. -->
3 <html>
4 <head>
5 <meta charset="utf-8">
6 <meta name="viewport" content="width=device-width,height=device-width, initial-scale=0.9, maximum-scale=1">
7 <script src="jquery.min.js"></script>
8 <script src="Markdown.Converter.min.js"></script>
9 <script src="semantic.min.js"></script>
10 <link rel="stylesheet" type="text/css" href="semantic.min.css">
11
12
13
14 <script src="blockly_compressed.js"></script>
15 <script src="blocks_compressed.js"></script>
16 <script src="javascript_compressed.js"></script>
17 <script src="python_compressed.js"></script>
18 <link rel="stylesheet" type="text/css" href="webviewstyle.css">
19 <link rel="stylesheet" type="text/css" href="gauge.min.css">
20 <link rel="stylesheet" type="text/css" href="gauge-glossy.min.css">
21 <script src="msg/js/en.js"></script>
22 <link rel="stylesheet" type="text/css" href="piano.css">
23
24 <script src="blocks/blockHelp.js"></script>
25 <script src="blocks/api.js"></script>
26 <script src="blocks/FlotPlots.js"></script>
27 <script src="blocks/Lists.js"></script>
28 <script src="blocks/IO.js"></script>
29 <script src="blocks/Games.js"></script>
30 <script src="blocks/Sounds.js"></script>
31 <script src="blocks/KuttyPy.js"></script>
32 <script src="blocks/Sensors.js"></script>
33 <script src="blocks/MP.js"></script>
34
35 <!-- IoT and JSON -->
36 <script src="blocks/Mosquito.js"></script>
37
38
39
40
41 <script src="blocks/acorn_interpreter.js"></script>
42
43
44 <script src="quill/quill.min.js"></script>
45 <script src="quill/myquill.js"></script>
46 <link rel="stylesheet" type="text/css" href="quill/quill.snow.css" />
47 <script src="quill/katex.min.js"></script>
48 <link rel="stylesheet" type="text/css" href="quill/katex.min.css" />
49
50 <script src="jspdf.min.js"></script>
51 <script src="mqtt.min.js"></script>
52 <script src="html2canvas.min.js"></script>
53
54 <script language="javascript" type="text/javascript" src="flot/jquery.canvaswrapper.js"></script>
55 <script language="javascript" type="text/javascript" src="flot/jquery.colorhelpers.js"></script>
56 <script language="javascript" type="text/javascript" src="flot/jquery.flot.js"></script>
57 <script language="javascript" type="text/javascript" src="flot/jquery.flot.saturated.js"></script>
58 <script language="javascript" type="text/javascript" src="flot/jquery.flot.browser.js"></script>
59 <script language="javascript" type="text/javascript" src="flot/jquery.flot.drawSeries.js"></script>
60 <script language="javascript" type="text/javascript" src="flot/jquery.flot.uiConstants.js"></script>
61 <script language="javascript" type="text/javascript" src="flot/jquery.flot.legend.js"></script>
62 <script language="javascript" type="text/javascript" src="flot/jquery.flot.symbol.js"></script>
63 <script language="javascript" type="text/javascript" src="flot/jquery.flot.axislabels.js"></script>
64
65
66
67
68
69 </head>
70
71 <body>
72
73
74 <xml xmlns="https://developers.google.com/blockly/xml" id="samplexml" style="display:none;">
75 <block type="controls_repeat_ext" id="CaRiJ`PO7(C~_]{a,s,=" x="97" y="102">
76 <value name="TIMES">
77 <shadow type="math_number" id="s6Pd)]!)5ZCMLqGt8P2l">
78 <field name="NUM">200</field>
79 </shadow>
80 </value>
81 <statement name="DO">
82 <block type="plot_datapoint" id="e6[G1FD]j8VV#-FRt$WP">
83 <field name="PLOTNAME">myplot</field>
84 <value name="VALUE">
85 <block type="get_voltage" id="#DtrcKI*rtD9?WHDu)5_">
86 <field name="CHANNEL">1</field>
87 </block>
88 </value>
89 </block>
90 </statement>
91 </block>
92 </xml>
93
94
95 <xml xmlns="https://developers.google.com/blockly/xml" id="mytoolbox" style="display: none">
96 <sep></sep>
97
98
99 <category name="Variables" colour="#a55b80" custom="VARIABLE">
100 </category>
101 <category name="Values" colour="#a55b80">
102 <block type="math_number">
103 <field name="NUM">0</field>
104 </block>
105 <block type="math_number">
106 <field name="NUM">1000</field>
107 </block>
108 <block type="math_number">
109 <field name="NUM">1</field>
110 </block>
111 <block type="math_number">
112 <field name="NUM">15</field>
113 </block>
114 <block type="math_number">
115 <field name="NUM">255</field>
116 </block>
117 <block type="binary_value">
118 </block>
119 <block type="reg">
120 </block>
121
122 <block type="text">
123 <field name="TEXT"></field>
124 </block>
125 <block type="logic_boolean">
126 <field name="BOOL">TRUE</field>
127 </block>
128
129 <block type="math_constant">
130 <field name="CONSTANT">PI</field>
131 </block>
132
133 </category>
134
135 <category name="Operators" colour="#5b80a5">
136
137
138 <block type="math_arithmetic">
139 <field name="OP">ADD</field>
140 <value name="A">
141 <shadow type="math_number">
142 <field name="NUM">1</field>
143 </shadow>
144 </value>
145 <value name="B">
146 <shadow type="math_number">
147 <field name="NUM">1</field>
148 </shadow>
149 </value>
150 </block>
151
152 <block type="text_join" >
153 <mutation items="2"></mutation>
154 <value name="ADD0">
155 <shadow type="text">
156 <field name="TEXT"></field>
157 </shadow>
158 </value>
159 <value name="ADD1">
160 <shadow type="text">
161 <field name="TEXT"></field>
162 </shadow>
163 </value>
164 </block>
165
166 <block type="lists_subtract_return">
167 </block>
168
169 <block type="shift_bits">
170 <value name="VALUE">
171 <shadow type="math_number">
172 <field name="NUM">1</field>
173 </shadow>
174 </value>
175 </block>
176
177 <block type="clear_bit">
178 <value name="VALUE">
179 <shadow type="math_number">
180 <field name="NUM">255</field>
181 </shadow>
182 </value>
183 </block>
184
185 <block type="and_or">
186 <value name="VALUE">
187 <shadow type="math_number">
188 <field name="NUM">255</field>
189 </shadow>
190 </value>
191 <value name="VALUE2">
192 <shadow type="math_number">
193 <field name="NUM">1</field>
194 </shadow>
195 </value>
196 </block>
197
198 <block type="logic_operation">
199 <field name="OP">AND</field>
200 </block>
201
202 <block type="logic_negate"></block>
203 <sep></sep>
204 </category>
205
206 <category name="Logic" colour="#5b80a5">
207 <block type="logic_boolean">
208 <field name="BOOL">TRUE</field>
209 </block>
210
211 <block type="logic_compare">
212 <field name="OP">EQ</field>
213 </block>
214
215 <block type="controls_if"></block>
216
217 <block type="logic_ternary"></block>
218
219 </category>
220
221
222 <category name="In / Out" colour="#5ba58c">
223
224 <block type="cs_print">
225 <value name="TEXT">
226 <shadow type="text">
227 <field name="TEXT">hello</field>
228 </shadow>
229 </value>
230 </block>
231
232 <block type="cs_sticker">
233 <value name="LABEL">
234 <shadow type="text">
235 <field name="TEXT">Parameter</field>
236 </shadow>
237 </value>
238 <value name="TEXT">
239 <shadow type="text">
240 <field name="TEXT">Reading</field>
241 </shadow>
242 </value>
243 </block>
244
245
246 <block type="text_prompt_ext">
247 <mutation type="TEXT"></mutation>
248 <field name="TYPE">TEXT</field>
249 <value name="TEXT">
250 <shadow type="text">
251 <field name="TEXT">Enter Input</field>
252 </shadow>
253 </value>
254 </block>
255
256
257 <block type="write_to_file">
258 </block>
259
260
261 <block type="save_lists">
262 </block>
263
264 <block type="cs_gauge">
265 <value name="VALUE">
266 <shadow type="math_number">
267 <field name="NUM">0</field>
268 </shadow>
269 </value>
270 </block>
271
272
273 </category>
274
275 <category name="Loops" colour="#5ba55b">
276 <block type="wait_seconds">
277 <field name="SECONDS">1</field>
278 </block>
279 <block type="controls_repeat_ext">
280 <value name="TIMES">
281 <shadow type="math_number">
282 <field name="NUM">20</field>
283 </shadow>
284 </value>
285 </block>
286
287 <block type="controls_whileUntil">
288 <field name="MODE">WHILE</field>
289 <value name="BOOL">
290 <shadow type="logic_boolean">
291 <field name="BOOL">TRUE</field>
292 </shadow>
293 </value>
294 </block>
295
296 <block type="controls_for">
297 <field name="VAR" id="LbE2%mV/CRs,w^fwYIZy">i</field>
298 <value name="FROM">
299 <shadow type="math_number">
300 <field name="NUM">1</field>
301 </shadow>
302 </value>
303 <value name="TO">
304 <shadow type="math_number">
305 <field name="NUM">10</field>
306 </shadow>
307 </value>
308 <value name="BY">
309 <shadow type="math_number">
310 <field name="NUM">1</field>
311 </shadow>
312 </value>
313 </block>
314 <block type="controls_forEach">
315 <field name="VAR" id="}KE@V7,)cpEQ-Df=Q3r(">j</field>
316 </block>
317 <block type="controls_flow_statements">
318 <field name="FLOW">BREAK</field>
319 </block>
320 </category>
321 <sep></sep>
322
323
324 <category name="Text" colour="%{BKY_TEXTS_HUE}">
325
326 <block type="text">
327 <field name="TEXT"></field>
328 </block>
329
330 <block type="text_join" >
331 <mutation items="2"></mutation>
332 <value name="ADD0">
333 <shadow type="text">
334 <field name="TEXT"></field>
335 </shadow>
336 </value>
337 <value name="ADD1">
338 <shadow type="text">
339 <field name="TEXT"></field>
340 </shadow>
341 </value>
342 </block>
343
344 <block type="text_append">
345 <field name="VAR" id="NA?/#Ojn#=$$1[^`/^Dd">item</field>
346 <value name="TEXT">
347 <shadow type="text">
348 <field name="TEXT"></field>
349 </shadow>
350 </value>
351 </block>
352
353 <block type="cs_search">
354 <value name="CHILD">
355 <shadow type="text">
356 <field name="TEXT">small string</field>
357 </shadow>
358 </value>
359 <value name="PARENT">
360 <shadow type="text">
361 <field name="TEXT">much longer string</field>
362 </shadow>
363 </value>
364 </block>
365
366
367 </category>
368
369
370
371 <category name="Math" colour="#5b67a5">
372 <block type="math_number">
373 <field name="NUM">0</field>
374 </block>
375
376 <block type="math_arithmetic">
377 <field name="OP">ADD</field>
378 <value name="A">
379 <shadow type="math_number">
380 <field name="NUM">1</field>
381 </shadow>
382 </value>
383 <value name="B">
384 <shadow type="math_number">
385 <field name="NUM">1</field>
386 </shadow>
387 </value>
388 </block>
389
390 <block type="math_single">
391 <field name="OP">ROOT</field>
392 <value name="NUM">
393 <shadow type="math_number">
394 <field name="NUM">9</field>
395 </shadow>
396 </value>
397 </block>
398 <block type="math_trig">
399 <field name="OP">SIN</field>
400 <value name="NUM">
401 <shadow type="math_number">
402 <field name="NUM">45</field>
403 </shadow>
404 </value>
405 </block>
406
407
408 <block type="math_number_property">
409 <mutation divisor_input="false"></mutation>
410 <field name="PROPERTY">EVEN</field>
411 <value name="NUMBER_TO_CHECK">
412 <shadow type="math_number">
413 <field name="NUM">0</field>
414 </shadow>
415 </value>
416 </block>
417 <block type="math_round">
418 <field name="OP">ROUND</field>
419 <value name="NUM">
420 <shadow type="math_number">
421 <field name="NUM">3.1</field>
422 </shadow>
423 </value>
424 </block>
425 <block type="math_on_list">
426 <mutation op="SUM"></mutation>
427 <field name="OP">SUM</field>
428 </block>
429 <block type="math_modulo">
430 <value name="DIVIDEND">
431 <shadow type="math_number">
432 <field name="NUM">64</field>
433 </shadow>
434 </value>
435 <value name="DIVISOR">
436 <shadow type="math_number">
437 <field name="NUM">10</field>
438 </shadow>
439 </value>
440 </block>
441 <block type="math_random_int">
442 <value name="FROM">
443 <shadow type="math_number">
444 <field name="NUM">1</field>
445 </shadow>
446 </value>
447 <value name="TO">
448 <shadow type="math_number">
449 <field name="NUM">100</field>
450 </shadow>
451 </value>
452 </block>
453
454
455
456 </category>
457 <category name="Lists" colour="#745ba5">
458 <block type="lists_new">
459 </block>
460
461 <block type="lists_split">
462 <mutation mode="SPLIT"></mutation>
463 <field name="MODE">SPLIT</field>
464 <value name="INPUT">
465 <shadow type="text">
466 <field name="TEXT"></field>
467 </shadow>
468 </value>
469 <value name="DELIM">
470 <shadow type="text">
471 <field name="TEXT">,</field>
472 </shadow>
473 </value>
474 </block>
475
476
477 <block type="lists_push">
478 </block>
479 <block type="lists_push_time">
480 </block>
481
482 <block type="lists_subtract">
483 </block>
484 <block type="lists_subtract_return">
485 </block>
486
487 <block type="lists_getIndex">
488 <mutation statement="false" at="true"></mutation>
489 <field name="MODE">GET</field>
490 <field name="WHERE">FROM_START</field>
491 <value name="VALUE">
492 <block type="variables_get">
493 <field name="VAR" id="ZHzR_1b9[t1=F!y{a.VT">list</field>
494 </block>
495 </value>
496 </block>
497 <block type="lists_setIndex">
498 <mutation at="true"></mutation>
499 <field name="MODE">SET</field>
500 <field name="WHERE">FROM_START</field>
501 <value name="LIST">
502 <block type="variables_get">
503 <field name="VAR" id="ZHzR_1b9[t1=F!y{a.VT">list</field>
504 </block>
505 </value>
506 </block>
507 <block type="lists_length"></block>
508 <block type="lists_isEmpty"></block>
509 <block type="lists_create_with">
510 <mutation items="0"></mutation>
511 </block>
512 <block type="lists_sort">
513 <field name="TYPE">NUMERIC</field>
514 <field name="DIRECTION">1</field>
515 </block>
516 </category>
517 <category name="PLOTS" colour="#995b95">
518
519 <block type="plot_scale">
520 </block>
521
522
523 <block type="plot_datapoint">
524 </block>
525 <block type="plot_xy">
526 </block>
527
528 <block type="plot_xyarray">
529 </block>
530
531 <block type="plot_xyyarray">
532 </block>
533
534 <block type="plot_xyyyarray">
535 </block>
536
537 <block type="plot_radar">
538 <value name="MAXRADIUS">
539 <shadow type="math_number">
540 <field name="NUM">30</field>
541 </shadow>
542 </value>
543 </block>
544
545 </category>
546 <category name="Functions" colour="#995ba5" custom="PROCEDURE"></category>
547
548
549
550 <sep></sep>
551
552 <category name="KuttyPy" colour="#995ba5">
553
554 <block type="get_voltage">
555 <field name="CHANNEL">1</field>
556 </block>
557
558 <block type="get_reg">
559 </block>
560 <block type="get_reg_from_string">
561 <field name="REGISTER">PINA</field>
562 </block>
563 <block type="set_reg">
564 <value name="VALUE">
565 <shadow type="math_number">
566 <field name="NUM">255</field>
567 </shadow>
568 </value>
569 </block>
570
571 <block type="set_reg_from_string">
572 <value name="REGISTER">
573 <block type="reg">
574 <field name="REGISTER">PORTB</field>
575 </block>
576 </value>
577
578 <value name="VALUE">
579 <block type="binary_value">
580 <field name="B3">TRUE</field>
581 </block>
582 <block type="binary_value">
583 <field name="B2">TRUE</field>
584 </block>
585 <block type="binary_value">
586 <field name="B1">TRUE</field>
587 </block>
588 <block type="binary_value">
589 <field name="B0">TRUE</field>
590 </block>
591 </value>
592 </block>
593
594 <block type="set_reg_bits_string">
595 <field name="REGISTER">DDRB</field>
596 </block>
597
598 <block type="set_reg_bits">
599 </block>
600
601
602 <block type="shift_bits">
603 <value name="VALUE">
604 <shadow type="math_number">
605 <field name="NUM">1</field>
606 </shadow>
607 </value>
608 </block>
609
610 <block type="bytes_to_int">
611 </block>
612
613 <block type="set_pwm">
614 </block>
615
616 <block type="read_i2c_sensor_flexible_dynamic">
617 </block>
618
619 <category name="Sensors" colour="#5b67a5">
620
621 <block type="read_i2c_sensor_flexible_dynamic">
622 </block>
623
624 <block type="read_i2c_sensor_flexible_dynamic_array">
625 </block>
626
627 <block type="scanI2Cselector">
628 </block>
629 <block type="read_i2c_sensor_flexible">
630 <value name="NAME">
631 <shadow type="text">
632 <field name="TEXT">[118]BMP280</field>
633 </shadow>
634 </value>
635 </block>
636 <block type="scanI2CString">
637 </block>
638 <block type="read_I2C_sensor">
639 </block>
640
641 <block type="read_BMP280">
642 <field name="CHANNEL">1</field>
643 </block>
644 <block type="read_MPU6050">
645 <field name="CHANNEL">0</field>
646 </block>
647 <block type="read_MAX6675">
648 <field name="CHANNEL">CS1</field>
649 </block>
650
651 <block type="read_VL53L0X">
652 <field name="CHANNEL">0</field>
653 </block>
654 <block type="read_HMC5883L">
655 <field name="CHANNEL">0</field>
656 </block>
657 <block type="read_ADS1115">
658 <field name="CHANNEL">0</field>
659 </block>
660 <block type="read_INA219">
661 <field name="CHANNEL">0</field>
662 </block>
663 <block type="read_TCS34725">
664 </block>
665 <block type="read_TSL2561">
666 <field name="CHANNEL">0</field>
667 </block>
668 <block type="read_TSL2591">
669 <field name="CHANNEL">0</field>
670 </block>
671 <block type="read_QMC5883L">
672 <field name="CHANNEL">0</field>
673 </block>
674 <block type="read_MAX30100">
675 <field name="CHANNEL">0</field>
676 </block>
677
678 </category>
679
680 <category name="Outputs" colour="#5b67a5">
681 <block type="set_PCA9685">
682 <field name="CHANNEL">1</field>
683 </block>
684 <block type="direction">
685 </block>
686
687 <block type="init_stepper">
688 </block>
689
690 <block type="move_stepper">
691 <value name="STEPS">
692 <shadow type="math_number">
693 <field name="NUM">10</field>
694 </shadow>
695 </value>
696
697 <value name="DELAY">
698 <shadow type="math_number">
699 <field name="NUM">10</field>
700 </shadow>
701 </value>
702
703 </block>
704
705 <block type="move_steppers">
706
707 <value name="STEPS1">
708 <shadow type="math_number">
709 <field name="NUM">10</field>
710 </shadow>
711 </value>
712
713
714 <value name="STEPS2">
715 <shadow type="math_number">
716 <field name="NUM">10</field>
717 </shadow>
718 </value>
719
720 <value name="DELAY">
721 <shadow type="math_number">
722 <field name="NUM">10</field>
723 </shadow>
724 </value>
725
726 </block>
727
728
729 </category>
730
731 <category name="Analysis" colour="#5b67a5">
732
733 <block type="sine_fit_arrays">
734 </block>
735
736 <block type="sine_fit_two_arrays">
737 </block>
738
739 </category>
740
741
742 </category>
743
744
745 <category name="AI" colour="#ff4">
746 <block type="add_mp_hands"></block>
747 <block type="del_mp_hands"></block>
748 <block type="ai_distance"></block>
749 </category>
750
751 <category name="Phone" colour="#5b67a5">
752 <block type="cs_start_timer">
753 </block>
754 <block type="cs_get_timer">
755 </block>
756
757 </category>
758
759
760 <category name="Games" colour="#995b95">
761
762 <block type="add_game">
763 </block>
764 <block type="stop_game">
765 </block>
766
767 <block type="set_bird_y">
768 <value name="Y">
769 <shadow type="math_number">
770 <field name="NUM">200</field>
771 </shadow>
772 </value>
773
774 </block>
775
776
777 <block type="add_piano">
778 </block>
779
780 <block type="play_piano">
781 <value name="NOTE">
782 <shadow type="text">
783 <field name="TEXT">C</field>
784 </shadow>
785 </value>
786
787 </block>
788
789
790
791
792 </category>
793
794 <category name="Internet of Things" colour="#c95bc5">
795 <block type="mqtt_connect">
796 </block>
797 <block type="mqtt_publish">
798 <value name="CHANNEL">
799 <shadow type="text">
800 <field name="TEXT">SENSOR</field>
801 </shadow>
802 </value>
803
804 <value name="DATA">
805 <shadow type="text">
806 <field name="TEXT">SAMPLE</field>
807 </shadow>
808 </value>
809
810 </block>
811
812 <block type="mqtt_subscribe">
813 </block>
814 <block type="mqtt_hasdata">
815 </block>
816 <block type="mqtt_fetchdata">
817 </block>
818 <sep></sep>
819 <block type="mqtt_json">
820 </block>
821
822
823 </category>
824
825
826 </xml>
827
828 <div class="ui icon error mini hidden message missingdevice" style="padding: 3px !important;margin:0px;">
829 <div class="content">
830 <p>Missing Hardware! Is a device Connected?</p>
831 </div>
832 </div>
833
834 <div class="ui top help sidebar" >
835 <div id="quillheader">
836 <a onClick= "toggleHelpEdit()" class="ui mini primary button enablehelpedit">Instructions <i class="pencil icon"></i></a>
837
838 <a class="ui basic mini red button right floated" onclick="hideHelp()"><i class="ui angle double up icon"></i> Hide</a>
839 <div class = "ui mini buttons right floated helpediton" style="display:none">
840 <a onClick= "helpeditor.history.undo()" class="ui red basic button"><i class="undo icon"></i></a>
841 <a onClick= "helpeditor.history.redo()" class="ui green basic button" style="margin-right:40px"><i class="redo icon"></i></a>
842 </div>
843
844 </div>
845 <hr>
846 <div id="quilleditor"></div>
847 </div>
848
849
850 <div onclick="$(this).sidebar('hide');" class="ui inverted labeled icon right vertical settings sidebar menu" >
851
852 <input type="text" id="filename" onclick="event.stopPropagation();" name="fname" placeholder="Filename" style="font-size:12pt;width:150px" value="myfile"></input>
853 <div class="divider"></div>
854
855 <a onclick="saveXMLtoDisc()" class="ui red item">
856 <i class="red block save icon"></i> Save
857 </a>
858 <a onclick="openFile()" class="ui green item">
859 <i class="block green file outline icon"></i> Open
860 </a>
861
862 <a onclick="loadEditor()" class="ui item">
863 <i class="block blue pencil icon"></i> Edit JavaScript
864 </a>
865
866 <a onclick="showCode()" class="ui item">
867 <i class="block yellow user secret icon"></i> Hmm
868 </a>
869
870 </div>
871
872
873 <div class="ui content mygrid pusher" style="padding:0.2rem ! important;">
874 <div id="toolbar" class="ui secondary menu mini ">
875 <audio id="remoteAudio" autoplay></audio>
876
877 <div class="item">
878 <a onclick="toggleRun()" class="ui mini primary button runbutton"><i class="play icon"></i><span class="text">Run!</span></a>
879 </div>
880
881 <!-- Button to open the experiment list modal -->
882 <div class="item"><button class="ui basic red button" id="openMenuButton"><i class="red block file icon"></i>Samples</button></div>
883
884
885 <div class="right menu">
886
887 <div class="ui right aligned item">
888 <a onclick="saveXML()" class="ui mini red button" ><i class="download icon"></i></a>
889 </div>
890 <div class="ui right aligned item">
891 <a onclick="getCachedXML()" class="ui mini teal button" ><i class="upload icon"></i></a>
892 </div>
893
894 <div class="ui right aligned item">
895 <a onclick="showHelp()" class="ui mini green button" ><i class="question icon"></i>Help </a>
896 </div>
897 <div class="ui right aligned item">
898 <a onclick="showQuiz()" class="ui mini green button popquiz" style="display:none"><i class="question icon"></i>Quiz </a>
899 </div>
900
901 <div class="item">
902 <div class="ui toggle checkbox bcast">
903 <label><i class="wifi icon"></i></label>
904 <input type="checkbox" name="public">
905 </div>
906 </div>
907
908 <div class="ui right aligned item">
909 <a onclick="showSettings()" class="ui mini pink button" >Menu<i class="ui angle double right icon"></i></a>
910 </div>
911
912 </div>
913 </div>
914
915 <div id="blocklyArea">
916 <div id="blocklyDiv">
917 </div>
918 </div>
919 </div>
920
921
922
923 <!-- -------------results _-------------- -->
924 <div class="ui very wide bottom results sidebar overlay" >
925 <div class="ui centered header">
926
927 <a onclick="savePDF()" class="ui right corner huge blue label" ><i class="download icon pdfdownloadicon"></i></a>
928 <a onclick="toggleResultSize(this);" class="ui top left attached label" ><i class="ui double angle down red icon"></i></a>
929 <div onclick="toggleFullscreen();" class="ui wide teal label" style="padding-left:20px;padding-right:20px;" ><i class="sliders horizontal icon" ></i> Output </div>
930
931
932 </div>
933
934 <div class="ui content mygrid" style="padding:0.2rem ! important; background-color:#fff5f5e3">
935 <div id="myresults" class="ui two column stackable top aligned grid ">
936 <div class="ui vertical divider"></div>
937 <div class="top aligned row">
938
939 <div class="column resplotarea" style="background:#fffe;">
940 <div id="resplot" class="ui description resplot">
941 </div>
942 </div>
943
944 <div class="column">
945 <div class="top aligned row">
946 <div class="ui relaxed horizontal divided list gauges">
947 </div>
948 </div>
949
950 <div class="ui celled list registers" style="color:#a33;">
951 </div>
952 <div class="ui description cmdarea" style="color:darkgreen;">
953 </div>
954
955 <div class="ui scrolling content description printarea" style="color:black;scrollable:true;">
956 </div>
957 </div>
958
959
960 </div>
961 </div>
962
963 </div>
964
965 </div>
966
967
968 <div class="ui help modal">
969 <i class="close icon"></i>
970 <div id="helptitle" class="header">
971 Title
972 </div>
973 <div class="image content">
974 <div id="helpdescription" class="description">
975 Help
976 </div>
977 </div>
978 </div>
979
980 <!-- Modal -->
981 <div class="ui modal" id="experimentsModal">
982 <div class="header">Sample Programs Menu</div>
983 <div class="content">
984 <div id="menu"></div>
985 </div>
986 <div class="actions">
987 <button class="ui button red" id="closeMenuButton">Close</button>
988 </div>
989 </div>
990
991 <script type="text/javascript">
992
993 function showSettings(){
994 $('.ui.settings.sidebar').sidebar('setting', {
995 dimPage : true,
996 transition : 'overlay',
997 mobileTransition : 'overlay'})
998 .sidebar('show');
999 }
1000
1001 $('.ui.dropdown').dropdown();
1002 $('.top.menu .item').tab({onVisible: function(a){switchHelp(a);}})
1003
1004 var workspaceHelp = '';
1005 var workspaceMD = '';
1006 var converter = new Markdown.Converter();
1007 var results = $('.description.printarea');
1008 var resultModal = $('.modal.results');
1009 var resplotarea = $('.resplotarea');
1010 var resultplots = $('.description.resplot');
1011 var mygrid = $('.content.mygrid');
1012
1013 var isRunning = false;
1014
1015
1016 var registers = $('.list.registers');
1017 var gaugearea = $('.list.gauges');
1018 var regvals = [];
1019 var command = $('.description.cmdarea');
1020
1021 // Fetch the experiments.json and populate the menu
1022 fetch('/samples/experiments.json')
1023 .then(response => response.json())
1024 .then(data => {
1025 const menuContainer = document.getElementById('menu');
1026
1027 for (const [section, details] of Object.entries(data)) {
1028 // Create section container
1029 const sectionDiv = document.createElement('div');
1030 sectionDiv.className = 'menu-section';
1031
1032 // Add section title
1033 const sectionTitle = document.createElement('h3');
1034 sectionTitle.className = 'menu-title';
1035 sectionTitle.textContent = section;
1036 sectionDiv.appendChild(sectionTitle);
1037
1038 // Add section description
1039 const sectionDescription = document.createElement('p');
1040 sectionDescription.textContent = details.description;
1041 sectionDiv.appendChild(sectionDescription);
1042
1043 // Add files as buttons
1044 const fileList = document.createElement('div');
1045 fileList.className = 'menu-items';
1046 for (const [file, description] of Object.entries(details.files)) {
1047 const fileButton = document.createElement('button');
1048 fileButton.className = 'ui basic button primary';
1049 fileButton.textContent = file;
1050 fileButton.dataset.filename = `${details.directory}/${file}`; // Store filename in dataset
1051
1052 // On button click, call the /loadxml endpoint
1053 fileButton.addEventListener('click', function() {
1054 const filename = this.dataset.filename;
1055 fetch(`/loadxml?file=${encodeURIComponent(filename)}`)
1056 .then(response => response.json())
1057 .then(data => {
1058 console.log('Response from /loadxml:', data);
1059 loadRawXml(data.xml);
1060 $('#experimentsModal').modal('hide');
1061 })
1062 .catch(error => console.error('Error fetching /loadxml:', error));
1063 });
1064
1065 fileList.appendChild(fileButton);
1066 }
1067
1068 sectionDiv.appendChild(fileList);
1069 menuContainer.appendChild(sectionDiv);
1070 }
1071 })
1072 .catch(error => console.error('Error fetching the JSON:', error));
1073
1074 // Open modal
1075 $('#openMenuButton').click(function() {
1076 $('#experimentsModal').modal('show');
1077 });
1078
1079 // Close modal
1080 $('#closeMenuButton').click(function() {
1081 $('#experimentsModal').modal('hide');
1082 });
1083
1084
1085 // Initialize Help Window sidebar
1086 var helpeditor = loadquill();
1087
1088 // Initialize function helps (Block wise help)
1089 var helptitle = $('#helptitle');
1090 var helpdescription = $('#helpdescription');
1091
1092 function showBlockHelp(name){
1093 helptitle.text(name);
1094 helpdescription.html(Blockly.Msg[name]);
1095 $('.ui.modal')
1096 .modal({
1097 blurring: true
1098 })
1099 .modal('show')
1100 ;
1101 }
1102
1103 function updateJSONarea() {
1104 //document.getElementById('json_area').value = Blockly.JSON.fromWorkspace( Blockly.getMainWorkspace() );
1105 console.log(Blockly.JSON.fromWorkspace( Blockly.getMainWorkspace() ));
1106 }
1107
1108 function interpretJSONarea() {
1109 //Blockly.JSON.toWorkspace( document.getElementById('json_area').value, Blockly.getMainWorkspace() );
1110 console.log(document.getElementById('json_area').value, Blockly.getMainWorkspace());
1111 }
1112
1113
1114 var JSBridge;
1115 var HWBridge;
1116 var devState = false;
1117
1118 var isTeacher=false;
1119 var roomname='none';
1120
1121 function showReg(reg, val){
1122 regclass = 'reg_'+reg.replace(/ /g,"_").replace(/-/g,"_");
1123 if(regvals.indexOf(regclass)!=-1){ // Register is already shown in the results segment. update it.
1124 registers.find('.'+regclass).text(reg+"="+val);
1125 }else{
1126 registers.append(`<div class="item ${regclass}">${reg}=${val}</div>`)
1127 regvals.push(regclass);
1128 }
1129 }
1130
1131
1132
1133 var workspacePlayground = Blockly.inject('blocklyDiv', {
1134 media: 'media/',
1135 toolbox: mytoolbox,
1136 toolboxPosition : 'start',
1137 horizontal: true,
1138 trashcan: true,
1139
1140 zoom: {
1141 startScale: 0.8,
1142 wheel: true,
1143 controls: false
1144 },
1145 move:{
1146 scrollbars: {
1147 horizontal: true,
1148 vertical: true
1149 },
1150 drag: true,
1151 wheel: true
1152 },
1153 drag: true,
1154 css : true
1155 }
1156 );
1157
1158 var blocklyArea = document.getElementById('blocklyArea');
1159 var onresize = function(e) {
1160 // Compute the absolute coordinates and dimensions of blocklyArea.
1161 var element = blocklyArea;
1162 var x = 0;
1163 var y = 0;
1164 do {
1165 x += element.offsetLeft;
1166 y += element.offsetTop+20;
1167 element = element.offsetParent;
1168 } while (element);
1169 // Position blocklyDiv over blocklyArea.
1170 //blocklyDiv.style.left = x + 'px';
1171 //blocklyDiv.style.top = y + 'px';
1172 //blocklyDiv.style.width = blocklyArea.offsetWidth + 'px';
1173 //blocklyDiv.style.height = (blocklyArea.offsetHeight-20) + 'px';
1174 Blockly.svgResize(workspacePlayground);
1175 };
1176 //window.addEventListener('resize', onresize, false);
1177 //onresize();
1178 Blockly.svgResize(workspacePlayground);
1179
1180
1181 Blockly.Xml.clearWorkspaceAndLoadFromXml($('#samplexml')[0], workspacePlayground);
1182
1183
1184 $('.ui.results.sidebar').sidebar('hide');
1185
1186 function toggleResultSize(e){
1187 var sb = $('.ui.results.sidebar');
1188 if($(e.firstChild).hasClass('down')){
1189 $(e.firstChild).addClass('up').removeClass('down');
1190 sb.attr('style','height:35% !important;');
1191 }else{
1192 $(e.firstChild).addClass('down').removeClass('up');
1193 sb.attr('style','height:75% !important;');
1194 }
1195 }
1196
1197
1198 function toggleFullscreen(){
1199 var sb = $('.ui.results.sidebar');
1200 if(fullscreen){
1201 sb.attr('style','height:50% !important;');
1202 fullscreen = false;
1203 }else{
1204 sb.attr('style','height:92% !important;');
1205 fullscreen = true;
1206 }
1207 if(typeof JSBridge != 'undefined')
1208 JSBridge.showMP(fullscreen);
1209 }
1210
1211
1212
1213 function savePDF(){
1214
1215 $('.pdfdownloadicon').addClass('notched circle loading').removeClass('download');
1216 setTimeout(()=>{
1217
1218 var element = $('#myresults');
1219 var HTML_Width = element.width();
1220 var HTML_Height = element.height();
1221 var top_left_margin = 15;
1222 var PDF_Width = HTML_Width + (top_left_margin * 2);
1223 var PDF_Height = (PDF_Width * 1.5) + (top_left_margin * 2);
1224 var canvas_image_width = HTML_Width;
1225 var canvas_image_height = HTML_Height;
1226
1227 var totalPDFPages = Math.ceil(HTML_Height / PDF_Height) - 1;
1228
1229 html2canvas(element[0]).then(function (canvas) {
1230 var imgData = canvas.toDataURL("image/jpeg", 0.85);
1231 var pdf = new jsPDF('p', 'pt', [PDF_Width, PDF_Height]);
1232 pdf.addImage(imgData, 'JPG', top_left_margin, top_left_margin, canvas_image_width, canvas_image_height);
1233 for (var i = 1; i <= totalPDFPages; i++) {
1234 console.log(HTML_Width+','+HTML_Height+','+i);
1235 pdf.addPage(PDF_Width, PDF_Height);
1236 pdf.addImage(imgData, 'JPG', top_left_margin, -(PDF_Height*i)+(top_left_margin*4),canvas_image_width,canvas_image_height);
1237 }
1238 //pdf.save("results.pdf");
1239 $('.pdfdownloadicon').removeClass('notched circle loading').addClass('download');
1240 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))
1241 {
1242 JSBridge.savePDF("results", pdf.output('datauristring'));
1243
1244 }
1245 else
1246 {
1247 pdf.save('filename.pdf');
1248 }
1249 });
1250 }, 50);
1251
1252 }
1253
1254
1255
1256
1257
1258
1259 function on() {
1260 isRunning = true;
1261 $('.runbutton').removeClass('primary').addClass('red');
1262 $('.runbutton > .text').text('Stop');
1263 $('.runbutton > .icon').removeClass('play').addClass('stop');
1264
1265 registers.empty();
1266 regvals = [];
1267 results.html("");
1268
1269 $('.ui.results.sidebar').sidebar('setting', {
1270 dimPage : false,
1271 transition : 'overlay',
1272 closable : false,
1273 exclusive : true,
1274 mobileTransition : 'overlay'})
1275 .sidebar('show');
1276 }
1277
1278 $('.blocklyToolboxContents').first().append(`
1279 <div width="85%">
1280 <div class = "ui fluid buttons" style="margin-top:30px;">
1281 <a onClick= "workspacePlayground.undo(false)" class="ui mini red basic button"><i class="undo icon"></i></a>
1282 <a onClick= "workspacePlayground.undo(true)" class="ui mini green basic button"><i class="redo icon"></i></a>
1283 </div>
1284 </div>
1285 `);
1286
1287
1288 function playButtonOff(){
1289 isRunning = false;
1290 $('.runbutton').removeClass('red').removeClass('orange').addClass('primary');
1291 $('.runbutton > .text').text('Run!');
1292 $('.runbutton > .icon').removeClass('stop').removeClass('double angle down').addClass('play');
1293
1294 }
1295 function off() {
1296 if(typeof JSBridge != 'undefined')
1297 if($('.checkbox.bcast').checkbox('is checked'))
1298 JSBridge.offBroadcast();
1299
1300 $('.ui.results.sidebar').sidebar('hide');
1301
1302 playButtonOff();
1303
1304 resetStepUi();
1305 resetInterpreter();
1306 if(typeof JSBridge != 'undefined')
1307 JSBridge.closeFiles();
1308 stopGame();
1309 stopMQTT();
1310 }
1311
1312 function resetInterpreter() {
1313 myInterpreter = null;
1314 if (runner) {
1315 clearTimeout(runner);
1316 runner = null;
1317 }
1318 }
1319
1320 function showJSCode() {
1321 // Generate JavaScript code and display it.
1322 Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
1323 var code = Blockly.JavaScript.workspaceToCode(workspacePlayground);
1324 }
1325 var myInterpreter;
1326
1327 var runner;
1328 var highlightPause = false;
1329 var latestCode = '';
1330 var filehandlecodes_js={},filehandlecodes_py={};
1331
1332 var autoScalingX = true;
1333 var autoScalingY = true;
1334
1335
1336 function highlightBlock(id) {
1337 workspacePlayground.highlightBlock(id);
1338 highlightPause = true;
1339 }
1340
1341 function resetStepUi() {
1342 workspacePlayground.highlightBlock(null);
1343 highlightPause = false;
1344
1345 }
1346
1347 function deviceConnected(){
1348 $('.message.missingdevice').closest('.message').transition('fade out','300mS');
1349 }
1350 function deviceDisconnected(){
1351 $('.message.missingdevice').closest('.message').transition('fade in','1000mS').transition('glow');
1352 }
1353 var url = new URL(window.location.href);
1354 var state = url.searchParams.get("connected");
1355 if(typeof state != 'undefined' && state === "false")
1356 deviceDisconnected()
1357
1358
1359 function chatDisconnected(){
1360 $('.chatstatus').transition('fade out','300mS');
1361 }
1362 function chatConnected(message,connect){
1363 $('.chatstatus > .chatmsg').text(message);
1364 if(connect)$('.chatstatus > .button').show();
1365 else $('.chatstatus > .button').hide();
1366 $('.chatstatus').transition('fade in','1000mS').transition('glow');
1367 }
1368
1369
1370 function toggleRun(){
1371 if(isRunning){
1372 off();
1373 }else{
1374 startStep();
1375 }
1376
1377
1378 }
1379
1380 function startStep() {
1381 if(typeof JSBridge != 'undefined')
1382 if($('.checkbox.bcast').checkbox('is checked'))
1383 JSBridge.startStepBroadcast();
1384
1385
1386 // Generate JavaScript code and parse it.
1387 Blockly.JavaScript.STATEMENT_PREFIX = 'highlightBlock(%1);\n';
1388 Blockly.JavaScript.addReservedWords('highlightBlock');
1389 filehandlecodes_js={};
1390 filehandlecodes_py={};
1391 latestCode = Blockly.JavaScript.workspaceToCode(workspacePlayground);
1392
1393
1394
1395 resetStepUi();
1396 on();
1397 clearPlot();
1398 createPlots(latestCode);
1399 resplotarea.show();
1400
1401
1402
1403 runCode();
1404 }
1405
1406 function initAllApis(interpreter, scope){
1407 console.log('Init all apis');
1408
1409 initApi(interpreter, scope);
1410 initLists(interpreter, scope);
1411 initIO(interpreter, scope);
1412 initPlots(interpreter, scope);
1413 initGames(interpreter, scope);
1414 initKuttyPy(interpreter, scope);
1415 initSensors(interpreter, scope);
1416 initSounds(interpreter, scope);
1417
1418 initMP(interpreter, scope);
1419 initMQTT(interpreter, scope);
1420
1421 }
1422
1423
1424
1425 function runCode() {
1426 console.log('start running code');
1427 if (!myInterpreter) {
1428 // First statement of this code.
1429 // Clear the program output.
1430 resetStepUi();
1431 console.log('step UI reset');
1432
1433 // And then show generated code in an alert.
1434 // In a timeout to allow the outputArea.value to reset first.
1435 setTimeout(function() {
1436 // Begin execution
1437 try{
1438 highlightPause = false;
1439 if(!latestCode.startsWith('programStarting')){
1440 var fileopenlines = '';
1441 for(l in filehandlecodes_js)
1442 fileopenlines+= filehandlecodes_js[l];
1443 //latestCode = 'programStarting();' + fileopenlines+latestCode;
1444 }
1445
1446 try{myInterpreter = new Interpreter(latestCode, initAllApis);}
1447 catch(e){console.log(e.message+';'+e.stack);off();return;};
1448
1449 if(latestCode.search("alert") != -1) // -1 means not found
1450 on();
1451
1452 runner = function() {
1453 if (myInterpreter) {
1454 try{
1455 var hasMore = myInterpreter.run();
1456 }catch(e){
1457 console.log(e);
1458 var stack = ''
1459 var segments = e.stack.split('\n');
1460 for(var i=0;i<segments.length && i<10;i++){
1461 stack+=segments[segments.length-i-1].split('file:')[0]+',';
1462 }
1463 results.append(`<p style="color:red">${e.name}:${e.message}</p>`);
1464 $('#maincontent').prepend(`
1465 <div class="ui error program message">
1466 <i class="close icon"></i>
1467 <div class="header">
1468 ${e.name}. Check the Highlighted Block
1469 </div>
1470 <ul class="list">
1471 <li>
1472 ${e.message}
1473 </li>
1474 <li>
1475 ${stack}
1476 </li>
1477 </ul>
1478 </div>
1479 `);
1480 $(".close.icon").click(function(){
1481 $(this).parent().hide();
1482 });
1483 // Stop Program.
1484 console.log('Program ended');
1485 off();
1486 setTimeout(()=>{ $('.ui.results.sidebar').sidebar('setting',{closable:true,dimPage:true}).sidebar('show'); },50 );
1487 return;
1488 }
1489
1490 if (hasMore) {
1491 // Execution is currently blocked by some async call.
1492 // Try again later.
1493 setTimeout(runner, 2); // TODO . Critical . can cause crashes.
1494 return;
1495 } else {
1496 console.log("we're done here");
1497 // Program is complete.
1498 $('.runbutton').removeClass('red').addClass('orange');
1499 $('.runbutton > .text').text('Done!');
1500 $('.runbutton > .icon').removeClass('stop').addClass('double angle down');
1501 resetInterpreter();
1502 resetStepUi();
1503 //off();
1504 }
1505 }
1506 };
1507
1508 runner();
1509
1510 }catch(e){
1511 console.log(e);
1512 var stack = ''
1513 var segments = e.stack.split('\n');
1514 for(var i=0;i<segments.length && i<5;i++){
1515 stack+=segments[segments.length-i-1].split('(file:')[0]+',';
1516 }
1517 $('#maincontent').prepend(`
1518 <div class="ui error program message">
1519 <i class="close icon"></i>
1520 <div class="header">
1521 ${e.name} . Check the plots.
1522 </div>
1523 <div class="content">
1524 ${e.message}
1525 ${stack}
1526
1527 </div>
1528 </div>
1529 `);
1530 $(".close.icon").click(function(){
1531 $(this).parent().hide();
1532 });
1533 // Stop Program.
1534 off();
1535 setTimeout(()=>{console.log('closing due to error'); $('.ui.results.sidebar').sidebar('hide');},50);
1536 return;
1537 }
1538
1539
1540 }, 1);
1541 return;
1542 }
1543 }
1544
1545
1546
1547
1548
1549 function saveXML(){
1550 if(typeof JSBridge != 'undefined')
1551 JSBridge.saveXML("kuttypy",injectHelp());
1552 else
1553 localStorage.setItem('kuttypy', injectHelp());
1554 }
1555
1556 function getCachedXML(){
1557 if(typeof JSBridge != 'undefined')
1558 JSBridge.loadLocalXML('kuttypy',loadRawXml)
1559 else
1560 loadXML(localStorage.getItem('kuttypy'));
1561 }
1562
1563 function loadXML(xml) {
1564
1565 if (typeof xml != "string" || xml.length < 5) {
1566 return false;
1567 }
1568
1569 try {
1570 var dom = Blockly.Xml.textToDom(xml);
1571 Blockly.mainWorkspace.clear();
1572 Blockly.Xml.domToWorkspace(dom,Blockly.mainWorkspace);
1573
1574 parser = new DOMParser();
1575 xmlDoc = parser.parseFromString(xml,"text/xml");
1576 loadhelp(xmlDoc);
1577 loadquiz(xmlDoc);
1578 return true;
1579 } catch (e) {
1580 console.log("XML Load Error",e);
1581 console.log(xml)
1582 return false;
1583 }
1584 }
1585 function loadRawXml(msg){
1586 var parsedxml = Blockly.Xml.textToDom(msg);
1587 loadhelp(parsedxml);
1588 Blockly.Xml.clearWorkspaceAndLoadFromXml(parsedxml,workspacePlayground);
1589 console.log('loaded new file');
1590 }
1591
1592
1593 function loadhelp(xml) {
1594 try {
1595 workspaceMD = $(xml).find('description').text();
1596 if(workspaceMD.startsWith('<')){
1597 helpeditor.clipboard.dangerouslyPasteHTML(workspaceMD);
1598 }else{ // Process markdown
1599 helpeditor.clipboard.dangerouslyPasteHTML(converter.makeHtml(workspaceMD));
1600 }
1601 return true;
1602 } catch (e) {
1603 console.log("Invalid xml",e);
1604 return false;
1605 }
1606 }
1607
1608 function showHelp(){
1609 $('.ui.help.sidebar').sidebar('setting', {
1610 dimPage : false,
1611 transition : 'overlay',
1612 mobileTransition : 'overlay'})
1613 .sidebar('show');
1614 }
1615
1616 function loadquiz(xml) {
1617 try {
1618 quizString = $(xml).find('quizzing').text();
1619 if(quizString.length>2) $('.popquiz').show();
1620 return true;
1621 } catch (e) {
1622 console.log("Invalid xml",e);
1623 return false;
1624 }
1625 }
1626 function showQuiz(){
1627 if(typeof JSBridge != 'undefined' && quizString.length>2)
1628 JSBridge.showQuizDialog(quizString);
1629
1630 }
1631
1632
1633 function hideHelp(){
1634 disableHelpEdit();
1635 $('.ui.help.sidebar').sidebar('hide');
1636 }
1637
1638 function toggleHelpEdit(){
1639 if($('.enablehelpedit').hasClass('red'))
1640 disableHelpEdit();
1641 else
1642 enableHelpEdit();
1643 }
1644 function enableHelpEdit(){
1645 $('.helpediton').show();
1646 $('.ql-toolbar').show();
1647 $('.enablehelpedit').addClass('red');
1648 helpeditor.enable();
1649 }
1650 function disableHelpEdit(){
1651 $('.helpediton').hide();
1652 $('.ql-toolbar').hide();
1653 helpeditor.disable();
1654 $('.enablehelpedit').removeClass('red');
1655 }
1656
1657
1658
1659 function injectHelp(){
1660 var helpContent = workspaceMD;
1661 if(helpeditor.root.innerHTML.length>15)helpContent = helpeditor.root.innerHTML;
1662 var xmlDom = Blockly.Xml.workspaceToDom(workspacePlayground);
1663 var text = Blockly.Xml.domToPrettyText(xmlDom);
1664 if(helpContent.length)
1665 text = text.split('</xml')[0] + "<description>\n<![CDATA[" + helpContent + "]]>" + "\n</description>\n</xml>";
1666 console.log(text);
1667 return text;
1668 }
1669
1670
1671
1672
1673 function showCode() {
1674 // Generate Python code and display it.
1675 Blockly.Python.INFINITE_LOOP_TRAP = null;
1676 Blockly.Python.init(workspacePlayground)
1677 var code = Blockly.Python.workspaceToCode(workspacePlayground);
1678 alert(code);
1679 }
1680
1681
1682 function myUpdateFunction(event) {
1683
1684 //resetInterpreter();
1685 Blockly.Python.init(workspacePlayground)
1686 Blockly.JavaScript.init(workspacePlayground)
1687
1688 var xmlDom = Blockly.Xml.workspaceToDom(Blockly.mainWorkspace);
1689 var xmlText = Blockly.Xml.domToPrettyText(xmlDom);
1690
1691 if(typeof JSBridge != 'undefined'){
1692 var pycode= Blockly.Python.workspaceToCode(workspacePlayground);
1693
1694 var fileopenlines = '';
1695 for(l in filehandlecodes_py)
1696 fileopenlines += filehandlecodes_py[l];
1697 pycode = fileopenlines+pycode;
1698 JSBridge.updateCode(pycode);
1699
1700 JSBridge.xmlCode(xmlText, $('.checkbox.bcast').checkbox('is checked'));
1701 }
1702
1703 }
1704
1705 $('.checkbox.listen')
1706 .checkbox({
1707 onChecked: function() {
1708 $('.checkbox.bcast').checkbox('set unchecked')
1709 if(typeof JSBridge != 'undefined')
1710 JSBridge.listenBcast(true);
1711 },
1712 onUnchecked: function() {
1713 JSBridge.listenBcast(false);
1714 }
1715 });
1716
1717 $('.checkbox.bcast')
1718 .checkbox({
1719 onChecked: function() {
1720 $('.checkbox.listen').checkbox('set unchecked')
1721 }
1722 });
1723
1724 workspacePlayground.addChangeListener(myUpdateFunction);
1725
1726
1727 if(typeof JSBridge != 'undefined'){
1728 var localxml = JSBridge.loadXMLFile("xml");
1729 if(localxml.length>2) //To prevent loading, JSBridge can return an empty string
1730 loadXML(localxml);
1731 }
1732
1733
1734 function loadEditor(){ //Redirect to editor.html where the localstorage will return contents of the code.
1735 Blockly.JavaScript.STATEMENT_PREFIX = '';
1736 var mycode = Blockly.JavaScript.workspaceToCode(workspacePlayground)
1737 localStorage.setItem('kuttypycode', mycode);
1738 window.location = "/editor";
1739 }
1740
1741 function saveXMLtoDisc(){
1742 const textContent = injectHelp();
1743
1744 // Create a blob (file-like object) from the text content
1745 const blob = new Blob([textContent], { type: 'text/xml' });
1746
1747 // Create a link element for download
1748 const link = document.createElement('a');
1749 link.href = URL.createObjectURL(blob);
1750 link.download = 'myfile.xml'; // The filename for download
1751
1752 // Programmatically click the link to trigger the download
1753 link.click();
1754
1755 // Clean up by revoking the object URL after download
1756 URL.revokeObjectURL(link.href);
1757 }
1758 function openFile(){ // Launch file open dialog
1759 JSBridge.openFileDialog();
1760 }
1761
1762 document.addEventListener('keydown', function (event) {
1763 // Check if 'Ctrl+S' (or 'Cmd+S' on macOS) is pressed
1764 if ((event.ctrlKey || event.metaKey) && event.key === 's') {
1765 event.preventDefault(); // Prevent the default Ctrl+S action
1766 saveXML();
1767 }
1768 });
1769
1770 </script>
1771
1772 </body>
1773
1774
1775 </html>