diff --git a/blockly_compressed.js b/blockly_compressed.js index fd3879d2d..0e3d38ec3 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -133,26 +133,7 @@ goog.userAgent.isVersionOrHigher=function(a){return goog.userAgent.ASSUME_ANY_VE goog.userAgent.DOCUMENT_MODE=function(){var a=goog.global.document;return a&&goog.userAgent.IE?goog.userAgent.getDocumentMode_()||("CSS1Compat"==a.compatMode?parseInt(goog.userAgent.VERSION,10):5):void 0}();goog.math.Size=function(a,b){this.width=a;this.height=b};goog.math.Size.equals=function(a,b){return a==b?!0:a&&b?a.width==b.width&&a.height==b.height:!1};goog.math.Size.prototype.clone=function(){return new goog.math.Size(this.width,this.height)};goog.DEBUG&&(goog.math.Size.prototype.toString=function(){return"("+this.width+" x "+this.height+")"});goog.math.Size.prototype.getLongest=function(){return Math.max(this.width,this.height)}; goog.math.Size.prototype.getShortest=function(){return Math.min(this.width,this.height)};goog.math.Size.prototype.area=function(){return this.width*this.height};goog.math.Size.prototype.perimeter=function(){return 2*(this.width+this.height)};goog.math.Size.prototype.aspectRatio=function(){return this.width/this.height};goog.math.Size.prototype.isEmpty=function(){return!this.area()};goog.math.Size.prototype.ceil=function(){this.width=Math.ceil(this.width);this.height=Math.ceil(this.height);return this}; goog.math.Size.prototype.fitsInside=function(a){return this.width<=a.width&&this.height<=a.height};goog.math.Size.prototype.floor=function(){this.width=Math.floor(this.width);this.height=Math.floor(this.height);return this};goog.math.Size.prototype.round=function(){this.width=Math.round(this.width);this.height=Math.round(this.height);return this};goog.math.Size.prototype.scale=function(a,b){var c=goog.isNumber(b)?b:a;this.width*=a;this.height*=c;return this}; -goog.math.Size.prototype.scaleToFit=function(a){a=this.aspectRatio()>a.aspectRatio()?a.width/this.width:a.height/this.height;return this.scale(a)};goog.math.Coordinate=function(a,b){this.x=goog.isDef(a)?a:0;this.y=goog.isDef(b)?b:0};goog.math.Coordinate.prototype.clone=function(){return new goog.math.Coordinate(this.x,this.y)};goog.DEBUG&&(goog.math.Coordinate.prototype.toString=function(){return"("+this.x+", "+this.y+")"});goog.math.Coordinate.equals=function(a,b){return a==b?!0:a&&b?a.x==b.x&&a.y==b.y:!1};goog.math.Coordinate.distance=function(a,b){var c=a.x-b.x,d=a.y-b.y;return Math.sqrt(c*c+d*d)}; -goog.math.Coordinate.magnitude=function(a){return Math.sqrt(a.x*a.x+a.y*a.y)};goog.math.Coordinate.azimuth=function(a){return goog.math.angle(0,0,a.x,a.y)};goog.math.Coordinate.squaredDistance=function(a,b){var c=a.x-b.x,d=a.y-b.y;return c*c+d*d};goog.math.Coordinate.difference=function(a,b){return new goog.math.Coordinate(a.x-b.x,a.y-b.y)};goog.math.Coordinate.sum=function(a,b){return new goog.math.Coordinate(a.x+b.x,a.y+b.y)}; -goog.math.Coordinate.prototype.ceil=function(){this.x=Math.ceil(this.x);this.y=Math.ceil(this.y);return this};goog.math.Coordinate.prototype.floor=function(){this.x=Math.floor(this.x);this.y=Math.floor(this.y);return this};goog.math.Coordinate.prototype.round=function(){this.x=Math.round(this.x);this.y=Math.round(this.y);return this};goog.math.Coordinate.prototype.translate=function(a,b){a instanceof goog.math.Coordinate?(this.x+=a.x,this.y+=a.y):(this.x+=a,goog.isNumber(b)&&(this.y+=b));return this}; -goog.math.Coordinate.prototype.scale=function(a,b){var c=goog.isNumber(b)?b:a;this.x*=a;this.y*=c;return this};goog.math.Coordinate.prototype.rotateRadians=function(a,b){var c=b||new goog.math.Coordinate(0,0),d=this.x,e=this.y,f=Math.cos(a),g=Math.sin(a);this.x=(d-c.x)*f-(e-c.y)*g+c.x;this.y=(d-c.x)*g+(e-c.y)*f+c.y};goog.math.Coordinate.prototype.rotateDegrees=function(a,b){this.rotateRadians(goog.math.toRadians(a),b)};goog.math.Box=function(a,b,c,d){this.top=a;this.right=b;this.bottom=c;this.left=d};goog.math.Box.boundingBox=function(a){for(var b=new goog.math.Box(arguments[0].y,arguments[0].x,arguments[0].y,arguments[0].x),c=1;c=a.left&&b.right<=a.right&&b.top>=a.top&&b.bottom<=a.bottom:b.x>=a.left&&b.x<=a.right&&b.y>=a.top&&b.y<=a.bottom:!1};goog.math.Box.relativePositionX=function(a,b){return b.xa.right?b.x-a.right:0}; -goog.math.Box.relativePositionY=function(a,b){return b.ya.bottom?b.y-a.bottom:0};goog.math.Box.distance=function(a,b){var c=goog.math.Box.relativePositionX(a,b),d=goog.math.Box.relativePositionY(a,b);return Math.sqrt(c*c+d*d)};goog.math.Box.intersects=function(a,b){return a.left<=b.right&&b.left<=a.right&&a.top<=b.bottom&&b.top<=a.bottom};goog.math.Box.intersectsWithPadding=function(a,b,c){return a.left<=b.right+c&&b.left<=a.right+c&&a.top<=b.bottom+c&&b.top<=a.bottom+c}; -goog.math.Box.prototype.ceil=function(){this.top=Math.ceil(this.top);this.right=Math.ceil(this.right);this.bottom=Math.ceil(this.bottom);this.left=Math.ceil(this.left);return this};goog.math.Box.prototype.floor=function(){this.top=Math.floor(this.top);this.right=Math.floor(this.right);this.bottom=Math.floor(this.bottom);this.left=Math.floor(this.left);return this}; -goog.math.Box.prototype.round=function(){this.top=Math.round(this.top);this.right=Math.round(this.right);this.bottom=Math.round(this.bottom);this.left=Math.round(this.left);return this};goog.math.Box.prototype.translate=function(a,b){a instanceof goog.math.Coordinate?(this.left+=a.x,this.right+=a.x,this.top+=a.y,this.bottom+=a.y):(this.left+=a,this.right+=a,goog.isNumber(b)&&(this.top+=b,this.bottom+=b));return this}; -goog.math.Box.prototype.scale=function(a,b){var c=goog.isNumber(b)?b:a;this.left*=a;this.right*=a;this.top*=c;this.bottom*=c;return this};goog.math.Rect=function(a,b,c,d){this.left=a;this.top=b;this.width=c;this.height=d};goog.math.Rect.prototype.clone=function(){return new goog.math.Rect(this.left,this.top,this.width,this.height)};goog.math.Rect.prototype.toBox=function(){return new goog.math.Box(this.top,this.left+this.width,this.top+this.height,this.left)};goog.math.Rect.createFromBox=function(a){return new goog.math.Rect(a.left,a.top,a.right-a.left,a.bottom-a.top)}; -goog.DEBUG&&(goog.math.Rect.prototype.toString=function(){return"("+this.left+", "+this.top+" - "+this.width+"w x "+this.height+"h)"});goog.math.Rect.equals=function(a,b){return a==b?!0:a&&b?a.left==b.left&&a.width==b.width&&a.top==b.top&&a.height==b.height:!1}; -goog.math.Rect.prototype.intersection=function(a){var b=Math.max(this.left,a.left),c=Math.min(this.left+this.width,a.left+a.width);if(b<=c){var d=Math.max(this.top,a.top);a=Math.min(this.top+this.height,a.top+a.height);if(d<=a)return this.left=b,this.top=d,this.width=c-b,this.height=a-d,!0}return!1}; -goog.math.Rect.intersection=function(a,b){var c=Math.max(a.left,b.left),d=Math.min(a.left+a.width,b.left+b.width);if(c<=d){var e=Math.max(a.top,b.top),f=Math.min(a.top+a.height,b.top+b.height);if(e<=f)return new goog.math.Rect(c,e,d-c,f-e)}return null};goog.math.Rect.intersects=function(a,b){return a.left<=b.left+b.width&&b.left<=a.left+a.width&&a.top<=b.top+b.height&&b.top<=a.top+a.height};goog.math.Rect.prototype.intersects=function(a){return goog.math.Rect.intersects(this,a)}; -goog.math.Rect.difference=function(a,b){var c=goog.math.Rect.intersection(a,b);if(!c||!c.height||!c.width)return[a.clone()];var c=[],d=a.top,e=a.height,f=a.left+a.width,g=a.top+a.height,h=b.left+b.width,k=b.top+b.height;b.top>a.top&&(c.push(new goog.math.Rect(a.left,a.top,a.width,b.top-a.top)),d=b.top,e-=b.top-a.top);ka.left&&c.push(new goog.math.Rect(a.left,d,b.left-a.left,e));h=a.left+a.width&&this.top<=a.top&&this.top+this.height>=a.top+a.height:a.x>=this.left&&a.x<=this.left+this.width&&a.y>=this.top&&a.y<=this.top+this.height};goog.math.Rect.prototype.squaredDistance=function(a){var b=a.xa.aspectRatio()?a.width/this.width:a.height/this.height;return this.scale(a)};goog.Thenable=function(){};goog.Thenable.prototype.then=function(a,b,c){};goog.Thenable.IMPLEMENTED_BY_PROP="$goog_Thenable";goog.Thenable.addImplementation=function(a){goog.exportProperty(a.prototype,"then",a.prototype.then);COMPILED?a.prototype[goog.Thenable.IMPLEMENTED_BY_PROP]=!0:a.prototype.$goog_Thenable=!0};goog.Thenable.isImplementedBy=function(a){if(!a)return!1;try{return COMPILED?!!a[goog.Thenable.IMPLEMENTED_BY_PROP]:!!a.$goog_Thenable}catch(b){return!1}};goog.debug.entryPointRegistry={};goog.debug.EntryPointMonitor=function(){};goog.debug.entryPointRegistry.refList_=[];goog.debug.entryPointRegistry.monitors_=[];goog.debug.entryPointRegistry.monitorsMayExist_=!1;goog.debug.entryPointRegistry.register=function(a){goog.debug.entryPointRegistry.refList_[goog.debug.entryPointRegistry.refList_.length]=a;if(goog.debug.entryPointRegistry.monitorsMayExist_)for(var b=goog.debug.entryPointRegistry.monitors_,c=0;cgoog.Timer.MAX_TIMEOUT_?goog.Timer.INVALID_TIMEOUT_ID_:goog.Timer.defaultTimerObject.setTimeout(a,b||0)};goog.Timer.clear=function(a){goog.Timer.defaultTimerObject.clearTimeout(a)}; -goog.Timer.promise=function(a,b){var c=null;return(new goog.Promise(function(d,e){c=goog.Timer.callOnce(function(){d(b)},a);c==goog.Timer.INVALID_TIMEOUT_ID_&&e(Error("Failed to schedule timer."))})).thenCatch(function(a){goog.Timer.clear(c);throw a;})};goog.dom.BrowserFeature={CAN_ADD_NAME_OR_TYPE_ATTRIBUTES:!goog.userAgent.IE||goog.userAgent.isDocumentModeOrHigher(9),CAN_USE_CHILDREN_ATTRIBUTE:!goog.userAgent.GECKO&&!goog.userAgent.IE||goog.userAgent.IE&&goog.userAgent.isDocumentModeOrHigher(9)||goog.userAgent.GECKO&&goog.userAgent.isVersionOrHigher("1.9.1"),CAN_USE_INNER_TEXT:goog.userAgent.IE&&!goog.userAgent.isVersionOrHigher("9"),CAN_USE_PARENT_ELEMENT_PROPERTY:goog.userAgent.IE||goog.userAgent.OPERA||goog.userAgent.WEBKIT,INNER_HTML_NEEDS_SCOPED_ELEMENT:goog.userAgent.IE, +goog.Timer.promise=function(a,b){var c=null;return(new goog.Promise(function(d,e){c=goog.Timer.callOnce(function(){d(b)},a);c==goog.Timer.INVALID_TIMEOUT_ID_&&e(Error("Failed to schedule timer."))})).thenCatch(function(a){goog.Timer.clear(c);throw a;})};goog.math.Coordinate=function(a,b){this.x=goog.isDef(a)?a:0;this.y=goog.isDef(b)?b:0};goog.math.Coordinate.prototype.clone=function(){return new goog.math.Coordinate(this.x,this.y)};goog.DEBUG&&(goog.math.Coordinate.prototype.toString=function(){return"("+this.x+", "+this.y+")"});goog.math.Coordinate.equals=function(a,b){return a==b?!0:a&&b?a.x==b.x&&a.y==b.y:!1};goog.math.Coordinate.distance=function(a,b){var c=a.x-b.x,d=a.y-b.y;return Math.sqrt(c*c+d*d)}; +goog.math.Coordinate.magnitude=function(a){return Math.sqrt(a.x*a.x+a.y*a.y)};goog.math.Coordinate.azimuth=function(a){return goog.math.angle(0,0,a.x,a.y)};goog.math.Coordinate.squaredDistance=function(a,b){var c=a.x-b.x,d=a.y-b.y;return c*c+d*d};goog.math.Coordinate.difference=function(a,b){return new goog.math.Coordinate(a.x-b.x,a.y-b.y)};goog.math.Coordinate.sum=function(a,b){return new goog.math.Coordinate(a.x+b.x,a.y+b.y)}; +goog.math.Coordinate.prototype.ceil=function(){this.x=Math.ceil(this.x);this.y=Math.ceil(this.y);return this};goog.math.Coordinate.prototype.floor=function(){this.x=Math.floor(this.x);this.y=Math.floor(this.y);return this};goog.math.Coordinate.prototype.round=function(){this.x=Math.round(this.x);this.y=Math.round(this.y);return this};goog.math.Coordinate.prototype.translate=function(a,b){a instanceof goog.math.Coordinate?(this.x+=a.x,this.y+=a.y):(this.x+=a,goog.isNumber(b)&&(this.y+=b));return this}; +goog.math.Coordinate.prototype.scale=function(a,b){var c=goog.isNumber(b)?b:a;this.x*=a;this.y*=c;return this};goog.math.Coordinate.prototype.rotateRadians=function(a,b){var c=b||new goog.math.Coordinate(0,0),d=this.x,e=this.y,f=Math.cos(a),g=Math.sin(a);this.x=(d-c.x)*f-(e-c.y)*g+c.x;this.y=(d-c.x)*g+(e-c.y)*f+c.y};goog.math.Coordinate.prototype.rotateDegrees=function(a,b){this.rotateRadians(goog.math.toRadians(a),b)};goog.math.Box=function(a,b,c,d){this.top=a;this.right=b;this.bottom=c;this.left=d};goog.math.Box.boundingBox=function(a){for(var b=new goog.math.Box(arguments[0].y,arguments[0].x,arguments[0].y,arguments[0].x),c=1;c=a.left&&b.right<=a.right&&b.top>=a.top&&b.bottom<=a.bottom:b.x>=a.left&&b.x<=a.right&&b.y>=a.top&&b.y<=a.bottom:!1};goog.math.Box.relativePositionX=function(a,b){return b.xa.right?b.x-a.right:0}; +goog.math.Box.relativePositionY=function(a,b){return b.ya.bottom?b.y-a.bottom:0};goog.math.Box.distance=function(a,b){var c=goog.math.Box.relativePositionX(a,b),d=goog.math.Box.relativePositionY(a,b);return Math.sqrt(c*c+d*d)};goog.math.Box.intersects=function(a,b){return a.left<=b.right&&b.left<=a.right&&a.top<=b.bottom&&b.top<=a.bottom};goog.math.Box.intersectsWithPadding=function(a,b,c){return a.left<=b.right+c&&b.left<=a.right+c&&a.top<=b.bottom+c&&b.top<=a.bottom+c}; +goog.math.Box.prototype.ceil=function(){this.top=Math.ceil(this.top);this.right=Math.ceil(this.right);this.bottom=Math.ceil(this.bottom);this.left=Math.ceil(this.left);return this};goog.math.Box.prototype.floor=function(){this.top=Math.floor(this.top);this.right=Math.floor(this.right);this.bottom=Math.floor(this.bottom);this.left=Math.floor(this.left);return this}; +goog.math.Box.prototype.round=function(){this.top=Math.round(this.top);this.right=Math.round(this.right);this.bottom=Math.round(this.bottom);this.left=Math.round(this.left);return this};goog.math.Box.prototype.translate=function(a,b){a instanceof goog.math.Coordinate?(this.left+=a.x,this.right+=a.x,this.top+=a.y,this.bottom+=a.y):(this.left+=a,this.right+=a,goog.isNumber(b)&&(this.top+=b,this.bottom+=b));return this}; +goog.math.Box.prototype.scale=function(a,b){var c=goog.isNumber(b)?b:a;this.left*=a;this.right*=a;this.top*=c;this.bottom*=c;return this};goog.math.Rect=function(a,b,c,d){this.left=a;this.top=b;this.width=c;this.height=d};goog.math.Rect.prototype.clone=function(){return new goog.math.Rect(this.left,this.top,this.width,this.height)};goog.math.Rect.prototype.toBox=function(){return new goog.math.Box(this.top,this.left+this.width,this.top+this.height,this.left)};goog.math.Rect.createFromBox=function(a){return new goog.math.Rect(a.left,a.top,a.right-a.left,a.bottom-a.top)}; +goog.DEBUG&&(goog.math.Rect.prototype.toString=function(){return"("+this.left+", "+this.top+" - "+this.width+"w x "+this.height+"h)"});goog.math.Rect.equals=function(a,b){return a==b?!0:a&&b?a.left==b.left&&a.width==b.width&&a.top==b.top&&a.height==b.height:!1}; +goog.math.Rect.prototype.intersection=function(a){var b=Math.max(this.left,a.left),c=Math.min(this.left+this.width,a.left+a.width);if(b<=c){var d=Math.max(this.top,a.top);a=Math.min(this.top+this.height,a.top+a.height);if(d<=a)return this.left=b,this.top=d,this.width=c-b,this.height=a-d,!0}return!1}; +goog.math.Rect.intersection=function(a,b){var c=Math.max(a.left,b.left),d=Math.min(a.left+a.width,b.left+b.width);if(c<=d){var e=Math.max(a.top,b.top),f=Math.min(a.top+a.height,b.top+b.height);if(e<=f)return new goog.math.Rect(c,e,d-c,f-e)}return null};goog.math.Rect.intersects=function(a,b){return a.left<=b.left+b.width&&b.left<=a.left+a.width&&a.top<=b.top+b.height&&b.top<=a.top+a.height};goog.math.Rect.prototype.intersects=function(a){return goog.math.Rect.intersects(this,a)}; +goog.math.Rect.difference=function(a,b){var c=goog.math.Rect.intersection(a,b);if(!c||!c.height||!c.width)return[a.clone()];var c=[],d=a.top,e=a.height,f=a.left+a.width,g=a.top+a.height,h=b.left+b.width,k=b.top+b.height;b.top>a.top&&(c.push(new goog.math.Rect(a.left,a.top,a.width,b.top-a.top)),d=b.top,e-=b.top-a.top);ka.left&&c.push(new goog.math.Rect(a.left,d,b.left-a.left,e));h=a.left+a.width&&this.top<=a.top&&this.top+this.height>=a.top+a.height:a.x>=this.left&&a.x<=this.left+this.width&&a.y>=this.top&&a.y<=this.top+this.height};goog.math.Rect.prototype.squaredDistance=function(a){var b=a.x 0 || this.lidOpen_ < 1) { this.lidTask_ = goog.Timer.callOnce(this.animateLid_, 20, this); diff --git a/core/xml.js b/core/xml.js index be7bd2184..7abb2ac5a 100644 --- a/core/xml.js +++ b/core/xml.js @@ -247,10 +247,10 @@ Blockly.Xml.domToBlock = function(workspace, xmlBlock, opt_reuseBlock) { // Generate list of all blocks. var blocks = topBlock.getDescendants(); // Render each block. - for (var i = blocks.length -1; i >= 0; i--) { + for (var i = blocks.length - 1; i >= 0; i--) { blocks[i].initSvg(); } - for (var i = blocks.length -1; i >= 0; i--) { + for (var i = blocks.length - 1; i >= 0; i--) { blocks[i].render(false); } topBlock.updateDisabled(); diff --git a/generators/python.js b/generators/python.js index dbefed7ea..f0a5b957e 100644 --- a/generators/python.js +++ b/generators/python.js @@ -79,6 +79,11 @@ Blockly.Python.ORDER_CONDITIONAL = 15; // if else Blockly.Python.ORDER_LAMBDA = 16; // lambda Blockly.Python.ORDER_NONE = 99; // (...) +/** + * Empty loops or conditionals are not allowed in Python. + */ +Blockly.Python.PASS = ' pass\n'; + /** * Initialise the database of variable names. * @param {!Blockly.Workspace} workspace Workspace to generate code from. diff --git a/generators/python/logic.js b/generators/python/logic.js index d67ac8f7d..a485e5c9e 100644 --- a/generators/python/logic.js +++ b/generators/python/logic.js @@ -34,16 +34,19 @@ Blockly.Python['controls_if'] = function(block) { var n = 0; var argument = Blockly.Python.valueToCode(block, 'IF' + n, Blockly.Python.ORDER_NONE) || 'False'; - var branch = Blockly.Python.statementToCode(block, 'DO' + n) || ' pass\n'; + var branch = Blockly.Python.statementToCode(block, 'DO' + n) || + Blockly.Python.PASS; var code = 'if ' + argument + ':\n' + branch; for (n = 1; n <= block.elseifCount_; n++) { argument = Blockly.Python.valueToCode(block, 'IF' + n, Blockly.Python.ORDER_NONE) || 'False'; - branch = Blockly.Python.statementToCode(block, 'DO' + n) || ' pass\n'; + branch = Blockly.Python.statementToCode(block, 'DO' + n) || + Blockly.Python.PASS; code += 'elif ' + argument + ':\n' + branch; } if (block.elseCount_) { - branch = Blockly.Python.statementToCode(block, 'ELSE') || ' pass\n'; + branch = Blockly.Python.statementToCode(block, 'ELSE') || + Blockly.Python.PASS; code += 'else:\n' + branch; } return code; diff --git a/generators/python/loops.js b/generators/python/loops.js index 64bba0f96..55cd6b440 100644 --- a/generators/python/loops.js +++ b/generators/python/loops.js @@ -28,14 +28,12 @@ goog.provide('Blockly.Python.loops'); goog.require('Blockly.Python'); -Blockly.Python.LOOP_PASS = ' pass\n'; - Blockly.Python['controls_repeat'] = function(block) { // Repeat n times (internal number). var repeats = parseInt(block.getFieldValue('TIMES'), 10); var branch = Blockly.Python.statementToCode(block, 'DO'); branch = Blockly.Python.addLoopTrap(branch, block.id) || - Blockly.Python.LOOP_PASS; + Blockly.Python.PASS; var loopVar = Blockly.Python.variableDB_.getDistinctName( 'count', Blockly.Variables.NAME_TYPE); var code = 'for ' + loopVar + ' in range(' + repeats + '):\n' + branch; @@ -53,7 +51,7 @@ Blockly.Python['controls_repeat_ext'] = function(block) { } var branch = Blockly.Python.statementToCode(block, 'DO'); branch = Blockly.Python.addLoopTrap(branch, block.id) || - Blockly.Python.LOOP_PASS; + Blockly.Python.PASS; var loopVar = Blockly.Python.variableDB_.getDistinctName( 'count', Blockly.Variables.NAME_TYPE); var code = 'for ' + loopVar + ' in range(' + repeats + '):\n' + branch; @@ -68,7 +66,7 @@ Blockly.Python['controls_whileUntil'] = function(block) { Blockly.Python.ORDER_NONE) || 'False'; var branch = Blockly.Python.statementToCode(block, 'DO'); branch = Blockly.Python.addLoopTrap(branch, block.id) || - Blockly.Python.LOOP_PASS; + Blockly.Python.PASS; if (until) { argument0 = 'not ' + argument0; } @@ -87,7 +85,7 @@ Blockly.Python['controls_for'] = function(block) { Blockly.Python.ORDER_NONE) || '1'; var branch = Blockly.Python.statementToCode(block, 'DO'); branch = Blockly.Python.addLoopTrap(branch, block.id) || - Blockly.Python.LOOP_PASS; + Blockly.Python.PASS; var code = ''; var range; @@ -199,7 +197,7 @@ Blockly.Python['controls_forEach'] = function(block) { Blockly.Python.ORDER_RELATIONAL) || '[]'; var branch = Blockly.Python.statementToCode(block, 'DO'); branch = Blockly.Python.addLoopTrap(branch, block.id) || - Blockly.Python.LOOP_PASS; + Blockly.Python.PASS; var code = 'for ' + variable0 + ' in ' + argument0 + ':\n' + branch; return code; }; diff --git a/generators/python/procedures.js b/generators/python/procedures.js index 496c8d4d9..6d11df8c2 100644 --- a/generators/python/procedures.js +++ b/generators/python/procedures.js @@ -62,7 +62,7 @@ Blockly.Python['procedures_defreturn'] = function(block) { if (returnValue) { returnValue = ' return ' + returnValue + '\n'; } else if (!branch) { - branch = ' pass'; + branch = Blockly.Python.PASS; } var args = []; for (var x = 0; x < block.arguments_.length; x++) { diff --git a/i18n/status.html b/i18n/status.html deleted file mode 100644 index a520c69e4..000000000 --- a/i18n/status.html +++ /dev/null @@ -1,1825 +0,0 @@ -Blockly app translation status - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LanguageAppsCodeGraphMazePlanePuzzleTurtle
el -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
ia -30 (88%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
en -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
lrc -20 (58%) - -3 (42%) - -0 (0%) - -12 (35%) - -5 (35%) - -28 (87%) - -14 (43%) -
af -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -32 (100%) - -0 (0%) -
oc -25 (73%) - -7 (100%) - -1 (100%) - -27 (79%) - -10 (71%) - -32 (100%) - -32 (100%) -
arz -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -19 (59%) - -0 (0%) -
cdo -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -32 (100%) - -0 (0%) -
sk -23 (67%) - -7 (100%) - -1 (100%) - -33 (97%) - -14 (100%) - -32 (100%) - -32 (100%) -
it -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
cs -30 (88%) - -6 (85%) - -1 (100%) - -32 (94%) - -11 (78%) - -32 (100%) - -24 (75%) -
ar -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
pt-br -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
mk -23 (67%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
eu -21 (61%) - -3 (42%) - -0 (0%) - -27 (79%) - -3 (21%) - -32 (100%) - -0 (0%) -
gn -19 (55%) - -0 (0%) - -0 (0%) - -2 (5%) - -1 (7%) - -26 (81%) - -15 (46%) -
az -15 (44%) - -4 (57%) - -1 (100%) - -3 (8%) - -1 (7%) - -28 (87%) - -4 (12%) -
tzm -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -13 (40%) - -0 (0%) -
es -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
ps -9 (26%) - -1 (14%) - -0 (0%) - -3 (8%) - -0 (0%) - -29 (90%) - -6 (18%) -
gl -23 (67%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
lb -20 (58%) - -5 (71%) - -0 (0%) - -13 (38%) - -12 (85%) - -32 (100%) - -13 (40%) -
hrx -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
pt -20 (58%) - -5 (71%) - -0 (0%) - -27 (79%) - -1 (7%) - -26 (81%) - -7 (21%) -
la -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -32 (100%) - -0 (0%) -
zh-hant -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
nb -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
pms -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
tr -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
lv -23 (67%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
frr -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -32 (100%) - -0 (0%) -
lt -15 (44%) - -4 (57%) - -0 (0%) - -7 (20%) - -6 (42%) - -32 (100%) - -17 (53%) -
pa -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -32 (100%) - -0 (0%) -
sw -11 (32%) - -0 (0%) - -0 (0%) - -27 (79%) - -0 (0%) - -32 (100%) - -0 (0%) -
sr -34 (100%) - -7 (100%) - -1 (100%) - -31 (91%) - -8 (57%) - -29 (90%) - -1 (3%) -
th -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
vi -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
he -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
ca -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
pl -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
ta -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -22 (68%) - -0 (0%) -
fr -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
bg -2 (5%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -24 (75%) - -0 (0%) -
uk -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
ru -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
ku-latn -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -12 (37%) - -0 (0%) -
bn -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -22 (68%) - -0 (0%) -
de -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
mg -34 (100%) - -7 (100%) - -1 (100%) - -14 (41%) - -2 (14%) - -10 (31%) - -5 (15%) -
da -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
fa -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
hak -13 (38%) - -3 (42%) - -0 (0%) - -11 (32%) - -0 (0%) - -32 (100%) - -0 (0%) -
br -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
tlh -18 (52%) - -6 (85%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) -
fi -12 (35%) - -1 (14%) - -0 (0%) - -2 (5%) - -0 (0%) - -32 (100%) - -3 (9%) -
mzn -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -32 (100%) - -0 (0%) -
hu -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
ja -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
is -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
fo -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -32 (100%) - -0 (0%) -
ka -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -32 (100%) - -0 (0%) -
ro -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
ace -34 (100%) - -7 (100%) - -1 (100%) - -13 (38%) - -1 (7%) - -30 (93%) - -3 (9%) -
zh-hans -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
ml -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -32 (100%) - -0 (0%) -
ko -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
sv -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
km -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -32 (100%) - -0 (0%) -
ksh -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -32 (100%) - -0 (0%) -
sco -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -30 (93%) -
te -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -21 (65%) - -0 (0%) -
si -15 (44%) - -0 (0%) - -1 (100%) - -7 (20%) - -13 (92%) - -30 (93%) - -7 (21%) -
hi -34 (100%) - -6 (85%) - -1 (100%) - -22 (64%) - -13 (92%) - -31 (96%) - -29 (90%) -
be-tarask -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
ms -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
mr -8 (23%) - -2 (28%) - -0 (0%) - -2 (5%) - -8 (57%) - -31 (96%) - -18 (56%) -
ky -1 (2%) - -0 (0%) - -0 (0%) - -0 (0%) - -0 (0%) - -32 (100%) - -0 (0%) -
nl -34 (100%) - -7 (100%) - -1 (100%) - -34 (100%) - -14 (100%) - -32 (100%) - -32 (100%) -
diq -17 (50%) - -4 (57%) - -1 (100%) - -6 (17%) - -9 (64%) - -27 (84%) - -14 (43%) -
ALL -0000000 -
- diff --git a/i18n/status.py b/i18n/status.py deleted file mode 100755 index 45b8d7695..000000000 --- a/i18n/status.py +++ /dev/null @@ -1,247 +0,0 @@ -#!/usr/bin/python - -# Gives the translation status of the specified apps and languages. -# -# Copyright 2013 Google Inc. -# https://developers.google.com/blockly/ -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Produce a table showing the translation status of each app by language. - -@author Ellen Spertus (ellen.spertus@gmail.com) -""" - -import argparse -import os -from common import read_json_file - -# Bogus language name representing all messages defined. -TOTAL = 'qqq' - -# List of key prefixes, which are app names, except for 'Apps', which -# has common messages. It is included here for convenience. -APPS = ['Apps', 'Code', 'Graph', 'Maze', 'Plane', 'Puzzle', 'Turtle'] - - -def get_prefix(s): - """Gets the portion of a string before the first period. - - Args: - s: A string. - - Returns: - The portion of the string before the first period, or the entire - string if it does not contain a period. - """ - return s.split('.')[0] - - -def get_prefix_count(prefix, arr): - """Counts how many strings in the array start with the prefix. - - Args: - prefix: The prefix string. - arr: An array of strings. - Returns: - The number of strings in arr starting with prefix. - """ - # This code was chosen for its elegance not its efficiency. - return len([elt for elt in arr if elt.startswith(prefix)]) - - -def output_as_html(messages, apps, verbose): - """Outputs the given prefix counts and percentages as HTML. - - Specifically, a sortable HTML table is produced, where the app names - are column headers, and one language is output per row. Entries - are color-coded based on the percent completeness. - - Args: - messages: A dictionary of dictionaries, where the outer keys are language - codes used by translatewiki (generally, ISO 639 language codes) or - the string TOTAL, used to indicate the total set of messages. The - inner dictionary makes message keys to values in that language. - apps: Apps to consider. - verbose: Whether to list missing keys. - """ - def generate_language_url(lang): - return 'https://translatewiki.net/wiki/Special:SupportedLanguages#' + lang - - def generate_number_as_percent(num, total, tag): - percent = num * 100 / total - if percent == 100: - color = 'green' - elif percent >= 90: - color = 'orange' - elif percent >= 60: - color = 'black' - else: - color = 'gray' - s = '{1} ({2}%)'.format(color, num, percent) - if verbose and percent < 100: - return '{1}'.format(tag, s) - else: - return s - - print('Blockly app translation status') - print("") - print('') - print('') - for lang in messages: - if lang != TOTAL: - print(''.format( - lang, generate_language_url(lang))) - for app in apps: - print '' - print('') - print('
Language' + - ''.join(apps) + '
{0}' - print(generate_number_as_percent( - get_prefix_count(app, messages[lang]), - get_prefix_count(app, messages[TOTAL]), - (lang + app))) - print '
ALL') - print(''.join([str(get_prefix_count(app, TOTAL)) for app in apps])) - print('
') - - if verbose: - for lang in messages: - if lang != TOTAL: - for app in apps: - if (get_prefix_count(app, messages[lang]) < - get_prefix_count(app, messages[TOTAL])): - print('
{1} ({0})'. - format(lang, app, generate_language_url(lang))) - print(' missing: ') - print(', '.join( - [key for key in messages[TOTAL] if - key.startswith(app) and key not in messages[lang]])) - print('

') - print('') - - -def output_as_text(messages, apps, verbose): - """Outputs the given prefix counts and percentages as text. - - Args: - messages: A dictionary of dictionaries, where the outer keys are language - codes used by translatewiki (generally, ISO 639 language codes) or - the string TOTAL, used to indicate the total set of messages. The - inner dictionary makes message keys to values in that language. - apps: Apps to consider. - verbose: Whether to list missing keys. - """ - def generate_number_as_percent(num, total): - return '{0} ({1}%)'.format(num, num * 100 / total) - MAX_WIDTH = len('999 (100%)') + 1 - FIELD_STRING = '{0: <' + str(MAX_WIDTH) + '}' - print(FIELD_STRING.format('Language') + ''.join( - [FIELD_STRING.format(app) for app in apps])) - print(('-' * (MAX_WIDTH - 1) + ' ') * (len(apps) + 1)) - for lang in messages: - if lang != TOTAL: - print(FIELD_STRING.format(lang) + - ''.join([FIELD_STRING.format(generate_number_as_percent( - get_prefix_count(app, messages[lang]), - get_prefix_count(app, messages[TOTAL]))) - for app in apps])) - print(FIELD_STRING.format(TOTAL) + - ''.join( - [FIELD_STRING.format(get_prefix_count(app, messages[TOTAL])) - for app in apps])) - if verbose: - for lang in messages: - if lang != TOTAL: - for app in apps: - missing = [key for key in messages[TOTAL] - if key.startswith(app) and key not in messages[lang]] - print('{0} {1}: Missing: {2}'.format( - app.upper(), lang, (', '.join(missing) if missing else 'none'))) - - -def output_as_csv(messages, apps): - """Outputs the given prefix counts and percentages as CSV. - - Args: - messages: A dictionary of dictionaries, where the outer keys are language - codes used by translatewiki (generally, ISO 639 language codes) or - the string TOTAL, used to indicate the total set of messages. The - inner dictionary makes message keys to values in that language. - apps: Apps to consider. - """ - # Header row. - print('Language, ' + ', ,'.join(apps)) - - # Total row. - # Put at top, rather than bottom, so it can be frozen. - print('TOTAL, ' + ', '.join( - [str(get_prefix_count(app, messages[TOTAL])) + ', ' - for app in apps])) - - # One line per language. - for lang in messages: - if lang != TOTAL: - print(lang + ', ' + ', '.join( - [str(get_prefix_count(app, messages[lang])) - + ', ' - + str((get_prefix_count(app, messages[lang]) * 1.0 / - get_prefix_count(app, messages[TOTAL]))) - for app in apps])) - - -def main(): - """Processes input files and outputs results in specified format. - """ - # Argument parsing. - parser = argparse.ArgumentParser( - description='Display translation status by app and language.') - parser.add_argument('--key_file', default='json' + os.path.sep + 'keys.json', - help='file with complete list of keys.') - parser.add_argument('--output', default='text', - choices=['text', 'html', 'csv'], - help='output format') - parser.add_argument('--verbose', action='store_true', default=False, - help='whether to indicate which messages were translated ' - '(only used in text and html output modes)') - parser.add_argument('--app', default=None, choices=APPS, - help='if set, only consider the specified app (prefix).') - parser.add_argument('lang_files', nargs='+', - help='names of JSON files to examine') - args = parser.parse_args() - apps = [args.app] if args.app else APPS - - - # Read in JSON files. - messages = {} # A dictionary of dictionaries. - messages[TOTAL] = read_json_file(args.key_file) - for lang_file in args.lang_files: - prefix = get_prefix(os.path.split(lang_file)[1]) - # Skip non-language files. - if prefix not in ['qqq', 'keys']: - messages[prefix] = read_json_file(lang_file) - - # Output results. - if args.output == 'text': - output_as_text(messages, apps, args.verbose) - elif args.output == 'html': - output_as_html(messages, apps, args.verbose) - elif args.output == 'csv': - output_as_csv(messages, apps) - else: - print('No output?!') - - -if __name__ == '__main__': - main() diff --git a/python_compressed.js b/python_compressed.js index afb224ca9..0c445d4c6 100644 --- a/python_compressed.js +++ b/python_compressed.js @@ -5,7 +5,7 @@ // Copyright 2012 Google Inc. Apache License 2.0 Blockly.Python=new Blockly.Generator("Python");Blockly.Python.addReservedWords("and,as,assert,break,class,continue,def,del,elif,else,except,exec,finally,for,from,global,if,import,in,is,lambda,not,or,pass,print,raise,return,try,while,with,yield,True,False,None,NotImplemented,Ellipsis,__debug__,quit,exit,copyright,license,credits,abs,divmod,input,open,staticmethod,all,enumerate,int,ord,str,any,eval,isinstance,pow,sum,basestring,execfile,issubclass,print,super,bin,file,iter,property,tuple,bool,filter,len,range,type,bytearray,float,list,raw_input,unichr,callable,format,locals,reduce,unicode,chr,frozenset,long,reload,vars,classmethod,getattr,map,repr,xrange,cmp,globals,max,reversed,zip,compile,hasattr,memoryview,round,__import__,complex,hash,min,set,apply,delattr,help,next,setattr,buffer,dict,hex,object,slice,coerce,dir,id,oct,sorted,intern"); Blockly.Python.ORDER_ATOMIC=0;Blockly.Python.ORDER_COLLECTION=1;Blockly.Python.ORDER_STRING_CONVERSION=1;Blockly.Python.ORDER_MEMBER=2;Blockly.Python.ORDER_FUNCTION_CALL=2;Blockly.Python.ORDER_EXPONENTIATION=3;Blockly.Python.ORDER_UNARY_SIGN=4;Blockly.Python.ORDER_BITWISE_NOT=4;Blockly.Python.ORDER_MULTIPLICATIVE=5;Blockly.Python.ORDER_ADDITIVE=6;Blockly.Python.ORDER_BITWISE_SHIFT=7;Blockly.Python.ORDER_BITWISE_AND=8;Blockly.Python.ORDER_BITWISE_XOR=9;Blockly.Python.ORDER_BITWISE_OR=10; -Blockly.Python.ORDER_RELATIONAL=11;Blockly.Python.ORDER_LOGICAL_NOT=12;Blockly.Python.ORDER_LOGICAL_AND=13;Blockly.Python.ORDER_LOGICAL_OR=14;Blockly.Python.ORDER_CONDITIONAL=15;Blockly.Python.ORDER_LAMBDA=16;Blockly.Python.ORDER_NONE=99; +Blockly.Python.ORDER_RELATIONAL=11;Blockly.Python.ORDER_LOGICAL_NOT=12;Blockly.Python.ORDER_LOGICAL_AND=13;Blockly.Python.ORDER_LOGICAL_OR=14;Blockly.Python.ORDER_CONDITIONAL=15;Blockly.Python.ORDER_LAMBDA=16;Blockly.Python.ORDER_NONE=99;Blockly.Python.PASS=" pass\n"; Blockly.Python.init=function(a){Blockly.Python.definitions_=Object.create(null);Blockly.Python.functionNames_=Object.create(null);Blockly.Python.variableDB_?Blockly.Python.variableDB_.reset():Blockly.Python.variableDB_=new Blockly.Names(Blockly.Python.RESERVED_WORDS_);var b=[];a=Blockly.Variables.allVariables(a);for(var c=0;c",GTE:">="}[a.getFieldValue("OP")],c=Blockly.Python.ORDER_RELATIONAL,d=Blockly.Python.valueToCode(a,"A",c)||"0";a=Blockly.Python.valueToCode(a,"B",c)||"0";return[d+" "+b+" "+a,c]}; Blockly.Python.logic_operation=function(a){var b="AND"==a.getFieldValue("OP")?"and":"or",c="and"==b?Blockly.Python.ORDER_LOGICAL_AND:Blockly.Python.ORDER_LOGICAL_OR,d=Blockly.Python.valueToCode(a,"A",c);a=Blockly.Python.valueToCode(a,"B",c);if(d||a){var e="and"==b?"True":"False";d||(d=e);a||(a=e)}else a=d="False";return[d+" "+b+" "+a,c]};Blockly.Python.logic_negate=function(a){return["not "+(Blockly.Python.valueToCode(a,"BOOL",Blockly.Python.ORDER_LOGICAL_NOT)||"True"),Blockly.Python.ORDER_LOGICAL_NOT]}; Blockly.Python.logic_boolean=function(a){return["TRUE"==a.getFieldValue("BOOL")?"True":"False",Blockly.Python.ORDER_ATOMIC]};Blockly.Python.logic_null=function(a){return["None",Blockly.Python.ORDER_ATOMIC]}; Blockly.Python.logic_ternary=function(a){var b=Blockly.Python.valueToCode(a,"IF",Blockly.Python.ORDER_CONDITIONAL)||"False",c=Blockly.Python.valueToCode(a,"THEN",Blockly.Python.ORDER_CONDITIONAL)||"None";a=Blockly.Python.valueToCode(a,"ELSE",Blockly.Python.ORDER_CONDITIONAL)||"None";return[c+" if "+b+" else "+a,Blockly.Python.ORDER_CONDITIONAL]}; // Copyright 2012 Google Inc. Apache License 2.0 -Blockly.Python.loops={};Blockly.Python.LOOP_PASS=" pass\n";Blockly.Python.controls_repeat=function(a){var b=parseInt(a.getFieldValue("TIMES"),10),c=Blockly.Python.statementToCode(a,"DO"),c=Blockly.Python.addLoopTrap(c,a.id)||Blockly.Python.LOOP_PASS;return"for "+Blockly.Python.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE)+" in range("+b+"):\n"+c}; -Blockly.Python.controls_repeat_ext=function(a){var b=Blockly.Python.valueToCode(a,"TIMES",Blockly.Python.ORDER_NONE)||"0",b=Blockly.isNumber(b)?parseInt(b,10):"int("+b+")",c=Blockly.Python.statementToCode(a,"DO"),c=Blockly.Python.addLoopTrap(c,a.id)||Blockly.Python.LOOP_PASS;return"for "+Blockly.Python.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE)+" in range("+b+"):\n"+c}; -Blockly.Python.controls_whileUntil=function(a){var b="UNTIL"==a.getFieldValue("MODE"),c=Blockly.Python.valueToCode(a,"BOOL",b?Blockly.Python.ORDER_LOGICAL_NOT:Blockly.Python.ORDER_NONE)||"False",d=Blockly.Python.statementToCode(a,"DO"),d=Blockly.Python.addLoopTrap(d,a.id)||Blockly.Python.LOOP_PASS;b&&(c="not "+c);return"while "+c+":\n"+d}; -Blockly.Python.controls_for=function(a){var b=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.Python.valueToCode(a,"FROM",Blockly.Python.ORDER_NONE)||"0",d=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_NONE)||"0",e=Blockly.Python.valueToCode(a,"BY",Blockly.Python.ORDER_NONE)||"1",g=Blockly.Python.statementToCode(a,"DO"),g=Blockly.Python.addLoopTrap(g,a.id)||Blockly.Python.LOOP_PASS,f="",h=function(){return Blockly.Python.provideFunction_("upRange", +Blockly.Python.loops={};Blockly.Python.controls_repeat=function(a){var b=parseInt(a.getFieldValue("TIMES"),10),c=Blockly.Python.statementToCode(a,"DO"),c=Blockly.Python.addLoopTrap(c,a.id)||Blockly.Python.PASS;return"for "+Blockly.Python.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE)+" in range("+b+"):\n"+c}; +Blockly.Python.controls_repeat_ext=function(a){var b=Blockly.Python.valueToCode(a,"TIMES",Blockly.Python.ORDER_NONE)||"0",b=Blockly.isNumber(b)?parseInt(b,10):"int("+b+")",c=Blockly.Python.statementToCode(a,"DO"),c=Blockly.Python.addLoopTrap(c,a.id)||Blockly.Python.PASS;return"for "+Blockly.Python.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE)+" in range("+b+"):\n"+c}; +Blockly.Python.controls_whileUntil=function(a){var b="UNTIL"==a.getFieldValue("MODE"),c=Blockly.Python.valueToCode(a,"BOOL",b?Blockly.Python.ORDER_LOGICAL_NOT:Blockly.Python.ORDER_NONE)||"False",d=Blockly.Python.statementToCode(a,"DO"),d=Blockly.Python.addLoopTrap(d,a.id)||Blockly.Python.PASS;b&&(c="not "+c);return"while "+c+":\n"+d}; +Blockly.Python.controls_for=function(a){var b=Blockly.Python.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.Python.valueToCode(a,"FROM",Blockly.Python.ORDER_NONE)||"0",d=Blockly.Python.valueToCode(a,"TO",Blockly.Python.ORDER_NONE)||"0",e=Blockly.Python.valueToCode(a,"BY",Blockly.Python.ORDER_NONE)||"1",g=Blockly.Python.statementToCode(a,"DO"),g=Blockly.Python.addLoopTrap(g,a.id)||Blockly.Python.PASS,f="",h=function(){return Blockly.Python.provideFunction_("upRange", ["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(start, stop, step):"," while start <= stop:"," yield start"," start += abs(step)"])},k=function(){return Blockly.Python.provideFunction_("downRange",["def "+Blockly.Python.FUNCTION_NAME_PLACEHOLDER_+"(start, stop, step):"," while start >= stop:"," yield start"," start -= abs(step)"])};a=function(a,b,c){return"("+a+" <= "+b+") and "+h()+"("+a+", "+b+", "+c+") or "+k()+"("+a+", "+b+", "+c+")"};if(Blockly.isNumber(c)&&Blockly.isNumber(d)&& Blockly.isNumber(e))c=parseFloat(c),d=parseFloat(d),e=Math.abs(parseFloat(e)),0===c%1&&0===d%1&&0===e%1?(c<=d?(d++,a=0==c&&1==e?d:c+", "+d,1!=e&&(a+=", "+e)):(d--,a=c+", "+d+", -"+e),a="range("+a+")"):(a=ca?Blockly.Python.ORDER_UNARY_SIGN:Blockly.Python.ORDER_ATOMIC]}; @@ -67,7 +68,7 @@ Blockly.Python.math_random_int=function(a){Blockly.Python.definitions_.import_ra // Copyright 2012 Google Inc. Apache License 2.0 Blockly.Python.procedures={}; Blockly.Python.procedures_defreturn=function(a){for(var b=Blockly.Variables.allVariables(a),c=b.length-1;0<=c;c--){var d=b[c];-1==a.arguments_.indexOf(d)?b[c]=Blockly.Python.variableDB_.getName(d,Blockly.Variables.NAME_TYPE):b.splice(c,1)}b=b.length?" global "+b.join(", ")+"\n":"";c=Blockly.Python.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE);d=Blockly.Python.statementToCode(a,"STACK");Blockly.Python.STATEMENT_PREFIX&&(d=Blockly.Python.prefixLines(Blockly.Python.STATEMENT_PREFIX.replace(/%1/g,"'"+ -a.id+"'"),Blockly.Python.INDENT)+d);Blockly.Python.INFINITE_LOOP_TRAP&&(d=Blockly.Python.INFINITE_LOOP_TRAP.replace(/%1/g,'"'+a.id+'"')+d);var e=Blockly.Python.valueToCode(a,"RETURN",Blockly.Python.ORDER_NONE)||"";e?e=" return "+e+"\n":d||(d=" pass");for(var g=[],f=0;f