From c0ae589c9b80ead5b75c995c164f468ab88a7d45 Mon Sep 17 00:00:00 2001 From: angelasofiaremolinagutierrez Date: Wed, 9 Jun 2021 22:59:23 -0500 Subject: [PATCH 1/7] Add the html elements needed for brython --- runestone/activecode/js/activecode_brython.js | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 runestone/activecode/js/activecode_brython.js diff --git a/runestone/activecode/js/activecode_brython.js b/runestone/activecode/js/activecode_brython.js new file mode 100644 index 000000000..d7ae7fb4a --- /dev/null +++ b/runestone/activecode/js/activecode_brython.js @@ -0,0 +1,58 @@ +import { ActiveCode } from "./activecode.js"; + +export default class BrythonActiveCode extends ActiveCode { + constructor(opts) { + super(opts); + opts.alignVertical = true; + this.code = $(" @@ -162,6 +162,7 @@ class ActiveCode(RunestoneIdDirective): :nopair: -- disable pair programming features :dburl: url to load database for sql mode :showlastsql: -- Only show the last sql result in output + :python3_interpreter: brython (uses brython as interpreter of python3) If this is a homework problem instead of an example in the text then the assignment text should go here. The assignment text ends with @@ -217,6 +218,7 @@ class ActiveCode(RunestoneIdDirective): "nopair": directives.flag, "dburl": directives.unchanged, "showlastsql": directives.flag, + "python3_interpreter": directives.unchanged } ) @@ -393,6 +395,11 @@ def run(self): else: self.options["wasmuri"] = "" + if ("python3_interpreter" in self.options): #and (self.options["language"]=="python3") : + self.options["python3_interpreter"] = "data-python3_interpreter='{}'".format(self.options["python3_interpreter"]) + else: + self.options["python3_interpreter"] = "" + if self.content: if "^^^^" in self.content: idx = self.content.index("^^^^") diff --git a/runestone/activecode/js/acfactory.js b/runestone/activecode/js/acfactory.js index b064754d8..a3b464f03 100644 --- a/runestone/activecode/js/acfactory.js +++ b/runestone/activecode/js/acfactory.js @@ -2,6 +2,7 @@ import { ActiveCode } from "./activecode.js"; import JSActiveCode from "./activecode_js.js"; import HTMLActiveCode from "./activecode_html.js"; import SQLActiveCode from "./activecode_sql.js"; +import BrythonActiveCode from "./activecode_brython.js"; import LiveCode from "./livecode.js"; import { TimedActiveCode, @@ -9,6 +10,7 @@ import { TimedJSActiveCode, TimedHTMLActiveCode, TimedSQLActiveCode, + TimedBrythonActiveCode } from "./timed_activecode"; import "../../common/js/jquery.highlight.js"; @@ -30,7 +32,11 @@ export default class ACFactory { if (lang === undefined) { lang = $(opts.orig).find("[data-lang]").data("lang"); } + var python3_interpreter = $(opts.orig).data("python3_interpreter"); if (opts.timed == true) { + if(python3_interpreter==="brython"){ + return new TimedBrythonActiveCode(opts); + } if (lang === "python") { return new TimedActiveCode(opts); } else if ( @@ -50,6 +56,9 @@ export default class ACFactory { return new TimedActiveCode(opts); } } else { + if(python3_interpreter==="brython"){ + return new BrythonActiveCode(opts); + } if (lang === "javascript") { return new JSActiveCode(opts); } else if (lang === "htmlmixed") { diff --git a/runestone/activecode/js/activecode.js b/runestone/activecode/js/activecode.js index bf60c122b..db2a7584d 100755 --- a/runestone/activecode/js/activecode.js +++ b/runestone/activecode/js/activecode.js @@ -60,6 +60,7 @@ export class ActiveCode extends RunestoneBase { this.question = $(opts.orig).find(`#${this.divid}_question`)[0]; this.tie = $(orig).data("tie"); this.dburl = $(orig).data("dburl"); + this.python3_interpreter = $(orig).data("python3_interpreter"); this.runButton = null; this.enabledownload = $(orig).data("enabledownload"); this.downloadButton = null; diff --git a/runestone/activecode/js/activecode_brython.js b/runestone/activecode/js/activecode_brython.js new file mode 100644 index 000000000..2a3d2079e --- /dev/null +++ b/runestone/activecode/js/activecode_brython.js @@ -0,0 +1,59 @@ +import { ActiveCode } from "./activecode.js"; + +export default class BrythonActiveCode extends ActiveCode { + constructor(opts) { + super(opts); + opts.alignVertical = true; + //this.code = $("