index_1.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Python Blockly</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <meta http-equiv="Content-Type" content="text/html; scharset=UTF-8">
  8. <meta name="theme-color" content="#2C4FCD">
  9. <link type="text/css" rel="stylesheet" href="libs/materialize.min.css" media="screen,projection">
  10. <link rel="stylesheet" href="libs/codemirror/codemirror.css" />
  11. <link rel="stylesheet" href="libs/font-awesome.min.css" />
  12. <link rel="stylesheet" href="libs/summernote/summernote.css" />
  13. <link rel="stylesheet" href="libs/multi-select.css" />
  14. <link rel="stylesheet" href="src/blockpy.css" />
  15. <!-- JQuery, D3, Math.js, Bootstrap -->
  16. <!-- <script type="text/javascript" src="libs/jquery.js"></script> -->
  17. <script type="text/javascript" src="libs/jquery-3.3.1.min.js"></script>
  18. <script type="text/javascript" src="libs/jquery-ui.min.js"></script>
  19. <script type="text/javascript" src="libs/jquery.hotkeys.js"></script>
  20. <script type="text/javascript" src="libs/jquery.multi-select.js"></script>
  21. <script type="text/javascript" src="libs/materialize.min.js"></script>
  22. <script type="text/javascript" src="libs/d3.min.js"></script>
  23. <script type="text/javascript" src="libs/math.0.19.0.min.js"></script>
  24. <!-- <script type="text/javascript" src="libs/bootstrap.min.js"></script>
  25. <script type="text/javascript" src="libs/bootstrap-wysiwyg.js"></script> -->
  26. <script type="text/javascript" src="libs/mindmup-editabletable.js"></script>
  27. <script type="text/javascript" src="libs/codemirror/codemirror.js"></script>
  28. <script type="text/javascript" src="libs/codemirror/python.js"></script>
  29. <script type="text/javascript" src="libs/codemirror/htmlmixed.js"></script>
  30. <script type="text/javascript" src="libs/codemirror/xml.js"></script>
  31. <script type="text/javascript" src="libs/knockout-3.4.0.js"></script>
  32. <script type="text/javascript" src="libs/stringify.js"></script>
  33. <!-- Summernote, a rich text editor -->
  34. <script type="text/javascript" src="libs/summernote/summernote.min.js"></script>
  35. <script type="text/javascript" src="libs/summernote/summernote-ext-hint.js"></script>
  36. <script type="text/javascript" src="libs/summernote/summernote-ext-video.js"></script>
  37. <!-- Blockly -->
  38. <script type="text/javascript" src="blockly/blockly_uncompressed.js"></script>
  39. <script type="text/javascript" src="blockly/blocks_compressed.js"></script>
  40. <script type="text/javascript" src="blockly/python_compressed.js"></script>
  41. <script type="text/javascript" src="blockly/pseudo_compressed.js"></script>
  42. <script type="text/javascript" src="blockly/javascript_compressed.js"></script>
  43. <script type="text/javascript" src="blockly/msg/js/en.js"></script>
  44. <!-- Skulpt -->
  45. <script type="text/javascript" src="skulpt/dist/skulpt.min.js"></script>
  46. <script type="text/javascript" src="skulpt/dist/skulpt-stdlib.js"></script>
  47. <!-- Source Code -->
  48. <script type="text/javascript" src="src/utilities.js"></script>
  49. <script type="text/javascript" src="src/python_errors.js"></script>
  50. <script type="text/javascript" src="src/ast_node_visitor.js"></script>
  51. <script type="text/javascript" src="src/abstract_interpreter.js"></script>
  52. <script type="text/javascript" src="src/pytifa.js"></script>
  53. <script type="text/javascript" src="src/abstract_interpreter_definitions.js"></script>
  54. <script type="text/javascript" src="src/python_to_blockly.js"></script>
  55. <script type="text/javascript" src="src/imported.js"></script>
  56. <script type="text/javascript" src="src/blockly_blocks/class.js"></script>
  57. <script type="text/javascript" src="src/blockly_blocks/comment.js"></script>
  58. <script type="text/javascript" src="src/blockly_blocks/comprehensions.js"></script>
  59. <script type="text/javascript" src="src/blockly_blocks/dict.js"></script>
  60. <script type="text/javascript" src="src/blockly_blocks/if.js"></script>
  61. <script type="text/javascript" src="src/blockly_blocks/io.js"></script>
  62. <script type="text/javascript" src="src/blockly_blocks/lists.js"></script>
  63. <script type="text/javascript" src="src/blockly_blocks/sets.js"></script>
  64. <script type="text/javascript" src="src/blockly_blocks/loops.js"></script>
  65. <script type="text/javascript" src="src/blockly_blocks/parking.js"></script>
  66. <script type="text/javascript" src="src/blockly_blocks/tuple.js"></script>
  67. <script type="text/javascript" src="src/blockly_blocks/turtles.js"></script>
  68. <script type="text/javascript" src="src/blockly_blocks/text.js"></script>
  69. <script type="text/javascript" src="src/blockly_blocks/plots.js"></script>
  70. <script type="text/javascript" src="src/dialog.js"></script>
  71. <script type="text/javascript" src="src/storage.js"></script>
  72. <script type="text/javascript" src="src/printer.js"></script>
  73. <script type="text/javascript" src="src/interface.js"></script>
  74. <script type="text/javascript" src="src/server.js"></script>
  75. <script type="text/javascript" src="src/english.js"></script>
  76. <script type="text/javascript" src="src/corgis.js"></script>
  77. <script type="text/javascript" src="src/history.js"></script>
  78. <script type="text/javascript" src="src/presentation.js"></script>
  79. <script type="text/javascript" src="src/editor.js"></script>
  80. <script type="text/javascript" src="src/feedback.js"></script>
  81. <script type="text/javascript" src="src/toolbar.js"></script>
  82. <script type="text/javascript" src="src/sk_mod_instructor_extended.js"></script>
  83. <script type="text/javascript" src="src/sk_mod_instructor.js"></script>
  84. <script type="text/javascript" src="src/engine.js"></script>
  85. <script type="text/javascript" src="src/main.js"></script>
  86. <script>
  87. $(document).ready(function() {
  88. $('.dropdown-trigger').dropdown();
  89. setTimeout(() => $('.modal').modal(), 0);
  90. blockpy = new BlockPy({
  91. blocklyPath: "blockly/",
  92. attachmentPoint: document.getElementById("blockpy-div"),
  93. instructor:
  94. !getQueryParams()["instructor"] ||
  95. getQueryParams()["instructor"] == "true",
  96. developer: true,
  97. editor: getQueryParams()["mode"] || "Split",
  98. urls: {
  99. }
  100. });
  101. blockpy.setAssignment(
  102. // settings
  103. {
  104. editor: getQueryParams()["mode"] || "Split",
  105. read_only: getQueryParams()["upload"] == "true",
  106. disable_semantic_errors: false,
  107. disable_timeout: true
  108. },
  109. // assignment
  110. {
  111. introduction:
  112. "Use the canvas below to calculate the sum of a list of 4 numbers.",
  113. name: "#1.3",
  114. //'give_feedback': 'from instructor_functions import *\nsuppress("analyzer", "Incompatible types")\nmatch_signature("curve_grade", 1, "old")\nunit_test("curve_grade", (64, True), (0, 0), (100, 100))',
  115. //'give_feedback': 'from instructor_functions import *\n5+""\nsuppress("analyzer", "Incompatible types")\nmatch_signature("rate_animal", 1, "old")\nunit_test("rate_animal", (64, True))',
  116. //'give_feedback': "log(parse_program().find_all('FunctionDef')[0].args.args[0].arg)",
  117. give_feedback: "set_success()",
  118. //'give_feedback': 'from instructor_utility import *\nfrom instructor_printing import *\n\nsuppress("analyzer")\nsuppress("instructor")\nhide_correctness()\n\nast = parse_program()\n\nall_checked = True\nanswers = [("1*2*3", "6"), ("3*4","12"), ("0","0"), ("5*-5", "-25")]\nfor an_input, result in answers:\n reset_output()\n queue_input(an_input)\n run_student()\n if not get_output():\n all_checked = False\n elif result not in get_output():\n if str(float(result)) in get_output():\n give_partial(.1/len(answers), "Checking Float "+an_input)\n all_checked = False\n else:\n give_partial(.2/len(answers), "Checking "+an_input)',
  119. //'give_feedback': "from instructor_utility import *\nensure_operation('in')",
  120. //'give_feedback': 'for x in range(2):\n reset_output()\n queue_input("Test", "")\n e = run_student()\n if e:\n gently(str(e))\n log(get_output())\nif not e:\n set_success()',
  121. //'give_feedback': "from instructor_files import *\nfiles_not_handled_correctly('example.txt')",
  122. //'give_feedback': "from instructor_imports import *\nensure_imports('math', 'random')",
  123. //'give_feedback': "from instructor_plotting import * \nprevent_incorrect_plt() \nensure_correct_plot('plot') \nensure_show() \ncheck_for_plot('line', [[1,2,3],[4,5,6]])",
  124. //'give_feedback': 'ast = parse_program()\nassignments = ast.find_all("Assign")\nfor assignment in assignments:\n if assignment.targets.id == "parking_allowed":\n log(assignment.targets.data_type)',
  125. on_change: "",
  126. //'on_change': 'gently("Test")',
  127. parsons: false,
  128. starting_code: "",
  129. importable: true,
  130. initial_view: getQueryParams()["mode"] || "Split",
  131. upload: getQueryParams()["upload"] == "true",
  132. modules: {
  133. added: ["Classes", "Tuples", "Data - Weather", "Request" , "Camera",'AIY Board','VisionKit','VoiceKit','System'],
  134. removed: []
  135. }
  136. },
  137. // programs
  138. {
  139. //'__main__': 'ss = ["Testing", "Here"]\nfor a in ss:\n print(a)\nfor b in a:\n print(b)',
  140. //'__main__': 'print("Hello world"[1:5])',
  141. __main__: ""
  142. //'__main__': 'num = input("")\nnum_list = [int(n) for n in num.split("*")]\nfor n in num_list:\n n*n\n return 4\nprint(n)',
  143. //'__main__': 'def rate_animal(an_animal):\n if an_animal != "dog":\n 1 + ""\nrate_animal("dog")',
  144. //'__main__': 'round(float("9.5", ___))',
  145. //'__main__': getQueryParams()["code"] || "import matplotlib.pyplot as plt\nplt.plot([1, 2, 3],[4, 5, 6])\nplt.show()",
  146. //'__main__': 'i=0\nwhile i!="0":\n i=input("")\n print(i)',
  147. //'__main__': "import requests\nprint(requests.get('https://pastebin.com/raw/V7tWn1Rj').text)"
  148. //'__main__': "print(open('example.txt').read())"
  149. //'__main__': "import math\nmath\nfrom random import choice\nchoice"
  150. //'__main__': "from random import randint\nprint(5+randint(1,10))"
  151. //'__main__': 'print(input("Prompt:"))',
  152. //'__main__': 'import parking\nparking_allowed = parking.now()\nif parking.now() > parking.Time(8,30,"AM") and parking.now() < parking.Time(5,30,"PM"):\n parking_allowed = False\nelse:\n parking_allowed = True \nprint(parking_allowed)'
  153. //'__main__': 'print("Banana"[:int(len("Banana")/2)])',
  154. //'__main__': 'def curve_grade(old):\n return (old ** .5) * 10\n\nprint(90, "becomes", curve_grade(90))\nprint(50, "becomes", curve_grade(50))\nprint(20, "becomes", curve_grade(20))'
  155. //'__main__': 'print(1 != 2 and 2 != 1)'
  156. }
  157. );
  158. function inIframe() {
  159. try {
  160. return window.self !== window.top;
  161. } catch (e) {
  162. return true;
  163. }
  164. }
  165. if (inIframe()) {
  166. $("#blockpy-container").width("100%");
  167. $("#blockpy-div").css("padding", 0);
  168. }
  169. });
  170. </script>
  171. </head>
  172. <body>
  173. <div id="white-box">
  174. <div id="preloader">
  175. <img src="./images/preloader.gif">
  176. <h4 style="margin:0;">Loading...</h4>
  177. </div>
  178. </div>
  179. <div id="container">
  180. <nav id="header">
  181. <div>
  182. <div id="logo">
  183. <span>Coco Python Blockly</span>
  184. <input id="sketch_name" value="Untitled" type="text" size="8" />
  185. <i id="delete-all">
  186. <img style="height:1.2rem;" src="./images/icon-delete.svg" />
  187. </i>
  188. <i id="screenshot">
  189. <img style="height:1.2rem;" src="./images/icon-camera.svg" />
  190. </i>
  191. </div>
  192. <div id="nav">
  193. <div>
  194. <ul class="right hide-on-med-and-down">
  195. <li>
  196. <a class='dropdown-trigger' data-target="local_saveOrOpen">
  197. <span class="translate-storage">Storage</span>
  198. <img class="left nav-icon" src="./images/local_storage.png">
  199. </a>
  200. <ul id='local_saveOrOpen' class='dropdown-content blockpy-toolbar'>
  201. <li id="button_load">
  202. <span class="translate-import">Import</span>
  203. </li>
  204. <li class="divider"></li>
  205. <li id="button_save">
  206. <span class="translate-export">Export</span>
  207. </li>
  208. </ul>
  209. <div id="fileImport" class="btn" style="display:none;">
  210. <input type="file" accept=".py">
  211. </div>
  212. <div id="xmlFileImport" class="btn" style="display:none;">
  213. <input type="file" accept=".xml">
  214. </div>
  215. </li>
  216. <li>
  217. <a id="nav_language" class='dropdown-trigger' data-target='languages'>
  218. <span class="translate-language">Language</span>
  219. <img class="left nav-icon" src="./images/language.png">
  220. </a>
  221. <ul id='languages' class='dropdown-content'>
  222. <li>
  223. <a>English</a>
  224. </li>
  225. <li class="divider"></li>
  226. <li>
  227. <a>繁体中文</a>
  228. </li>
  229. <li class="divider"></li>
  230. <li>
  231. <a>简体中文</a>
  232. </li>
  233. </ul>
  234. </li>
  235. <li><span class="vertical-separator"></span></li>
  236. <li>
  237. <a target="_blank" href="//cocorobo.cn/online/">
  238. <img class="nav-icon" src="./images/home_icon.png" />
  239. </a>
  240. </li>
  241. </ul>
  242. </div>
  243. </div>
  244. </div>
  245. </nav>
  246. <div>
  247. <div style="height:100%;" id="blockpy-div"></div>
  248. <ul id="icon-tool">
  249. <li class="card-icon active" onclick="">
  250. <i class="material-icons media">build</i>
  251. </li>
  252. <li id="file-tool" class="card-icon">
  253. <i class="material-icons media">folder</i>
  254. </li>
  255. <li id="lang-tool" class="card-icon">
  256. <i class="material-icons media">translate</i>
  257. </li>
  258. </ul>
  259. <div id='side-lang-trigger'>
  260. <a class='dropdown-trigger' data-target='side-lang'></a>
  261. </div>
  262. <ul id="side-lang" class='dropdown-content'>
  263. <li>
  264. <a>English</a>
  265. </li>
  266. <li class="divider"></li>
  267. <li>
  268. <a>繁体中文</a>
  269. </li>
  270. <li class="divider"></li>
  271. <li>
  272. <a>简体中文</a>
  273. </li>
  274. </ul>
  275. <div id='side-file-trigger'>
  276. <a class='dropdown-trigger' data-target="side-file"></a>
  277. </div>
  278. <ul id='side-file' class='dropdown-content blockpy-toolbar'>
  279. <li id="side_button_load">
  280. <span class="translate-import">Import</span>
  281. </li>
  282. <li class="divider"></li>
  283. <li id="side_button_save">
  284. <span class="translate-export">Export</span>
  285. </li>
  286. </ul>
  287. </div>
  288. <footer id="footer">
  289. <div>
  290. <div><span>CocoRobo LTD © 2019 </span><span class="translate-copyright">Copyright</span></div>
  291. <div><span>Coco Python Blockly v1</span></div>
  292. </div>
  293. </footer>
  294. </div>
  295. <script type="text/javascript" src="./libs/clipboard.min.js"></script>
  296. <script type="text/javascript" src="./index.js"></script>
  297. <script>
  298. function getQueryParams() {
  299. try {
  300. url = window.location.hreaf;
  301. query_str = url.substr(url.indexOf("?") + 1, url.length - 1);
  302. r_params = query_str.split("&");
  303. params = {};
  304. for (i in r_params) {
  305. param = r_params[i].split("=");
  306. params[param[0]] = param[1];
  307. }
  308. return params;
  309. } catch (e) {
  310. return {};
  311. }
  312. }
  313. </script>
  314. <script>
  315. document.addEventListener('DOMContentLoaded', function() {
  316. var elems = document.querySelectorAll('.aiymodal');
  317. var instances = M.Modal.init(elems, options);
  318. });
  319. document.addEventListener('DOMContentLoaded', function() {
  320. var elems = document.querySelectorAll('.tooltipped');
  321. var instances = M.Tooltip.init(elems, options);
  322. });
  323. var aiySocket = new WebSocket("ws://localhost:8089");
  324. aiySocket.onopen = function(event) {
  325. aiySocket.send("hello");
  326. };
  327. aiySocket.onmessage = function(event) {
  328. console.log(event.data);
  329. dataReceived = event.data;
  330. }
  331. function functionSSH() {
  332. aiySocket.send("ls");
  333. // document.getElementsByClassName("CodeMirror").value;
  334. aiySocket.send("scp ~/Downloads/python-blockly.py pi@" + document.getElementById("aiyip_input").value + ":/home/pi/python-blockly.py");
  335. aiySocket.send("ssh -t pi@" + document.getElementById("aiyip_input").value + " 'python3 /home/pi/python-blockly.py'");
  336. }
  337. </script>
  338. </body>
  339. </html>