diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..06bb031
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/markdown-navigator-enh.xml b/.idea/markdown-navigator-enh.xml
new file mode 100644
index 0000000..12fb99d
--- /dev/null
+++ b/.idea/markdown-navigator-enh.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml
new file mode 100644
index 0000000..d6df267
--- /dev/null
+++ b/.idea/markdown-navigator.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index fe49fed..6874d64 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,11 +4,11 @@
+
-
+
-
@@ -43,13 +43,18 @@
+
+
+
+
+
-
+
@@ -67,19 +72,13 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -104,6 +103,8 @@
+
+
@@ -111,8 +112,9 @@
+
+
-
@@ -170,6 +172,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
1564063805490
@@ -201,6 +215,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dist/block_mirror.js b/dist/block_mirror.js
index 5c90249..12c93f8 100644
--- a/dist/block_mirror.js
+++ b/dist/block_mirror.js
@@ -172,14 +172,14 @@ Blockly.Variables.flyoutCategoryBlocks = function (workspace) {
function BlockMirror(configuration) {
this.validateConfiguration(configuration);
this.initializeVariables();
- this.textEditor = new BlockMirrorTextEditor(this);
- this.blockEditor = new BlockMirrorBlockEditor(this);
- this.textToBlocks = new BlockMirrorTextToBlocks(this);
if (!this.configuration.skipSkulpt) {
this.loadSkulpt();
}
+ this.textToBlocks = new BlockMirrorTextToBlocks(this);
+ this.textEditor = new BlockMirrorTextEditor(this);
+ this.blockEditor = new BlockMirrorBlockEditor(this);
this.setMode(this.configuration.viewMode);
}
@@ -725,12 +725,45 @@ BlockMirrorBlockEditor.prototype.resized = function (e) {
this.resizeReadOnlyDiv();
};
+BlockMirrorBlockEditor.prototype.toolboxPythonToBlocks = function (toolboxPython) {
+ var _this4 = this;
+
+ return toolboxPython.map(function (category) {
+ if (typeof category === "string") {
+ return category;
+ }
+
+ var colour = BlockMirrorTextToBlocks.COLOR[category.colour];
+ var header = "");
+ } else {
+ header += ">";
+ }
+
+ var body = (category.blocks || []).map(function (code) {
+ var result = _this4.blockMirror.textToBlocks.convertSource('toolbox.py', code);
+
+ return result.rawXml.innerHTML.toString();
+ }).join("\n");
+ var footer = "";
+ return [header, body, footer].join("\n");
+ }).join("\n");
+};
+
BlockMirrorBlockEditor.prototype.makeToolbox = function () {
- var toolbox = this.blockMirror.configuration.toolbox;
+ var toolbox = this.blockMirror.configuration.toolbox; // Use palette if it exists, otherwise assume its a custom one.
if (toolbox in this.TOOLBOXES) {
toolbox = this.TOOLBOXES[toolbox];
- }
+ } // Convert if necessary
+
+
+ if (typeof toolbox !== "string") {
+ toolbox = this.toolboxPythonToBlocks(toolbox);
+ } // TODO: Fix Hack, this should be configurable by instance rather than by class
+
for (var name in BlockMirrorBlockEditor.EXTRA_TOOLS) {
toolbox += BlockMirrorBlockEditor.EXTRA_TOOLS[name];
@@ -1025,7 +1058,8 @@ BlockMirrorTextToBlocks.prototype.convertSource = function (filename, python_sou
if (python_source.trim() === "") {
return {
"xml": BlockMirrorTextToBlocks.xmlToString(xml),
- "error": null
+ "error": null,
+ rawXml: xml
};
}
@@ -1045,7 +1079,8 @@ BlockMirrorTextToBlocks.prototype.convertSource = function (filename, python_sou
xml.appendChild(BlockMirrorTextToBlocks.raw_block(originalSource));
return {
"xml": BlockMirrorTextToBlocks.xmlToString(xml),
- "error": error
+ "error": error,
+ "rawXml": xml
};
}
}
@@ -1079,7 +1114,8 @@ BlockMirrorTextToBlocks.prototype.convertSource = function (filename, python_sou
"xml": BlockMirrorTextToBlocks.xmlToString(xml),
"error": null,
"lineMap": this.lineMap,
- 'comments': this.comments
+ 'comments': this.comments,
+ "rawXml": xml
};
};
@@ -1091,7 +1127,7 @@ BlockMirrorTextToBlocks.prototype.recursiveMeasure = function (node, nextBlockLi
var myNext = nextBlockLine;
if ("orelse" in node && node.orelse.length > 0) {
- if (node.orelse.length == 1 && node.orelse[0]._astname == "If") {
+ if (node.orelse.length === 1 && node.orelse[0]._astname === "If") {
myNext = node.orelse[0].lineno - 1;
} else {
myNext = node.orelse[0].lineno - 1 - 1;
@@ -2380,30 +2416,150 @@ var ZERO_BLOCK = BlockMirrorTextToBlocks.create_block('ast_Num', null, {
'NUM': 0
});
BlockMirrorBlockEditor.EXTRA_TOOLS = {};
-
-BlockMirrorBlockEditor.getDefaultBlocks = function () {
- return "\n \n \n \n \n \n \n \n \n \n \n \n \n \n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("round"), "\n \n \n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("print"), "\n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("plot", {}, "plt"), "\n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("scatter", {}, "plt"), "\n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("hist", {}, "plt"), "\n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("show", {}, "plt"), "\n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("title", {}, "plt"), "\n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("xlabel", {}, "plt"), "\n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("ylabel", {}, "plt"), "\n \n \n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("input"), "\n \n \n \n \n \n \n \n \n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("int"), "\n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("float"), "\n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("str"), "\n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("bool"), "\n \n \n \n 0\n 0\n 0\n \n \n \n \n \n \n \n ").concat(BlockMirrorTextToBlocks.getFunctionBlock(".append"), "\n ").concat(BlockMirrorTextToBlocks.getFunctionBlock("range", {
- 'ARG0': ZERO_BLOCK
- }), "\n \n \n \n \n \n 1st key\n \n \n 2nd key\n \n \n 3rd key\n \n \n \n \n key\n \n \n ");
+var TOOLBOX_CATEGORY = {};
+TOOLBOX_CATEGORY.VARIABLES = {
+ name: 'Variables',
+ colour: 'VARIABLES',
+ custom: 'VARIABLE'
+};
+TOOLBOX_CATEGORY.DECISIONS = {
+ name: "Decisions",
+ colour: "LOGIC",
+ blocks: ['if ___: pass', 'if ___: pass\nelse: pass', '___ < ___', '___ and ___', 'not ___']
+};
+TOOLBOX_CATEGORY.CALCULATIONS = {
+ name: "Calculation",
+ colour: "MATH",
+ blocks: ["___ + ___", "round(___)"]
+};
+TOOLBOX_CATEGORY.OUTPUT_WITH_PLOTTING = {
+ name: "Output",
+ colour: "PLOTTING",
+ blocks: ["print(___)", "plt.plot(___)", "plt.scatter(___, ___)", "plt.hist(___)", "plt.show()", "plt.title(___)", "plt.xlabel(___)", "plt.ylabel(___)"]
+};
+TOOLBOX_CATEGORY.TURTLES = {
+ name: "Turtles",
+ colour: "PLOTTING",
+ blocks: ["turtle.mainloop()", "turtle.forward(50)", "turtle.backward(50)", "turtle.right(90)", "turtle.left(90)", "turtle.goto(0, 0)", "turtle.setx(100)", "turtle.sety(100)", "turtle.setheading(270)", "turtle.pendown()", "turtle.penup()", "turtle.pencolor('blue')"]
+};
+TOOLBOX_CATEGORY.INPUT = {
+ name: "Input",
+ colour: "TEXT",
+ blocks: ["input(___)"]
+};
+TOOLBOX_CATEGORY.VALUES = {
+ name: "Values",
+ colour: "TEXT",
+ blocks: ['""', "0", "True"]
+};
+TOOLBOX_CATEGORY.SEP = "";
+TOOLBOX_CATEGORY.CONVERSIONS = {
+ name: "Conversion",
+ colour: "TEXT",
+ blocks: ["int(___)", "float(___)", "str(___)", "bool(___)"]
+};
+TOOLBOX_CATEGORY.DICTIONARIES = {
+ name: "Dictionaries",
+ colour: "DICTIONARY",
+ blocks: ["{'1st key': ___, '2nd key': ___, '3rd key': ___}", "{}", "___['key']"]
};
-
BlockMirrorBlockEditor.prototype.TOOLBOXES = {
- 'normal': BlockMirrorBlockEditor.getDefaultBlocks()
-}; // TODO: fix these to be more interesting
-
-BlockMirrorBlockEditor.prototype.TOOLBOXES['minimal'] = BlockMirrorBlockEditor.prototype.TOOLBOXES['normal'];
-BlockMirrorBlockEditor.prototype.TOOLBOXES['full'] = BlockMirrorBlockEditor.prototype.TOOLBOXES['normal'];
-/*
-xml += '' +
-
- '' +
- '';
-xml += '' +
- '' +
- '';
-//xml += '';
-xml += '';*/
+ //******************************************************
+ 'minimal': [// TODO: What should live in here?
+ TOOLBOX_CATEGORY.VARIABLES],
+ //******************************************************
+ 'normal': [TOOLBOX_CATEGORY.VARIABLES, TOOLBOX_CATEGORY.DECISIONS, {
+ name: "Iteration",
+ colour: "CONTROL",
+ blocks: ['for ___ in ___: pass', 'while ___: pass', 'break']
+ }, {
+ name: "Functions",
+ colour: "FUNCTIONS",
+ blocks: ["def ___(___): pass", "def ___(___: int)->str: pass", "return ___"]
+ }, TOOLBOX_CATEGORY.SEP, TOOLBOX_CATEGORY.CALCULATIONS, TOOLBOX_CATEGORY.OUTPUT_WITH_PLOTTING, TOOLBOX_CATEGORY.INPUT, TOOLBOX_CATEGORY.TURTLES, TOOLBOX_CATEGORY.SEP, TOOLBOX_CATEGORY.VALUES, TOOLBOX_CATEGORY.CONVERSIONS, {
+ name: "Lists",
+ colour: "LIST",
+ blocks: ["[0, 0, 0]", "[___, ___, ___]", "[]", "___.append(___)", "range(0, 10)"]
+ }, TOOLBOX_CATEGORY.DICTIONARIES],
+ //******************************************************
+ 'ct': [TOOLBOX_CATEGORY.VARIABLES, TOOLBOX_CATEGORY.DECISIONS, {
+ name: "Iteration",
+ colour: "CONTROL",
+ blocks: ['for ___ in ___: pass']
+ }, TOOLBOX_CATEGORY.SEP, TOOLBOX_CATEGORY.CALCULATIONS, TOOLBOX_CATEGORY.OUTPUT_WITH_PLOTTING, TOOLBOX_CATEGORY.INPUT, TOOLBOX_CATEGORY.SEP, TOOLBOX_CATEGORY.VALUES, TOOLBOX_CATEGORY.CONVERSIONS, {
+ name: "Lists",
+ colour: "LIST",
+ blocks: ["[0, 0, 0]", "[___, ___, ___]", "[]", "___.append(___)"]
+ }],
+ //******************************************************
+ 'full': [TOOLBOX_CATEGORY.VARIABLES, {
+ name: "Literal Values",
+ colour: "LIST",
+ blocks: ["0", "''", "True", "None", "[___, ___, ___]", "(___, ___, ___)", "{___, ___, ___}", "{___: ___, ___: ___, ___: ___}"]
+ }, {
+ name: "Calculations",
+ colour: "MATH",
+ blocks: ["-___", "___ + ___", "___ >> ___", "abs(___)", "round(___)"]
+ }, {
+ name: "Logic",
+ colour: "LOGIC",
+ blocks: ['___ if ___ else ___', '___ == ___', '___ < ___', '___ in ___', '___ and ___', 'not ___']
+ }, TOOLBOX_CATEGORY.SEP, {
+ name: "Classes",
+ colour: "OO",
+ blocks: ["class ___: pass", "class ___(___): pass", "___.___", "___: ___", "super()"]
+ }, {
+ name: "Functions",
+ colour: "FUNCTIONS",
+ blocks: ["def ___(___): pass", "def ___(___: int)->str: pass", "return ___", "yield ___", "lambda ___: ___"]
+ }, {
+ name: "Imports",
+ colour: "PYTHON",
+ blocks: ["import ___", "from ___ import ___", "import ___ as ___", "from ___ import ___ as ___"]
+ }, TOOLBOX_CATEGORY.SEP, {
+ name: "Control Flow",
+ colour: "CONTROL",
+ blocks: ['if ___: pass', 'if ___: pass\nelse: pass', 'for ___ in ___: pass', 'while ___: pass', 'break', 'continue', 'try: pass\nexcept ___ as ___: pass', 'raise ___', 'assert ___', 'with ___ as ___: pass']
+ }, TOOLBOX_CATEGORY.SEP, TOOLBOX_CATEGORY.OUTPUT_WITH_PLOTTING, TOOLBOX_CATEGORY.INPUT, {
+ name: "Files",
+ colour: "FILE",
+ blocks: ["with open('', 'r') as ___: pass", "___.read()", "___.readlines()", "___.write(___)", "___.writelines(___)"]
+ }, TOOLBOX_CATEGORY.SEP, {
+ name: "Conversion",
+ colour: "TEXT",
+ blocks: ["int(___)", "float(___)", "str(___)", "chr(___)", "bool(___)", "list(___)", "dict(___)", "tuple(___)", "set(___)", "type(___)", "isinstance(___)"]
+ }, {
+ name: "Builtin Functions",
+ colour: "SEQUENCES",
+ blocks: ["len(___)", "sorted(___)", "enumerate(___)", "reversed(___)", "range(0, 10)", "min(___, ___)", "max(___, ___)", "sum(___)", "all(___)", "any(___)", "zip(___, ___)", "map(___, ___)", "filter(___, ___)"]
+ }, {
+ name: "List Methods",
+ colour: "LIST",
+ blocks: ["___.append(___)", "___.pop()", "___.clear()"]
+ }, {
+ name: "String Methods",
+ colour: "TEXT",
+ blocks: ["___.startswith('')", "___.endswith('')", "___.replace('', '')", "___.lower('')", "___.upper('')", "___.title('')", "___.strip('')", "___.split('')", "''.join(___)", "___.format('')", "___.strip('')"]
+ }, {
+ name: "Subscripting",
+ colour: "SEQUENCES",
+ blocks: ["___[___]", "___[___:___]", "___[___:___:___]"]
+ }, {
+ name: "Generators",
+ colour: "SEQUENCES",
+ blocks: ["[___ for ___ in ___]", "(___ for ___ in ___)", "{___ for ___ in ___}", "{___: ___ for ___ in ___ if ___}", "[___ for ___ in ___ if ___]", "(___ for ___ in ___ if ___)", "{___ for ___ in ___ if ___}", "{___: ___ for ___ in ___ if ___}"]
+ }, {
+ name: "Comments",
+ colour: "PYTHON",
+ blocks: ["# ", '"""\n"""']
+ /*,
+ {name: "Weird Stuff", colour: "PYTHON", blocks: [
+ "delete ___",
+ "global ___"
+ ]}*/
+ }]
+};
BlockMirrorTextToBlocks.BLOCKS.push({
"type": "ast_For",
"message0": "for each item %1 in list %2 : %3 %4",
diff --git a/src/block_editor.js b/src/block_editor.js
index f344bfa..06bbe8d 100644
--- a/src/block_editor.js
+++ b/src/block_editor.js
@@ -112,11 +112,38 @@ BlockMirrorBlockEditor.prototype.resized = function (e) {
this.resizeReadOnlyDiv();
};
+BlockMirrorBlockEditor.prototype.toolboxPythonToBlocks = function (toolboxPython) {
+ return toolboxPython.map((category) => {
+ if (typeof category === "string") {
+ return category;
+ }
+ let colour = BlockMirrorTextToBlocks.COLOR[category.colour];
+ let header = ``;
+ } else {
+ header += ">";
+ }
+ let body = (category.blocks || []).map((code) => {
+ let result = this.blockMirror.textToBlocks.convertSource('toolbox.py', code);
+ return result.rawXml.innerHTML.toString();
+ }).join("\n");
+ let footer = "";
+ return [header, body, footer].join("\n");
+ }).join("\n");
+};
+
BlockMirrorBlockEditor.prototype.makeToolbox = function () {
let toolbox = this.blockMirror.configuration.toolbox;
+ // Use palette if it exists, otherwise assume its a custom one.
if (toolbox in this.TOOLBOXES) {
toolbox = this.TOOLBOXES[toolbox];
}
+ // Convert if necessary
+ if (typeof toolbox !== "string") {
+ toolbox = this.toolboxPythonToBlocks(toolbox);
+ }
+ // TODO: Fix Hack, this should be configurable by instance rather than by class
for (let name in BlockMirrorBlockEditor.EXTRA_TOOLS) {
toolbox += BlockMirrorBlockEditor.EXTRA_TOOLS[name];
}
diff --git a/src/block_mirror.js b/src/block_mirror.js
index 4bae3bc..46d488d 100644
--- a/src/block_mirror.js
+++ b/src/block_mirror.js
@@ -32,14 +32,15 @@
function BlockMirror(configuration) {
this.validateConfiguration(configuration);
this.initializeVariables();
- this.textEditor = new BlockMirrorTextEditor(this);
- this.blockEditor = new BlockMirrorBlockEditor(this);
- this.textToBlocks = new BlockMirrorTextToBlocks(this);
if (!this.configuration.skipSkulpt) {
this.loadSkulpt();
}
+ this.textToBlocks = new BlockMirrorTextToBlocks(this);
+ this.textEditor = new BlockMirrorTextEditor(this);
+ this.blockEditor = new BlockMirrorBlockEditor(this);
+
this.setMode(this.configuration.viewMode);
};
diff --git a/src/text_to_blocks.js b/src/text_to_blocks.js
index d36550d..f74be7d 100644
--- a/src/text_to_blocks.js
+++ b/src/text_to_blocks.js
@@ -35,7 +35,7 @@ BlockMirrorTextToBlocks.prototype.convertSource = function (filename, python_sou
let previousLine = 1+this.source.length;
while (ast === null) {
if (python_source.trim() === "") {
- return {"xml": BlockMirrorTextToBlocks.xmlToString(xml), "error": null};
+ return {"xml": BlockMirrorTextToBlocks.xmlToString(xml), "error": null, rawXml: xml};
}
try {
parse = Sk.parse(filename, python_source);
@@ -51,7 +51,7 @@ BlockMirrorTextToBlocks.prototype.convertSource = function (filename, python_sou
} else {
//console.error(e);
xml.appendChild(BlockMirrorTextToBlocks.raw_block(originalSource));
- return {"xml": BlockMirrorTextToBlocks.xmlToString(xml), "error": error};
+ return {"xml": BlockMirrorTextToBlocks.xmlToString(xml), "error": error, "rawXml": xml};
}
}
}
@@ -75,10 +75,13 @@ BlockMirrorTextToBlocks.prototype.convertSource = function (filename, python_sou
xml.appendChild(BlockMirrorTextToBlocks.raw_block(badChunks.join("\n")));
}
return {
- "xml": BlockMirrorTextToBlocks.xmlToString(xml), "error": null,
- "lineMap": this.lineMap, 'comments': this.comments
+ "xml": BlockMirrorTextToBlocks.xmlToString(xml),
+ "error": null,
+ "lineMap": this.lineMap,
+ 'comments': this.comments,
+ "rawXml": xml
};
-}
+};
BlockMirrorTextToBlocks.prototype.recursiveMeasure = function (node, nextBlockLine) {
if (node === undefined) {
@@ -86,7 +89,7 @@ BlockMirrorTextToBlocks.prototype.recursiveMeasure = function (node, nextBlockLi
}
var myNext = nextBlockLine;
if ("orelse" in node && node.orelse.length > 0) {
- if (node.orelse.length == 1 && node.orelse[0]._astname == "If") {
+ if (node.orelse.length === 1 && node.orelse[0]._astname === "If") {
myNext = node.orelse[0].lineno - 1;
} else {
myNext = node.orelse[0].lineno - 1 - 1;
diff --git a/src/toolbars.js b/src/toolbars.js
index 6583777..1e3b947 100644
--- a/src/toolbars.js
+++ b/src/toolbars.js
@@ -2,99 +2,266 @@ let ZERO_BLOCK = BlockMirrorTextToBlocks.create_block('ast_Num', null, {'NUM': 0
BlockMirrorBlockEditor.EXTRA_TOOLS = {};
-BlockMirrorBlockEditor.getDefaultBlocks = function () {
- return `
-
-
-
-
-
-
-
-
-
-
-
-
-
- ${BlockMirrorTextToBlocks.getFunctionBlock("round")}
-
-
- ${BlockMirrorTextToBlocks.getFunctionBlock("print")}
- ${BlockMirrorTextToBlocks.getFunctionBlock("plot", {}, "plt")}
- ${BlockMirrorTextToBlocks.getFunctionBlock("scatter", {}, "plt")}
- ${BlockMirrorTextToBlocks.getFunctionBlock("hist", {}, "plt")}
- ${BlockMirrorTextToBlocks.getFunctionBlock("show", {}, "plt")}
- ${BlockMirrorTextToBlocks.getFunctionBlock("title", {}, "plt")}
- ${BlockMirrorTextToBlocks.getFunctionBlock("xlabel", {}, "plt")}
- ${BlockMirrorTextToBlocks.getFunctionBlock("ylabel", {}, "plt")}
-
-
- ${BlockMirrorTextToBlocks.getFunctionBlock("input")}
-
-
-
-
-
-
-
-
- ${BlockMirrorTextToBlocks.getFunctionBlock("int")}
- ${BlockMirrorTextToBlocks.getFunctionBlock("float")}
- ${BlockMirrorTextToBlocks.getFunctionBlock("str")}
- ${BlockMirrorTextToBlocks.getFunctionBlock("bool")}
-
-
-
- 0
- 0
- 0
-
-
-
-
-
-
-
- ${BlockMirrorTextToBlocks.getFunctionBlock(".append")}
- ${BlockMirrorTextToBlocks.getFunctionBlock("range", {'ARG0': ZERO_BLOCK})}
-
-
-
-
-
- 1st key
-
-
- 2nd key
-
-
- 3rd key
-
-
-
-
- key
-
-
- `;
-}
+const TOOLBOX_CATEGORY = {};
-BlockMirrorBlockEditor.prototype.TOOLBOXES = {
- 'normal': BlockMirrorBlockEditor.getDefaultBlocks(),
-};
+TOOLBOX_CATEGORY.VARIABLES = {name: 'Variables', colour: 'VARIABLES', custom: 'VARIABLE'};
+TOOLBOX_CATEGORY.DECISIONS = {name: "Decisions", colour: "LOGIC", blocks: [
+ 'if ___: pass',
+ 'if ___: pass\nelse: pass',
+ '___ < ___',
+ '___ and ___',
+ 'not ___'
+]};
+TOOLBOX_CATEGORY.CALCULATIONS = {name: "Calculation", colour: "MATH", blocks: [
+ "___ + ___",
+ "round(___)"
+]};
+TOOLBOX_CATEGORY.OUTPUT_WITH_PLOTTING = {name: "Output", colour: "PLOTTING", blocks: [
+ "print(___)",
+ "plt.plot(___)",
+ "plt.scatter(___, ___)",
+ "plt.hist(___)",
+ "plt.show()",
+ "plt.title(___)",
+ "plt.xlabel(___)",
+ "plt.ylabel(___)"
+]};
+TOOLBOX_CATEGORY.TURTLES = {name: "Turtles", colour: "PLOTTING", blocks: [
+ "turtle.mainloop()",
+ "turtle.forward(50)",
+ "turtle.backward(50)",
+ "turtle.right(90)",
+ "turtle.left(90)",
+ "turtle.goto(0, 0)",
+ "turtle.setx(100)",
+ "turtle.sety(100)",
+ "turtle.setheading(270)",
+ "turtle.pendown()",
+ "turtle.penup()",
+ "turtle.pencolor('blue')"
+]};
+TOOLBOX_CATEGORY.INPUT = {name: "Input", colour: "TEXT", blocks: [
+ "input(___)",
+]};
+TOOLBOX_CATEGORY.VALUES = {name: "Values", colour: "TEXT", blocks: [
+ '""',
+ "0",
+ "True"
+]};
+TOOLBOX_CATEGORY.SEP = "";
-// TODO: fix these to be more interesting
-BlockMirrorBlockEditor.prototype.TOOLBOXES['minimal'] = BlockMirrorBlockEditor.prototype.TOOLBOXES['normal'];
-BlockMirrorBlockEditor.prototype.TOOLBOXES['full'] = BlockMirrorBlockEditor.prototype.TOOLBOXES['normal'];
+TOOLBOX_CATEGORY.CONVERSIONS = {name: "Conversion", colour: "TEXT", blocks: [
+ "int(___)",
+ "float(___)",
+ "str(___)",
+ "bool(___)"
+]};
-/*
-xml += '' +
+TOOLBOX_CATEGORY.DICTIONARIES = {name: "Dictionaries", colour: "DICTIONARY", blocks: [
+ "{'1st key': ___, '2nd key': ___, '3rd key': ___}",
+ "{}",
+ "___['key']"
+]};
- '' +
- '';
-xml += '' +
- '' +
- '';
-//xml += '';
-xml += '';*/
\ No newline at end of file
+BlockMirrorBlockEditor.prototype.TOOLBOXES = {
+ //******************************************************
+ 'minimal': [
+ // TODO: What should live in here?
+ TOOLBOX_CATEGORY.VARIABLES,
+ ],
+ //******************************************************
+ 'normal': [
+ TOOLBOX_CATEGORY.VARIABLES,
+ TOOLBOX_CATEGORY.DECISIONS,
+ {name: "Iteration", colour: "CONTROL", blocks: [
+ 'for ___ in ___: pass',
+ 'while ___: pass',
+ 'break',
+ ]},
+ {name: "Functions", colour: "FUNCTIONS", blocks: [
+ "def ___(___): pass",
+ "def ___(___: int)->str: pass",
+ "return ___",
+ ]},
+ TOOLBOX_CATEGORY.SEP,
+ TOOLBOX_CATEGORY.CALCULATIONS,
+ TOOLBOX_CATEGORY.OUTPUT_WITH_PLOTTING,
+ TOOLBOX_CATEGORY.INPUT,
+ TOOLBOX_CATEGORY.TURTLES,
+ TOOLBOX_CATEGORY.SEP,
+ TOOLBOX_CATEGORY.VALUES,
+ TOOLBOX_CATEGORY.CONVERSIONS,
+ {name: "Lists", colour: "LIST", blocks: [
+ "[0, 0, 0]",
+ "[___, ___, ___]",
+ "[]",
+ "___.append(___)",
+ "range(0, 10)"
+ ]},
+ TOOLBOX_CATEGORY.DICTIONARIES
+ ],
+ //******************************************************
+ 'ct': [
+ TOOLBOX_CATEGORY.VARIABLES,
+ TOOLBOX_CATEGORY.DECISIONS,
+ {name: "Iteration", colour: "CONTROL", blocks: [
+ 'for ___ in ___: pass',
+ ]},
+ TOOLBOX_CATEGORY.SEP,
+ TOOLBOX_CATEGORY.CALCULATIONS,
+ TOOLBOX_CATEGORY.OUTPUT_WITH_PLOTTING,
+ TOOLBOX_CATEGORY.INPUT,
+ TOOLBOX_CATEGORY.SEP,
+ TOOLBOX_CATEGORY.VALUES,
+ TOOLBOX_CATEGORY.CONVERSIONS,
+ {name: "Lists", colour: "LIST", blocks: [
+ "[0, 0, 0]",
+ "[___, ___, ___]",
+ "[]",
+ "___.append(___)"
+ ]}
+ ],
+ //******************************************************
+ 'full': [
+ TOOLBOX_CATEGORY.VARIABLES,
+ {name: "Literal Values", colour: "LIST", blocks: [
+ "0",
+ "''",
+ "True",
+ "None",
+ "[___, ___, ___]",
+ "(___, ___, ___)",
+ "{___, ___, ___}",
+ "{___: ___, ___: ___, ___: ___}",
+ ]},
+ {name: "Calculations", colour: "MATH", blocks: [
+ "-___",
+ "___ + ___",
+ "___ >> ___",
+ "abs(___)",
+ "round(___)",
+ ]},
+ {name: "Logic", colour: "LOGIC", blocks: [
+ '___ if ___ else ___',
+ '___ == ___',
+ '___ < ___',
+ '___ in ___',
+ '___ and ___',
+ 'not ___'
+ ]},
+ TOOLBOX_CATEGORY.SEP,
+ {name: "Classes", colour: "OO", blocks: [
+ "class ___: pass",
+ "class ___(___): pass",
+ "___.___",
+ "___: ___",
+ "super()"
+ ]},
+ {name: "Functions", colour: "FUNCTIONS", blocks: [
+ "def ___(___): pass",
+ "def ___(___: int)->str: pass",
+ "return ___",
+ "yield ___",
+ "lambda ___: ___"
+ ]},
+ {name: "Imports", colour: "PYTHON", blocks: [
+ "import ___",
+ "from ___ import ___",
+ "import ___ as ___",
+ "from ___ import ___ as ___"
+ ]},
+ TOOLBOX_CATEGORY.SEP,
+ {name: "Control Flow", colour: "CONTROL", blocks: [
+ 'if ___: pass',
+ 'if ___: pass\nelse: pass',
+ 'for ___ in ___: pass',
+ 'while ___: pass',
+ 'break',
+ 'continue',
+ 'try: pass\nexcept ___ as ___: pass',
+ 'raise ___',
+ 'assert ___',
+ 'with ___ as ___: pass'
+ ]},
+ TOOLBOX_CATEGORY.SEP,
+ TOOLBOX_CATEGORY.OUTPUT_WITH_PLOTTING,
+ TOOLBOX_CATEGORY.INPUT,
+ {name: "Files", colour: "FILE", blocks: [
+ "with open('', 'r') as ___: pass",
+ "___.read()",
+ "___.readlines()",
+ "___.write(___)",
+ "___.writelines(___)"
+ ]},
+ TOOLBOX_CATEGORY.SEP,
+ {name: "Conversion", colour: "TEXT", blocks: [
+ "int(___)",
+ "float(___)",
+ "str(___)",
+ "chr(___)",
+ "bool(___)",
+ "list(___)",
+ "dict(___)",
+ "tuple(___)",
+ "set(___)",
+ "type(___)",
+ "isinstance(___)"
+ ]},
+ {name: "Builtin Functions", colour: "SEQUENCES", blocks: [
+ "len(___)",
+ "sorted(___)",
+ "enumerate(___)",
+ "reversed(___)",
+ "range(0, 10)",
+ "min(___, ___)",
+ "max(___, ___)",
+ "sum(___)",
+ "all(___)",
+ "any(___)",
+ "zip(___, ___)",
+ "map(___, ___)",
+ "filter(___, ___)",
+ ]},
+ {name: "List Methods", colour: "LIST", blocks: [
+ "___.append(___)",
+ "___.pop()",
+ "___.clear()",
+ ]},
+ {name: "String Methods", colour: "TEXT", blocks: [
+ "___.startswith('')",
+ "___.endswith('')",
+ "___.replace('', '')",
+ "___.lower('')",
+ "___.upper('')",
+ "___.title('')",
+ "___.strip('')",
+ "___.split('')",
+ "''.join(___)",
+ "___.format('')",
+ "___.strip('')",
+ ]},
+ {name: "Subscripting", colour: "SEQUENCES", blocks: [
+ "___[___]",
+ "___[___:___]",
+ "___[___:___:___]"
+ ]},
+ {name: "Generators", colour: "SEQUENCES", blocks: [
+ "[___ for ___ in ___]",
+ "(___ for ___ in ___)",
+ "{___ for ___ in ___}",
+ "{___: ___ for ___ in ___ if ___}",
+ "[___ for ___ in ___ if ___]",
+ "(___ for ___ in ___ if ___)",
+ "{___ for ___ in ___ if ___}",
+ "{___: ___ for ___ in ___ if ___}"
+ ]},
+ {name: "Comments", colour: "PYTHON", blocks: [
+ "# ",
+ '"""\n"""'
+ ]}/*,
+ {name: "Weird Stuff", colour: "PYTHON", blocks: [
+ "delete ___",
+ "global ___"
+ ]}*/
+ ],
+};