feat(boards): python_mixpy下更新Turtle模块

增加screen.update、turtle.title和turtle.setup接口对应图形块
This commit is contained in:
王立帮
2026-01-04 04:08:41 +08:00
parent c4abb15ba7
commit 7d0a87fc09
6 changed files with 108 additions and 6 deletions

View File

@@ -437,6 +437,38 @@ export const turtle_bgcolor = {
}
};
export const turtle_title = {
init: function () {
this.setColour(TURTLE_HUE);
this.appendValueInput('TITLE')
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_TURTLE_TITLE_SET);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};
export const turtle_setup = {
init: function () {
this.setColour(TURTLE_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_TURTLE_SETUP_SET);
this.appendValueInput('WIDTH')
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_WIDTH);
this.appendValueInput('HEIGHT')
.setCheck(null)
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(Blockly.Msg.MIXLY_HEIGHT);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};
export const turtle_tracer = {
init: function () {
this.setColour(TURTLE_HUE);
@@ -825,6 +857,19 @@ export const turtle_getscreen = {
}
export const turtle_update = {
init: function () {
this.setColour(TURTLE_HUE);
this.appendValueInput('TUR');
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_TURTLE_UPDATE);
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setInputsInline(true);
this.setTooltip(Blockly.Msg.MIXLY_TURTEL_EVENT_ONKEY_TOOLTIP);
}
};
export const turtle_onkey = {
init: function () {
this.setColour(TURTLE_HUE);

View File

@@ -173,6 +173,21 @@ export const turtle_bgcolor = function (_, generator) {
return code;
}
export const turtle_title = function (_, generator) {
generator.definitions_.import_turtle = "import turtle";
const TITLE = generator.valueToCode(this, 'TITLE', generator.ORDER_ASSIGNMENT) || 'Mixly';
var code = `turtle.title(${TITLE})\n`;
return code;
}
export const turtle_setup = function (_, generator) {
generator.definitions_.import_turtle = "import turtle";
const WIDTH = generator.valueToCode(this, 'WIDTH', generator.ORDER_ASSIGNMENT) || '1';
const HEIGHT = generator.valueToCode(this, 'HEIGHT', generator.ORDER_ASSIGNMENT) || 'None';
var code = `turtle.setup(width=${WIDTH}, height=${HEIGHT})\n`;
return code;
}
export const turtle_tracer = function (_, generator) {
generator.definitions_.import_turtle = "import turtle";
const STEP = generator.valueToCode(this, 'STEP', generator.ORDER_ASSIGNMENT) || '1';
@@ -358,6 +373,13 @@ export const turtle_getscreen = function (_, generator) {
return code;
}
export const turtle_update = function (_, generator) {
generator.definitions_.import_turtle = "import turtle";
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
var code = `${varName}.update()\n`;
return code;
}
export const turtle_onkey = function (_, generator) {
generator.definitions_.import_turtle = "import turtle";
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';

View File

@@ -1911,13 +1911,22 @@
</shadow>
</value>
</block>
<block type="turtle_bgcolor_hex_new">
<value name="VAR">
<block type="turtle_color_seclet">
<field name="COLOR">#ff0000</field>
</block>
<block type="turtle_title">
<value name="TITLE">
<shadow type="text">
<field name="TEXT">#FF0000</field>
<field name="TEXT">Mixly</field>
</shadow>
</value>
</block>
<block type="turtle_setup">
<value name="WIDTH">
<shadow type="math_number">
<field name="NUM">800</field>
</shadow>
</value>
<value name="HEIGHT">
<shadow type="math_number">
<field name="NUM">600</field>
</shadow>
</value>
</block>
@@ -1934,6 +1943,16 @@
<block type="logic_null"></block>
</value>
</block>
<block type="turtle_bgcolor_hex_new">
<value name="VAR">
<block type="turtle_color_seclet">
<field name="COLOR">#ff0000</field>
</block>
<shadow type="text">
<field name="TEXT">#FF0000</field>
</shadow>
</value>
</block>
<block type="turtle_pencolor_hex_new">
<value name="TUR">
<shadow type="variables_get">
@@ -2061,6 +2080,13 @@
</shadow>
</value>
</block>
<block type="turtle_update">
<value name="TUR">
<shadow type="variables_get">
<field name="VAR">screen</field>
</shadow>
</value>
</block>
<block type="turtle_onkey">
<value name="TUR">
<shadow type="variables_get">