feat: sync all remaining python source board configurations
This commit is contained in:
370
mixly/boards/default_src/python_mixpy/blocks/ai.js
Normal file
370
mixly/boards/default_src/python_mixpy/blocks/ai.js
Normal file
@@ -0,0 +1,370 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const AI_HUE = 205;
|
||||
|
||||
export const AI_ChooseAndGet = {
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_CHOOSE_AND_GET)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_CHOOSE_AND_GET_ONE_FILE_NAME, "getOneFile"],
|
||||
[Blockly.Msg.MIXLY_CHOOSE_AND_GET_MANY_FILE_NAMES, "getManyFiles"],
|
||||
[Blockly.Msg.MIXLY_CHOOSE_AND_GET_DIR, "getDirectory"]
|
||||
]), 'TYPE');
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
}
|
||||
}
|
||||
|
||||
export const AI_client = {
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_SETUP)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_AipImageClassify, "AipImageClassify"],
|
||||
[Blockly.Msg.MIXLY_AipSpeech, "AipSpeech"],
|
||||
[Blockly.Msg.MIXLY_AipImageCensor, "AipImageCensor"],
|
||||
[Blockly.Msg.MIXLY_AipFace, "AipFace"],
|
||||
[Blockly.Msg.MIXLY_AipOcr, "AipOcr"],
|
||||
[Blockly.Msg.MIXLY_AipNlp, "AipNlp"]
|
||||
]), 'CTYPE')
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_Client)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('API_KEY')
|
||||
.appendField('API_KEY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('SECRET_KEY')
|
||||
.appendField('SECRET_KEY')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setInputsInline(false);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const AI_Speech_synthesis = { // AI_TYPE_FUNC
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_AipSpeech_synthesis)
|
||||
.appendField(Blockly.Msg.MIXLY_Client)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('STR')
|
||||
.appendField(Blockly.Msg.OLED_STRING)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('ATTR')
|
||||
.appendField(Blockly.Msg.MIXLY_AIP_ATTR)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_AipSpeech_synthesis_TOOLTIP)
|
||||
this.setInputsInline(false);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const AI_Speech_asr = { // AI_TYPE_FUNC
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_AipSpeech_asr)
|
||||
.appendField(Blockly.Msg.MIXLY_Client)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('FILE')
|
||||
.appendField(Blockly.Msg.MIXLY_AipSpeech_File)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('ATTR')
|
||||
.appendField(Blockly.Msg.MIXLY_AIP_ATTR)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_AipSpeech_ASR_TOOLTIP)
|
||||
this.setInputsInline(false);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const AI_ImageClassify = { // AI_TYPE_FUNC
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_AipImageClassify)
|
||||
.appendField(Blockly.Msg.MIXLY_Client)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('FUNC')
|
||||
.appendField(Blockly.Msg.MIXLY_AIP_FUNC)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('ADDR')
|
||||
.appendField(Blockly.Msg.MIXLY_AipImageClassify_Image)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('ATTR')
|
||||
.appendField(Blockly.Msg.MIXLY_AIP_ATTR)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_AipImageClassify_advancedGeneral_TOOLTIP)
|
||||
this.setInputsInline(false);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const AI_ImageClassify_Func = {
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_AipImageClassify_advancedGeneral, "advancedGeneral"],
|
||||
[Blockly.Msg.MIXLY_AipImageClassify_dishDetect, "dishDetect"],
|
||||
[Blockly.Msg.MIXLY_AipImageClassify_carDetect, "carDetect"],
|
||||
[Blockly.Msg.MIXLY_AipImageClassify_animalDetect, "animalDetect"],
|
||||
[Blockly.Msg.MIXLY_AipImageClassify_plantDetect, "plantDetect"],
|
||||
[Blockly.Msg.MIXLY_AipImageClassify_logoSearch, "logoSearch"]
|
||||
]), 'TYPE')
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const AI_Face_match = { // AI_TYPE_FUNC
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_AipFace_match)
|
||||
.appendField(Blockly.Msg.MIXLY_Client)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_AipImageClassify_Image + '1' + Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_THE_PATH)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('VAR2')
|
||||
.appendField(Blockly.Msg.MIXLY_AipImageClassify_Image + '2' + Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_THE_PATH)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('ATTR')
|
||||
.appendField(Blockly.Msg.MIXLY_AIP_ATTR)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_AipFace_match_TOOLTIP)
|
||||
this.setInputsInline(false);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const AI_Ocr = { // AI_TYPE_FUNC
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_AipOcr)
|
||||
.appendField(Blockly.Msg.MIXLY_Client)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('FUNC')
|
||||
.appendField(Blockly.Msg.MIXLY_AIP_FUNC)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('ADDR')
|
||||
.appendField(Blockly.Msg.MIXLY_AipImageClassify_Image)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('ATTR')
|
||||
.appendField(Blockly.Msg.MIXLY_AIP_ATTR)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_AipOcr_TOOLTIP)
|
||||
this.setInputsInline(false);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const AI_Ocr_Func = {
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_AipOcr_basicGeneral, "basicGeneral"],
|
||||
[Blockly.Msg.MIXLY_AipOcr_webImage, "webImage"],
|
||||
[Blockly.Msg.MIXLY_AipOcr_idcard, "idcard"],
|
||||
[Blockly.Msg.MIXLY_AipOcr_bankcard, "bankcard"],
|
||||
[Blockly.Msg.MIXLY_AipOcr_drivingLicense, "drivingLicense"],
|
||||
[Blockly.Msg.MIXLY_AipOcr_vehicleLicense, "vehicleLicense"],
|
||||
[Blockly.Msg.MIXLY_AipOcr_licensePlate, "licensePlate"],
|
||||
[Blockly.Msg.MIXLY_AipOcr_businessLicense, "businessLicense"],
|
||||
[Blockly.Msg.MIXLY_AipOcr_receipt, "receipt"],
|
||||
[Blockly.Msg.MIXLY_AipOcr_trainTicket, "trainTicket"],
|
||||
[Blockly.Msg.MIXLY_AipOcr_taxiReceipt, "taxiReceipt"],
|
||||
[Blockly.Msg.MIXLY_AipOcr_form, "tableRecognition"],
|
||||
[Blockly.Msg.MIXLY_AipOcr_vatInvoice, "vatInvoice"],
|
||||
[Blockly.Msg.MIXLY_AipOcr_passport, "passport"],
|
||||
[Blockly.Msg.MIXLY_AipOcr_handwriting, "handwriting"]
|
||||
]), 'TYPE')
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const AI_Nlp = { // AI_TYPE_FUNC
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_AipNlp)
|
||||
.appendField(Blockly.Msg.MIXLY_Client)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('FUNC')
|
||||
.appendField(Blockly.Msg.MIXLY_AIP_FUNC)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('STR')
|
||||
.appendField(Blockly.Msg.OLED_STRING)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('ATTR')
|
||||
.appendField(Blockly.Msg.MIXLY_AIP_ATTR)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_AipNlp_TOOLTIP)
|
||||
this.setInputsInline(false);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const AI_Nlp_Sim = { // AI_TYPE_FUNC
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_AipNlp_Sim)
|
||||
.appendField(Blockly.Msg.MIXLY_Client)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('FUNC')
|
||||
.appendField(Blockly.Msg.MIXLY_AIP_FUNC)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('STR1')
|
||||
.appendField(Blockly.Msg.OLED_STRING + '1')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('STR2')
|
||||
.appendField(Blockly.Msg.OLED_STRING + '2')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('ATTR')
|
||||
.appendField(Blockly.Msg.MIXLY_AIP_ATTR)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_AipNlp_Sim_TOOLTIP)
|
||||
this.setInputsInline(false);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const AI_Nlp_Func = {
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_AipNlp_lexer, "lexer"],
|
||||
[Blockly.Msg.MIXLY_AipNlp_depParser, "depParser"],
|
||||
[Blockly.Msg.MIXLY_AipNlp_wordEmbedding, "wordEmbedding"],
|
||||
[Blockly.Msg.MIXLY_AipNlp_dnnlm, "dnnlm"],
|
||||
[Blockly.Msg.MIXLY_AipNlp_commentTag, "commentTag"],
|
||||
[Blockly.Msg.MIXLY_AipNlp_sentimentClassify, "sentimentClassify"],
|
||||
[Blockly.Msg.MIXLY_AipNlp_keyword, "keyword"],
|
||||
[Blockly.Msg.MIXLY_AipNlp_topic, "topic"],
|
||||
[Blockly.Msg.MIXLY_AipNlp_ecnet, "ecnet"],
|
||||
[Blockly.Msg.MIXLY_AipNlp_emotion, "emotion"]
|
||||
]), 'TYPE')
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const AI_Nlp_Func_sim = {
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_AipNlp_wordSimEmbedding, "wordSimEmbedding"],
|
||||
[Blockly.Msg.MIXLY_AipNlp_simnet, "simnet"]
|
||||
]), 'TYPE')
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const AI_Nlp_Topic = { // AI_TYPE_FUNC
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_AipNlp_topic)
|
||||
.appendField(Blockly.Msg.MIXLY_Client)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('STR1')
|
||||
.appendField(Blockly.Msg.MIXLY_AipNlp_Topic_Title)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('STR2')
|
||||
.appendField(Blockly.Msg.MIXLY_AipNlp_Topic_Content)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_AipNlp_Topic_TOOLTIP)
|
||||
this.setInputsInline(false);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const AI_Nlp_newsSummary = { // AI_TYPE_FUNC
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_AipNlp_summary)
|
||||
.appendField(Blockly.Msg.MIXLY_Client)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('STR')
|
||||
.appendField(Blockly.Msg.MIXLY_AipNlp_Topic_Content)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('LEN')
|
||||
.appendField(Blockly.Msg.MIXLY_LIST_LEN)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('ATTR')
|
||||
.appendField(Blockly.Msg.MIXLY_AIP_ATTR)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_AipNlp_Summary_TOOLTIP)
|
||||
this.setInputsInline(false);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// [Blockly.Msg.MIXLY_AipNlp_topic, "topic"]
|
||||
// [Blockly.Msg.MIXLY_AipNlp_keyword, "keyword"]
|
||||
|
||||
export const AI_audio = {
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.MIXPY_AI_AUDIO);
|
||||
this.appendValueInput("TIME")
|
||||
.appendField(Blockly.Msg.MIXPY_AI_AUDIO_TIME);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXPY_AI_AUDIO_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const AI_photo = {
|
||||
init: function () {
|
||||
this.setColour(AI_HUE);
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.MIXPY_AI_PHOTO);
|
||||
this.appendValueInput("BUT")
|
||||
.appendField(Blockly.Msg.MIXPY_AI_PHOTO_BUTTON);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXPY_AI_PHOTO_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const AI_result = {
|
||||
/**
|
||||
* Block for negation.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
init: function () {
|
||||
|
||||
this.setColour(AI_HUE);
|
||||
|
||||
this.appendValueInput('AI')
|
||||
.appendField(Blockly.Msg.MIXPY_AI_RESULT)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_AipImageClassify, "Image"],
|
||||
[Blockly.Msg.MIXLY_AipSpeech_asr, "Speech"],
|
||||
[Blockly.Msg.MIXLY_AipFace_match, "Face"],
|
||||
[Blockly.Msg.MIXLY_AipOcr, "Ocr"],
|
||||
[Blockly.Msg.MIXLY_AipNlp_simnet, "OcrSimilarity"],
|
||||
[Blockly.Msg.MIXLY_AipNlp_sentimentClassify, "Emotion"],
|
||||
]), 'CTYPE')
|
||||
|
||||
this.setOutput(true);
|
||||
this.setTooltip(Blockly.Msg.LOGIC_NEGATE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
835
mixly/boards/default_src/python_mixpy/blocks/algorithm.js
Normal file
835
mixly/boards/default_src/python_mixpy/blocks/algorithm.js
Normal file
@@ -0,0 +1,835 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const ALGORITHM_HUE = '#526FC3';
|
||||
|
||||
// sub_algorithm_1
|
||||
|
||||
export const algorithm_prepare = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_PREPARE);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_add_school = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_ADD_SCHOOL);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_find_path = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_FIND_PATH);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_new_path = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_NEW_PATH);
|
||||
this.setOutput(true);
|
||||
}
|
||||
}
|
||||
|
||||
export const algorithm_set_path = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_SET_PATH);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_add_path = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_ADD_PATH);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_del_path = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_DEL_PATH);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_return_path = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_RETURN_PATH);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_no_left = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_NO_LEFT);
|
||||
this.setOutput(true);
|
||||
}
|
||||
}
|
||||
|
||||
export const algorithm_print_path = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_PRINT_PATH);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
// sub_algorithm_2
|
||||
|
||||
export const algorithm_prepare2 = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_PREPARE2);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_current_school = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_CURRENT_SCHOOL);
|
||||
this.setOutput(true);
|
||||
}
|
||||
}
|
||||
|
||||
export const algorithm_no_path = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_NO_PATH);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
// sub_algorithm_3
|
||||
|
||||
export const algorithm_prepare_2_1 = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_PREPARE_2_1);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_prepare_2_2 = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_PREPARE_2_2);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_move_recent = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_MOVE_RECENT);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_not_home = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_NOT_HOME);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_not_school = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_NOT_SCHOOL);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_print_path2 = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_PRINT_PATH2);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
// sub_algorithm_4 hanoi
|
||||
|
||||
export const hanoi_init = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("准备")
|
||||
.appendField(new Blockly.FieldNumber(3, 0, 100, 1), "NUM")
|
||||
.appendField("层汉诺塔");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const hanoi_move = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("移动圆盘从");
|
||||
this.appendValueInput("FROM_NUM")
|
||||
.setCheck(null)
|
||||
.appendField("柱");
|
||||
this.appendDummyInput()
|
||||
.appendField("到");
|
||||
this.appendValueInput("TO_NUM")
|
||||
.setCheck(null)
|
||||
.appendField("柱");
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
// sub_algorithm_5
|
||||
|
||||
export const algorithm_all_books = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_ALL_BOOKS);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_all_books_sequence = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_ALL_BOOKS2);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_first_book = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_FIRST_BOOK);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
// export const algorithm_no_ring = {
|
||||
// init: function() {
|
||||
// this.setColour(ALGORITHM_HUE);
|
||||
// this.appendDummyInput()
|
||||
// .appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_NO_RING);
|
||||
// this.setOutput(true);
|
||||
// }
|
||||
// }
|
||||
|
||||
export const algorithm_no_ring2 = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_NO_RING);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_yes_ring2 = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_YES_RING);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_next_book = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_NEXT_BOOK);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_two_left = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_TWO_LEFT);
|
||||
this.setOutput(true);
|
||||
}
|
||||
}
|
||||
|
||||
export const algorithm_divide_books = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_DIVIDE_BOOKS);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_get_half_books = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_GET_HALF_BOOKS);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
// export const algorithm_check_half_books = {
|
||||
// init: function() {
|
||||
// this.setColour(ALGORITHM_HUE);
|
||||
// this.appendDummyInput()
|
||||
// .appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_CHECK_HALF_BOOKS);
|
||||
// this.setPreviousStatement(true, null);
|
||||
// this.setNextStatement(true, null);
|
||||
// }
|
||||
// };
|
||||
|
||||
export const algorithm_delete_book = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_DELETE_BOOK);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_delete_books = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_DELETE_BOOKS);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_delete_books2 = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_DELETE_BOOKS2);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
// export const algorithm_print_book = {
|
||||
// init: function() {
|
||||
// this.setColour(ALGORITHM_HUE);
|
||||
// this.appendDummyInput()
|
||||
// .appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_PRINT_BOOK);
|
||||
// this.setPreviousStatement(true, null);
|
||||
// this.setNextStatement(true, null);
|
||||
// }
|
||||
// };
|
||||
|
||||
export const algorithm_print_book2 = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_PRINT_BOOK);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
// sub_algorithm_6
|
||||
|
||||
export const algorithm_book_scale = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("设置待查书总数 N=")
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
["5", "5"],
|
||||
["10", "10"],
|
||||
["20", "20"],
|
||||
["50", "50"]
|
||||
]), "NUM");
|
||||
this.setInputsInline(false);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_number_zero = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_NUMBER_ZERO);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_number_add = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_NUMBER_ADD);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_print_number = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_PRINT_NUMBER);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_get_book_num = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField('n' + Blockly.Msg.MIXLY_VALUE2)
|
||||
.appendField(new Blockly.FieldTextInput('50'), 'NUM');
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_print_sequence = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_PRINT_SEQUENCE);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_print_divide = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_PRINT_DIVIDE);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
// sub_algorithm_7
|
||||
|
||||
export const algorithm_init_jttl = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("初始化鸡兔同笼问题:");
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("有若干只鸡、兔在同一个笼子里。");
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("从上面数鸡兔有10个头,");
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("从下面数鸡兔有32只脚。");
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("问笼中有多少只鸡和多少只兔?");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_rabbit_zero = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("假设兔子的数量为0只");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_rabbit_number_in_range = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("兔子的数量在范围之内");
|
||||
this.setOutput(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_chick_calculate = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("根据(头数-兔子数)计算出鸡的数量");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_check_feet = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("计算得到脚的数量正确");
|
||||
this.setOutput(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_print_jttl_answer = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("输出鸡、兔的数量");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_rabbit_add = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("假设兔子数量要更多一只");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
// sub_algorithm_8
|
||||
|
||||
export const algorithm_init_fzsf = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("加载路线图");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_fz_calc = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("计算")
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
["S1", "1"],
|
||||
["S2", "2"],
|
||||
["S3", "3"],
|
||||
["S4", "4"]
|
||||
]), "PATHNAME")
|
||||
.appendField("长度");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_fz_calc_first_min = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("设置S1为Smin");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_fz_compare = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
["S1", "1"],
|
||||
["S2", "2"],
|
||||
["S3", "3"],
|
||||
["S4", "4"]
|
||||
]), "PATHNAME")
|
||||
.appendField("的长度比")
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
["S1", "1"],
|
||||
["S2", "2"],
|
||||
["S3", "3"],
|
||||
["S4", "4"]
|
||||
]), "PATHNAME2")
|
||||
.appendField("短");
|
||||
this.setOutput(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_fz_set_min = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("设置")
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
["S1", "1"],
|
||||
["S2", "2"],
|
||||
["S3", "3"],
|
||||
["S4", "4"]
|
||||
]), "PATHNAME")
|
||||
.appendField("为Smin");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_fz_move = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("按照Smin移动");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
// sub_algorithm_8
|
||||
|
||||
export const algorithm_init_hxdb = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("初始化韩信点兵问题:");
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("有未知数量的若干士兵。");
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("若3人一排列队,多1人;");
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("若5人一排列队,多2人;");
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("若7人一排列队,多2人;");
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("问士兵的数量最少是多少人?");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_hxdb_init_soldier = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("初始化士兵为")
|
||||
.appendField(new Blockly.FieldTextInput("7"), "NUM")
|
||||
.appendField("个");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_hxdb_stand_in_line = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("使士兵")
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
["3", "3"],
|
||||
["5", "5"],
|
||||
["7", "7"]
|
||||
]), "NUM")
|
||||
.appendField("人一排列队");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_hxdb_last_line = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("剩余")
|
||||
.appendField(new Blockly.FieldTextInput("1"), "NUM")
|
||||
.appendField("个士兵");
|
||||
this.setOutput(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_hxdb_add = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("增加1个士兵");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_hxdb_result = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.LEFT)
|
||||
.appendField("输出士兵数量");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
// others
|
||||
|
||||
export const hanoi_init_offline = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("准备")
|
||||
.appendField(new Blockly.FieldNumber(3, 0, 100, 1), "NUM")
|
||||
.appendField("层汉诺塔");
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.HTML_COLOUR);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_get_current_location = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_GET_CURRENT_LOCATION);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const algorithm_void_path = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_ALGORITHM_VOID_PATH);
|
||||
this.setOutput(true);
|
||||
}
|
||||
}
|
||||
|
||||
export const algorithm_color_seclet = {
|
||||
init: function () {
|
||||
this.setColour(ALGORITHM_HUE);
|
||||
this.appendDummyInput("")
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(new Blockly.FieldColour("ff0000"), "COLOR");
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, String);
|
||||
}
|
||||
};
|
||||
121
mixly/boards/default_src/python_mixpy/blocks/communicate.js
Normal file
121
mixly/boards/default_src/python_mixpy/blocks/communicate.js
Normal file
@@ -0,0 +1,121 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const COMMUNICATE_HUE = '#3288dd'; //'#3288dd';
|
||||
|
||||
export const requests_get_old = {
|
||||
init: function () {
|
||||
this.setColour(COMMUNICATE_HUE);
|
||||
this.appendValueInput("DOMAIN")
|
||||
.appendField(Blockly.Msg.DISPLAY_IMAGE_LET2)
|
||||
.setCheck(String);
|
||||
this.appendDummyInput("")
|
||||
|
||||
.appendField(Blockly.Msg.blockpy_REQUESTS_GET)
|
||||
.appendField(new Blockly.FieldTextInput('response'), 'VAR')
|
||||
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.blockpy_REQUESTS_GET_TOOLTIP);
|
||||
},
|
||||
getVars: function () {
|
||||
return [this.getFieldValue('VAR')];
|
||||
},
|
||||
renameVar: function (oldName, newName) {
|
||||
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
|
||||
this.setTitleValue(newName, 'VAR');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const requests_get = {
|
||||
init: function () {
|
||||
this.setColour(COMMUNICATE_HUE);
|
||||
this.appendValueInput("URL")
|
||||
.appendField(Blockly.Msg.DISPLAY_IMAGE_LET2)
|
||||
.setCheck(String);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.blockpy_CONDUCT)
|
||||
.appendField(new Blockly.FieldDropdown([["get", "get"], ["head", "head"], ["delete", "delete"]]), 'TYPE')
|
||||
.appendField(Blockly.Msg.blockpy_REQUESTS)
|
||||
.appendField(Blockly.Msg.MIXPY_REQUESTS_GET_RESULT)
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
this.setTooltip("");
|
||||
},
|
||||
}
|
||||
|
||||
export const requests_post = {
|
||||
init: function () {
|
||||
this.setColour(COMMUNICATE_HUE);
|
||||
this.appendValueInput("URL")
|
||||
.appendField(Blockly.Msg.DISPLAY_IMAGE_LET2)
|
||||
.setCheck(String);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.blockpy_CONDUCT)
|
||||
.appendField(new Blockly.FieldDropdown([["post", "post"], ["put", "put"], ["patch", "patch"]]), 'TYPE')
|
||||
.appendField(Blockly.Msg.blockpy_REQUESTS)
|
||||
this.appendValueInput("data")
|
||||
.appendField(Blockly.Msg.blockpy_REQUESTS + Blockly.Msg.OLED_STRING)
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXPY_REQUESTS_GET_RESULT)
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
this.setTooltip("");
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
export const requests_attribute = {
|
||||
init: function () {
|
||||
this.appendValueInput('VAL')
|
||||
|
||||
var attr = [
|
||||
[Blockly.Msg.blockpy_REQUESTS_GET_ATTR_STATUS_CODE, 'status_code'], [Blockly.Msg.blockpy_REQUESTS_GET_ATTR_TEXT, 'text'],
|
||||
[Blockly.Msg.blockpy_REQUESTS_GET_ATTR_COOKIES, 'cookies'], [Blockly.Msg.blockpy_REQUESTS_GET_ATTR_CONTENT, 'content'],
|
||||
[Blockly.Msg.MIXPY_TEXT_ENCODE, 'encoding']
|
||||
];
|
||||
this.setColour(COMMUNICATE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_GET)
|
||||
.appendField(new Blockly.FieldDropdown(attr), 'ATTR')
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, String);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
export const requests_method = {
|
||||
init: function () {
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.DISPLAY_IMAGE_LET2)
|
||||
.setCheck(String);
|
||||
var method = [
|
||||
['post', 'post'], ['put', 'put'],
|
||||
['delete', 'delete'], ['head', 'head'],
|
||||
['option', 'option']
|
||||
];
|
||||
this.setColour(COMMUNICATE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.blockpy_CONDUCT)
|
||||
.appendField(new Blockly.FieldDropdown(method), 'DIR')
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.blockpy_REQUESTS)
|
||||
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'forward': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_FORWARD,
|
||||
'backward': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_BACKWARD
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
206
mixly/boards/default_src/python_mixpy/blocks/cv.js
Normal file
206
mixly/boards/default_src/python_mixpy/blocks/cv.js
Normal file
@@ -0,0 +1,206 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const CV_HUE = "f0a559";
|
||||
|
||||
export const cv_read_image = {
|
||||
init: function () {
|
||||
this.setColour(CV_HUE);
|
||||
this.appendValueInput("FILE")
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_CV_IMREAD);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(false);
|
||||
this.setNextStatement(false);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const cv_show_image = {
|
||||
init: function () {
|
||||
this.setColour(CV_HUE);
|
||||
this.appendValueInput("FILE")
|
||||
.appendField(Blockly.Msg.OLED_BITMAP);
|
||||
this.appendValueInput('data')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_AipNlp_Topic_Title);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
}
|
||||
}
|
||||
|
||||
export const cv_write_image = {
|
||||
init: function () {
|
||||
this.setColour(CV_HUE);
|
||||
this.appendValueInput("FILE")
|
||||
.appendField(Blockly.Msg.MIXLY_CV_IMWRITE);
|
||||
this.appendValueInput('data')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.HTML_NAME);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
}
|
||||
}
|
||||
|
||||
export const cv_waitkey = {
|
||||
init: function () {
|
||||
this.setColour(CV_HUE);
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_DELAY);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MILLIS + Blockly.Msg.MIXLY_CV_OR_PRESS)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_CV_WAITKEY_TOOLTIP)
|
||||
}
|
||||
}
|
||||
|
||||
export const cv_destroy_all = {
|
||||
init: function () {
|
||||
this.setColour(CV_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_CV_DESTROY_ALL)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
}
|
||||
}
|
||||
|
||||
export const cv_line_rect = {
|
||||
init: function () {
|
||||
this.setColour(CV_HUE);
|
||||
this.appendValueInput("FILE")
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_IMAGE);
|
||||
var line_rect =
|
||||
[[Blockly.Msg.MIXLY_CV_RECT, 'rectangle'], [Blockly.Msg.MIXLY_CV_LINE, 'line']];
|
||||
|
||||
this.appendValueInput('x1')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_DISPLAY_DRAW)
|
||||
.appendField(new Blockly.FieldDropdown(line_rect), 'DIR')
|
||||
.appendField(Blockly.Msg.MIXLY_CV_DRAWLINE_BEGIN + '(x1')
|
||||
this.appendValueInput('y1')
|
||||
.setCheck(Number)
|
||||
.appendField(',y1');
|
||||
this.appendValueInput('x2')
|
||||
.setCheck(Number)
|
||||
.appendField(') ' + Blockly.Msg.MIXLY_CV_DRAWLINE_END + '(x2');
|
||||
this.appendValueInput('y2')
|
||||
.setCheck(Number)
|
||||
.appendField(',y2');
|
||||
this.appendDummyInput()
|
||||
.appendField(') ' + Blockly.Msg.MIXLY_CV_DRAWLINE_COLOR)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME');
|
||||
this.appendValueInput('thick')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_CV_DRAWLINE_THICKNESS);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_CV_DRAWLINE_RECT_TOOLTIP)
|
||||
}
|
||||
}
|
||||
|
||||
export const cv_text = {
|
||||
init: function () {
|
||||
this.setColour(CV_HUE);
|
||||
this.appendValueInput("FILE")
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_IMAGE);
|
||||
var font =
|
||||
[['SIMPLEX', 'SIMPLEX'], ['PLAIN', 'PLAIN'], ['DUPLEX', 'DUPLEX'], ['COMPLEX', 'COMPLEX'], ['COMPLEX_SMALL', 'COMPLEX_SMALL'], ['TRIPLEX', 'TRIPLEX'], ['SCRIPT_SIMPLEX', 'SCRIPT_SIMPLEX'], ['SCRIPT_COMPLEX', 'SCRIPT_COMPLEX'],];
|
||||
this.appendValueInput('data')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_CV_DRAWTEXT);
|
||||
this.appendValueInput('x1')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_CV_DRAWLINE_BEGIN + '(x1')
|
||||
this.appendValueInput('y1')
|
||||
.setCheck(Number)
|
||||
.appendField(',y1');
|
||||
this.appendDummyInput()
|
||||
.appendField(') ' + Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NAME)
|
||||
.appendField(new Blockly.FieldDropdown(font), 'font');
|
||||
this.appendValueInput('size')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NUM);
|
||||
this.appendDummyInput()
|
||||
.appendField(') ' + Blockly.Msg.MIXLY_CV_DRAWLINE_COLOR)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME');
|
||||
this.appendValueInput('thick')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_CV_DRAWLINE_THICKNESS);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_CV_DRAWLINE_RECT_TOOLTIP)
|
||||
}
|
||||
}
|
||||
|
||||
export const cv_face_classifier = {
|
||||
init: function () {
|
||||
this.setColour(CV_HUE);
|
||||
this.appendValueInput("FILE")
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_CV_FACE_CLASSIFIER);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(false);
|
||||
this.setNextStatement(false);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const cv_face_detect = {
|
||||
init: function () {
|
||||
this.setColour(CV_HUE);
|
||||
this.appendValueInput("FILE")
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_IMAGE);
|
||||
this.appendValueInput("FACE")
|
||||
.appendField(Blockly.Msg.MIXLY_CV_FACE_DETECT);
|
||||
this.appendValueInput('SCALE')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_CV_FACE_DETECT_SCALE)
|
||||
this.appendValueInput('NEIGHBOR')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_CV_FACE_DETECT_NEIGHBOR)
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(false);
|
||||
this.setNextStatement(false);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const cv_face_detect_all = {
|
||||
init: function () {
|
||||
this.setColour(CV_HUE);
|
||||
this.appendValueInput("FILE")
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_IMAGE);
|
||||
this.appendValueInput("FACE")
|
||||
.appendField(Blockly.Msg.MIXLY_CV_FACE_DETECT);
|
||||
this.appendValueInput('SCALE')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_CV_FACE_DETECT_SCALE)
|
||||
this.appendValueInput('NEIGHBOR')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_CV_FACE_DETECT_NEIGHBOR)
|
||||
this.appendValueInput('x1')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_CV_FACE_DETECT_RANGE)
|
||||
.appendField(Blockly.Msg.blockpy_TUPLE_MIN)
|
||||
this.appendValueInput('y1')
|
||||
.setCheck(Number)
|
||||
.appendField('×')
|
||||
this.appendValueInput('x2')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_TUPLE_MAX)
|
||||
this.appendValueInput('y2')
|
||||
.setCheck(Number)
|
||||
.appendField('×')
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(false);
|
||||
this.setNextStatement(false);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
1570
mixly/boards/default_src/python_mixpy/blocks/data.js
Normal file
1570
mixly/boards/default_src/python_mixpy/blocks/data.js
Normal file
File diff suppressed because it is too large
Load Diff
355
mixly/boards/default_src/python_mixpy/blocks/datastructure.js
Normal file
355
mixly/boards/default_src/python_mixpy/blocks/datastructure.js
Normal file
@@ -0,0 +1,355 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const DS_HUE = 80;
|
||||
|
||||
export const ds_create_linkedlist = {
|
||||
|
||||
/**
|
||||
* Block for creating a list with any number of elements of any type.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
|
||||
init: function () {
|
||||
this.setColour(DS_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldLabel(Blockly.Msg.DS_CREATE_LINKEDLIST_NEW))
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldLabel(Blockly.Msg.DS_CREATE_LINKEDLIST_HEAD))
|
||||
.appendField(new Blockly.FieldTextInput('head'), 'VAR')
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldLabel(Blockly.Msg.DS_CREATE_LINKEDLIST_TYPE))
|
||||
.appendField(new Blockly.FieldTextInput('tag'), 'TYPE')
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.DS_CREATE_LINKEDLIST_ATTRIBUTE);
|
||||
this.itemCount_ = 1;
|
||||
this.updateShape_();
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setMutator(new Blockly.icons.MutatorIcon(['ds_create_linkedlist_item'], this));
|
||||
this.setTooltip(Blockly.Msg.DS_CREATE_LINKEDLIST_TOOLTIP);
|
||||
},
|
||||
|
||||
/**
|
||||
* Create XML to represent list inputs.
|
||||
* @return {Element} XML storage element.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
|
||||
mutationToDom: function () {
|
||||
var container = document.createElement('mutation');
|
||||
container.setAttribute('items', this.itemCount_);
|
||||
return container;
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse XML to restore the list inputs.
|
||||
* @param {!Element} xmlElement XML storage element.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
|
||||
domToMutation: function (xmlElement) {
|
||||
this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
|
||||
this.updateShape_();
|
||||
},
|
||||
|
||||
/**
|
||||
* Populate the mutator's dialog with this block's components.
|
||||
* @param {!Blockly.Workspace} workspace Mutator's workspace.
|
||||
* @return {!Blockly.Block} Root block in mutator.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
|
||||
decompose: function (workspace) {
|
||||
var containerBlock =
|
||||
workspace.newBlock('ds_create_linkedlist_container');
|
||||
containerBlock.initSvg();
|
||||
var connection = containerBlock.getInput('STACK').connection;
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
var itemBlock = workspace.newBlock('ds_create_linkedlist_item');
|
||||
itemBlock.initSvg();
|
||||
connection.connect(itemBlock.previousConnection);
|
||||
connection = itemBlock.nextConnection;
|
||||
}
|
||||
return containerBlock;
|
||||
},
|
||||
|
||||
/**
|
||||
* Reconfigure this block based on the mutator dialog's components.
|
||||
* @param {!Blockly.Block} containerBlock Root block in mutator.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
|
||||
compose: function (containerBlock) {
|
||||
var itemBlock = containerBlock.getInputTargetBlock('STACK');
|
||||
|
||||
// Count number of inputs.
|
||||
var connections = [];
|
||||
var i = 0;
|
||||
while (itemBlock) {
|
||||
connections[i] = itemBlock.valueConnection_;
|
||||
itemBlock = itemBlock.nextConnection &&
|
||||
itemBlock.nextConnection.targetBlock();
|
||||
i++;
|
||||
}
|
||||
|
||||
this.itemCount_ = i;
|
||||
this.updateShape_();
|
||||
// Reconnect any child blocks.
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
if (connections[i]) {
|
||||
this.getInput('ADD' + i).connection.connect(connections[i]);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Store pointers to any connected child blocks.
|
||||
* @param {!Blockly.Block} containerBlock Root block in mutator.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
|
||||
saveConnections: function (containerBlock) {
|
||||
var itemBlock = containerBlock.getInputTargetBlock('STACK');
|
||||
var i = 0;
|
||||
while (itemBlock) {
|
||||
var input = this.getInput('ADD' + i);
|
||||
itemBlock.valueConnection_ = input && input.connection.targetConnection;
|
||||
i++;
|
||||
itemBlock = itemBlock.nextConnection &&
|
||||
itemBlock.nextConnection.targetBlock();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Modify this block to have the correct number of inputs.
|
||||
* @private
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
|
||||
updateShape_: function () {
|
||||
// Delete everything.
|
||||
if (this.getInput('EMPTY')) {
|
||||
this.removeInput('EMPTY');
|
||||
}
|
||||
|
||||
var keyNames = [];
|
||||
for (var i = 0; this.getInput('ADD' + i); i++) {
|
||||
//this.getInput('VALUE' + i).removeField("KEY"+i);
|
||||
keyNames.push(this.getFieldValue("KEY" + i))
|
||||
this.removeInput('ADD' + i);
|
||||
}
|
||||
// Rebuild block.
|
||||
//if (this.itemCount_ == 0) {
|
||||
// this.getField('TIP').setText(Blockly.Msg.DICTS_CREATE_EMPTY_TITLE);
|
||||
// } else {
|
||||
// this.getField('TIP').setText(Blockly.Msg.DS_CREATE_LINKEDLIST_NEW);
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
this.appendValueInput('ADD' + i)
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(
|
||||
new Blockly.FieldTextInput(keyNames.length > i
|
||||
? keyNames[i]
|
||||
: 'name'),
|
||||
'KEY' + i)
|
||||
.appendField("=")
|
||||
|
||||
}
|
||||
}, getVars: function () {
|
||||
return [this.getFieldValue('VAR')];
|
||||
},
|
||||
renameVar: function (oldName, newName) {
|
||||
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
|
||||
this.setTitleValue(newName, 'VAR');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
export const ds_create_linkedlist_container = {
|
||||
|
||||
/**
|
||||
* Mutator block for list container.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
init: function () {
|
||||
this.setColour(DS_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.DS_CREATE_LINKEDLIST_CONTAINER_TITLE);
|
||||
this.appendStatementInput('STACK');
|
||||
this.setTooltip(Blockly.Msg.DS_CREATE_LINKEDLIST_CONTAINER_TOOLTIP);
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
|
||||
export const ds_create_linkedlist_item = {
|
||||
/**
|
||||
* Mutator bolck for adding items.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
init: function () {
|
||||
this.setColour(DS_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.DS_CREATE_LINKEDLIST_ITEM_TITLE);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.DS_CREATE_LINKEDLIST_ITEM_TOOLTIP);
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const ds_create_node = {
|
||||
init: function () {
|
||||
this.setColour(DS_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.DS_CREATE_NODE_USE)
|
||||
.appendField(new Blockly.FieldTextInput('tag'), 'TYPE')
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.DS_CREATE_NODE_NEW)
|
||||
this.appendValueInput('NODE')
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.DS_CREATE_NODE_TOOLTIP);
|
||||
}
|
||||
}
|
||||
|
||||
export const ds_get_node_attr = {
|
||||
init: function () {
|
||||
this.setColour(DS_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.DS_GET_NODE_ATTR_NODE)
|
||||
this.appendValueInput('NODE')
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_AIP_ATTR)
|
||||
.appendField(new Blockly.FieldTextInput('name'), 'TYPE')
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.DICTS_ADD_VALUE)
|
||||
this.setOutput(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.DS_GET_NODE_ATTR_TOOLTIP);
|
||||
}
|
||||
}
|
||||
|
||||
export const ds_set_node_attr = {
|
||||
init: function () {
|
||||
this.setColour(DS_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.DS_SET_NODE_ATTR_NODE)
|
||||
this.appendValueInput('NODE')
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_AIP_ATTR)
|
||||
.appendField(new Blockly.FieldTextInput('name'), 'TYPE')
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.DS_SET_NODE_ATTR_SET)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.DS_SET_NODE_ATTR_TOOLTIP);
|
||||
}
|
||||
}
|
||||
|
||||
export const ds_add_node_by_name = {
|
||||
init: function () {
|
||||
this.setColour(DS_HUE);
|
||||
this.appendValueInput('NODE')
|
||||
.appendField(Blockly.Msg.DS_ADD_NODE_HEAD_NODE)
|
||||
var pos =
|
||||
[[Blockly.Msg.DS_ADD_NODE_BEFORE, 'before'], [Blockly.Msg.DS_ADD_NODE_AFTER, 'after']];
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.DS_ADD_NODE_LINKEDLIST)
|
||||
this.appendValueInput('NODE2')
|
||||
.appendField(Blockly.Msg.DS_SET_NODE_ATTR_NODE)
|
||||
this.appendValueInput('NODE3')
|
||||
.appendField(new Blockly.FieldDropdown(pos), 'DIR')
|
||||
.appendField(Blockly.Msg.DS_ADD_NODE)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.DS_ADD_NODE_TOOLTIP);
|
||||
}
|
||||
}
|
||||
|
||||
export const ds_add_node_by_attr = {
|
||||
init: function () {
|
||||
this.setColour(DS_HUE);
|
||||
this.appendValueInput('NODE')
|
||||
.appendField(Blockly.Msg.DS_ADD_NODE_HEAD_NODE)
|
||||
var pos =
|
||||
[[Blockly.Msg.DS_ADD_NODE_BEFORE, 'before'], [Blockly.Msg.DS_ADD_NODE_AFTER, 'after']];
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.DS_ADD_NODE_LINKEDLIST)
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.DS_CREATE_LINKEDLIST_ITEM_TITLE)
|
||||
.appendField(new Blockly.FieldTextInput('name'), 'TYPE')
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_AS)
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.DS_ADD_NODE_ATTR)
|
||||
this.appendValueInput('NODE3')
|
||||
.appendField(new Blockly.FieldDropdown(pos), 'DIR')
|
||||
.appendField(Blockly.Msg.DS_ADD_NODE)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.DS_ADD_NODE_TOOLTIP);
|
||||
}
|
||||
}
|
||||
|
||||
export const ds_del_node_by_name = {
|
||||
init: function () {
|
||||
this.setColour(DS_HUE);
|
||||
this.appendValueInput('NODE')
|
||||
.appendField(Blockly.Msg.DS_ADD_NODE_HEAD_NODE)
|
||||
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.DS_ADD_NODE_LINKEDLIST)
|
||||
this.appendValueInput('NODE2')
|
||||
.appendField(Blockly.Msg.DS_DEL_NODE_NAME)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.DS_DEL_NODE_TOOLTIP);
|
||||
}
|
||||
}
|
||||
|
||||
export const ds_del_node_by_attr = {
|
||||
init: function () {
|
||||
this.setColour(DS_HUE);
|
||||
this.appendValueInput('NODE')
|
||||
.appendField(Blockly.Msg.DS_ADD_NODE_HEAD_NODE)
|
||||
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.DS_ADD_NODE_LINKEDLIST)
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.DS_DEL_NODE_ATTR)
|
||||
.appendField(new Blockly.FieldTextInput('name'), 'TYPE')
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_AS)
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.DS_ADD_NODE_ATTR)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.DS_DEL_NODE_TOOLTIP);
|
||||
}
|
||||
}
|
||||
|
||||
export const ds_reverse_linkedlist = {
|
||||
init: function () {
|
||||
this.setColour(DS_HUE);
|
||||
this.appendValueInput('NODE')
|
||||
.appendField(Blockly.Msg.DS_ADD_NODE_HEAD_NODE)
|
||||
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.DS_REVERSE_LINKEDLIST)
|
||||
this.appendValueInput('NODE2')
|
||||
.appendField(Blockly.Msg.DS_REVERSE_LINKEDLIST_NEW_HEAD)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.DS_DEL_NODE_TOOLTIP);
|
||||
}
|
||||
}
|
||||
273
mixly/boards/default_src/python_mixpy/blocks/factory.js
Normal file
273
mixly/boards/default_src/python_mixpy/blocks/factory.js
Normal file
@@ -0,0 +1,273 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const FACTORY_HUE = "#777777"; //65;
|
||||
|
||||
export const factory_from_import = {
|
||||
init: function () {
|
||||
this.setColour(FACTORY_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField("from ")
|
||||
.appendField(new Blockly.FieldTextInput('ESP32'), 'path')
|
||||
.appendField(" import ")
|
||||
.appendField(new Blockly.FieldTextInput('*'), 'module');
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const factory_import = {
|
||||
init: function () {
|
||||
this.setColour(FACTORY_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField("import ")
|
||||
.appendField(new Blockly.FieldTextInput('module'), 'module');
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const factory_function_noreturn = {
|
||||
init: function () {
|
||||
//console.log('init');
|
||||
this.setColour(FACTORY_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldTextInput('my_function'), 'NAME');
|
||||
this.itemCount_ = 1;
|
||||
this.arguments_ = ['x'];//add
|
||||
this.updateShape_();
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setMutator(new Blockly.icons.MutatorIcon(['factory_create_with_item'], this));
|
||||
},
|
||||
mutationToDom: function () {
|
||||
//console.log('mutationToDom');
|
||||
var container = document.createElement('mutation');
|
||||
container.setAttribute('items', this.itemCount_);
|
||||
//add
|
||||
for (var i = 0; i < this.arguments_.length; i++) {
|
||||
var parameter = document.createElement('arg');
|
||||
parameter.setAttribute('name', this.arguments_[i]);
|
||||
container.appendChild(parameter);
|
||||
}
|
||||
return container;
|
||||
},
|
||||
domToMutation: function (xmlElement) {
|
||||
//console.log('domToMutation');
|
||||
this.arguments_ = [];//add
|
||||
//add
|
||||
for (var i = 0; xmlElement.childNodes[i]; i++) {
|
||||
let childNode = xmlElement.childNodes[i];
|
||||
if (childNode.nodeName.toLowerCase() == 'arg') {
|
||||
this.arguments_.push(childNode.getAttribute('name'));
|
||||
}
|
||||
}
|
||||
this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
|
||||
this.updateShape_();
|
||||
},
|
||||
decompose: function (workspace) {
|
||||
//console.log('decompose');
|
||||
var containerBlock =
|
||||
workspace.newBlock('factory_create_with_container');
|
||||
containerBlock.initSvg();
|
||||
var connection = containerBlock.getInput('STACK').connection;
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
var itemBlock = workspace.newBlock('factory_create_with_item');
|
||||
itemBlock.initSvg();
|
||||
itemBlock.setFieldValue(this.arguments_[i], 'NAME');//add
|
||||
connection.connect(itemBlock.previousConnection);
|
||||
connection = itemBlock.nextConnection;
|
||||
}
|
||||
return containerBlock;
|
||||
},
|
||||
compose: function (containerBlock) {
|
||||
//console.log('compose');
|
||||
this.arguments_ = [];//add
|
||||
var itemBlock = containerBlock.getInputTargetBlock('STACK');
|
||||
// Count number of inputs.
|
||||
var connections = [];
|
||||
var i = 0;
|
||||
while (itemBlock) {
|
||||
this.arguments_.push(itemBlock.getFieldValue('NAME'));//add
|
||||
connections[i] = itemBlock.valueConnection_;
|
||||
itemBlock = itemBlock.nextConnection &&
|
||||
itemBlock.nextConnection.targetBlock();
|
||||
i++;
|
||||
}
|
||||
this.itemCount_ = i;
|
||||
this.updateShape_();
|
||||
// Reconnect any child blocks.
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
if (connections[i]) {
|
||||
this.getInput('ADD' + i)
|
||||
.connection.connect(connections[i]);
|
||||
}
|
||||
}
|
||||
},
|
||||
saveConnections: function (containerBlock) {
|
||||
//console.log('saveConnections');
|
||||
var itemBlock = containerBlock.getInputTargetBlock('STACK');
|
||||
var i = 0;
|
||||
while (itemBlock) {
|
||||
var input = this.getInput('ADD' + i);
|
||||
itemBlock.valueConnection_ = input && input.connection.targetConnection;
|
||||
i++;
|
||||
itemBlock = itemBlock.nextConnection &&
|
||||
itemBlock.nextConnection.targetBlock();
|
||||
}
|
||||
},
|
||||
updateShape_: function () {
|
||||
//console.log('updateShape_');
|
||||
// Delete everything.
|
||||
if (this.getInput('EMPTY')) {
|
||||
this.removeInput('EMPTY');
|
||||
} else {
|
||||
var i = 0;
|
||||
while (this.getInput('ADD' + i)) {
|
||||
this.removeInput('ADD' + i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// Rebuild block.
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
this.appendValueInput('ADD' + i)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(this.arguments_[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const factory_create_with_container = {
|
||||
init: function () {
|
||||
this.setColour(FACTORY_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_PARAMS);
|
||||
this.appendStatementInput('STACK');
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
|
||||
export const factory_create_with_item = {
|
||||
init: function () {
|
||||
this.setColour(FACTORY_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TITLE + ':')
|
||||
.appendField(new Blockly.FieldTextInput('x'), 'NAME');
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
|
||||
export const factory_function_return = {
|
||||
init: function () {
|
||||
this.setColour(FACTORY_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldTextInput('my_function'), 'NAME');
|
||||
this.itemCount_ = 1;
|
||||
this.arguments_ = ['x'];//add
|
||||
this.updateShape_();
|
||||
this.setOutput(true);
|
||||
this.setMutator(new Blockly.icons.MutatorIcon(['factory_create_with_item'], this));
|
||||
},
|
||||
mutationToDom: factory_function_noreturn.mutationToDom,
|
||||
domToMutation: factory_function_noreturn.domToMutation,
|
||||
decompose: factory_function_noreturn.decompose,
|
||||
compose: factory_function_noreturn.compose,
|
||||
saveConnections: factory_function_noreturn.saveConnections,
|
||||
updateShape_: factory_function_noreturn.updateShape_
|
||||
};
|
||||
|
||||
export const factory_declare = {
|
||||
init: function () {
|
||||
this.setColour(FACTORY_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldTextInput('test'), 'NAME')
|
||||
.appendField("=")
|
||||
.appendField(new Blockly.FieldTextInput('Test'), 'TYPE')
|
||||
.appendField("()");
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const factory_callMethod_noreturn = {
|
||||
init: function () {
|
||||
this.setColour(FACTORY_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldTextInput('test'), 'NAME')
|
||||
.appendField('.')
|
||||
.appendField(new Blockly.FieldTextInput('callMethod'), 'METHOD');
|
||||
this.itemCount_ = 1;
|
||||
this.arguments_ = ['x'];//add
|
||||
this.updateShape_();
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setMutator(new Blockly.icons.MutatorIcon(['factory_create_with_item'], this));
|
||||
},
|
||||
mutationToDom: factory_function_noreturn.mutationToDom,
|
||||
domToMutation: factory_function_noreturn.domToMutation,
|
||||
decompose: factory_function_noreturn.decompose,
|
||||
compose: factory_function_noreturn.compose,
|
||||
saveConnections: factory_function_noreturn.saveConnections,
|
||||
updateShape_: factory_function_noreturn.updateShape_
|
||||
};
|
||||
|
||||
export const factory_callMethod_return = {
|
||||
init: function () {
|
||||
this.setColour(FACTORY_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldTextInput('test'), 'NAME')
|
||||
.appendField('.')
|
||||
.appendField(new Blockly.FieldTextInput('callMethod'), 'METHOD');
|
||||
this.itemCount_ = 1;
|
||||
this.arguments_ = ['x'];//add
|
||||
this.updateShape_();
|
||||
this.setOutput(true);
|
||||
this.setMutator(new Blockly.icons.MutatorIcon(['factory_create_with_item'], this));
|
||||
},
|
||||
mutationToDom: factory_function_noreturn.mutationToDom,
|
||||
domToMutation: factory_function_noreturn.domToMutation,
|
||||
decompose: factory_function_noreturn.decompose,
|
||||
compose: factory_function_noreturn.compose,
|
||||
saveConnections: factory_function_noreturn.saveConnections,
|
||||
updateShape_: factory_function_noreturn.updateShape_
|
||||
};
|
||||
|
||||
export const factory_block = {
|
||||
init: function () {
|
||||
this.setColour(FACTORY_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldTextInput('display.scroll("Hello World!")'), 'VALUE');
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const factory_block_return = {
|
||||
init: function () {
|
||||
this.setColour(FACTORY_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldTextInput('test'), 'VALUE');
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const factory_block_with_textarea = {
|
||||
init: function () {
|
||||
this.setColour(FACTORY_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldMultilineInput('display.scroll("Hello World!")\ndisplay.scroll("Hello Mixly!")'), 'VALUE');
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const factory_block_return_with_textarea = {
|
||||
init: function () {
|
||||
this.setColour(FACTORY_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldMultilineInput('Hello\nMixly'), 'VALUE');
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
104
mixly/boards/default_src/python_mixpy/blocks/hardware.js
Normal file
104
mixly/boards/default_src/python_mixpy/blocks/hardware.js
Normal file
@@ -0,0 +1,104 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const HARDWARE_HUE = 40;
|
||||
|
||||
export const hardware_arduino_start = {
|
||||
init: function () {
|
||||
this.setColour(HARDWARE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_HARDWARE)
|
||||
this.appendValueInput('SUB')
|
||||
.setCheck("var");
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_HARDWARE_START)
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_highlow = {
|
||||
init: function () {
|
||||
this.setColour(HARDWARE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.MIXLY_HIGH, "HIGH"], [Blockly.Msg.MIXLY_LOW, "LOW"]]), 'BOOL')
|
||||
this.setOutput(true, Boolean);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_HIGHLOW);
|
||||
}
|
||||
};
|
||||
|
||||
export const hardware_arduino_digital_write = {
|
||||
init: function () {
|
||||
this.setColour(HARDWARE_HUE);
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_HARDWARE)
|
||||
.setCheck("var");
|
||||
this.appendValueInput("PIN", Number)
|
||||
.appendField(Blockly.Msg.MIXLY_Digital_PINMODEOUT)
|
||||
.appendField(Blockly.Msg.MIXLY_PIN)
|
||||
.setCheck(Number);
|
||||
this.appendValueInput("STAT")
|
||||
.appendField(Blockly.Msg.MIXLY_STAT)
|
||||
.setCheck([Number, Boolean]);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.LANG_INOUT_DIGITAL_WRITE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const hardware_arduino_digital_read = {
|
||||
init: function () {
|
||||
this.setColour(HARDWARE_HUE);
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_HARDWARE)
|
||||
.setCheck("var");
|
||||
this.appendValueInput("PIN", Number)
|
||||
.appendField(Blockly.Msg.MIXLY_Digital_PINMODEIN)
|
||||
.appendField(Blockly.Msg.MIXLY_PIN)
|
||||
.setCheck(Number);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_MACHINE_VALUE)
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, [Boolean, Number]);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_DIGITAL_READ);
|
||||
}
|
||||
};
|
||||
|
||||
export const hardware_arduino_analog_write = {
|
||||
init: function () {
|
||||
this.setColour(HARDWARE_HUE);
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_HARDWARE)
|
||||
.setCheck("var");
|
||||
this.appendValueInput("PIN", Number)
|
||||
.appendField(Blockly.Msg.MIXLY_Analog_PINMODEOUT)
|
||||
.appendField(Blockly.Msg.MIXLY_PIN)
|
||||
.setCheck(Number);
|
||||
this.appendValueInput("NUM", Number)
|
||||
.appendField(Blockly.Msg.MIXLY_VALUE2)
|
||||
.setCheck(Number);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_ANALOG_WRITE);
|
||||
}
|
||||
};
|
||||
|
||||
export const hardware_arduino_analog_read = {
|
||||
init: function () {
|
||||
this.setColour(HARDWARE_HUE);
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_HARDWARE)
|
||||
.setCheck("var");
|
||||
this.appendValueInput("PIN", Number)
|
||||
.appendField(Blockly.Msg.MIXLY_Analog_PINMODEIN)
|
||||
.appendField(Blockly.Msg.MIXLY_PIN)
|
||||
.setCheck(Number);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_MACHINE_VALUE)
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, [Boolean, Number]);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_INOUT_ANALOG_READ);
|
||||
}
|
||||
};
|
||||
229
mixly/boards/default_src/python_mixpy/blocks/inout.js
Normal file
229
mixly/boards/default_src/python_mixpy/blocks/inout.js
Normal file
@@ -0,0 +1,229 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
export const inout_input = {
|
||||
init: function () {
|
||||
this.setColour(20);
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.blockpy_inout_raw_input)
|
||||
.setCheck(String);
|
||||
this.setOutput(true);
|
||||
this.setTooltip(Blockly.Msg.INOUT_input_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_print = {
|
||||
init: function () {
|
||||
this.setColour(20);
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINTLN);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.BLOCKPY_PRINT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_print_inline = {
|
||||
init: function () {
|
||||
this.setColour(20);
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINT);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.TEXT_PRINT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_print_end = {
|
||||
init: function () {
|
||||
this.setColour(20);
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINT);
|
||||
this.appendValueInput("END")
|
||||
.appendField(Blockly.Msg.MIXLY_ENDSWITH);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_PYTHON_INOUT_PRINT_END_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_type_input = {
|
||||
init: function () {
|
||||
|
||||
var input_type =
|
||||
[[Blockly.Msg.LANG_MATH_STRING, 'str'], [Blockly.Msg.LANG_MATH_INT, 'int']
|
||||
, [Blockly.Msg.LANG_MATH_FLOAT, 'float']];
|
||||
this.setColour(20);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_GET)
|
||||
.appendField(new Blockly.FieldDropdown(input_type), 'DIR')
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.PROCEDURES_MUTATORCONTAINER_TITLE)
|
||||
.setCheck(String);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'str': Blockly.Msg.MIXLY_MIXPY_INOUT_STR_INPUT_TOOLTIP,
|
||||
'int': Blockly.Msg.MIXLY_MIXPY_INOUT_INT_INPUT_TOOLTIP,
|
||||
'float': Blockly.Msg.MIXLY_MIXPY_INOUT_FLOAT_INPUT_TOOLTIP
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const pyinout_type_input = {
|
||||
init: function () {
|
||||
|
||||
var input_type =
|
||||
[[Blockly.Msg.LANG_MATH_STRING, 'str'], [Blockly.Msg.LANG_MATH_INT, 'int']
|
||||
, [Blockly.Msg.LANG_MATH_FLOAT, 'float']];
|
||||
this.setColour(20);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_GET)
|
||||
.appendField(new Blockly.FieldDropdown(input_type), 'DIR')
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.PROCEDURES_MUTATORCONTAINER_TITLE)
|
||||
.setCheck(String);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'str': Blockly.Msg.MIXLY_MIXPY_INOUT_STR_INPUT_TOOLTIP,
|
||||
'int': Blockly.Msg.MIXLY_MIXPY_INOUT_INT_INPUT_TOOLTIP,
|
||||
'float': Blockly.Msg.MIXLY_MIXPY_INOUT_FLOAT_INPUT_TOOLTIP
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_print_many = {
|
||||
|
||||
init: function () {
|
||||
this.setColour(20);
|
||||
|
||||
this.itemCount_ = 2;
|
||||
this.updateShape_();
|
||||
this.setPreviousStatement(false);
|
||||
this.setNextStatement(false);
|
||||
this.setInputsInline(true);
|
||||
this.setMutator(new Blockly.icons.MutatorIcon(['inout_print_item'], this));
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_MANY_TOOLTIP);
|
||||
},
|
||||
|
||||
mutationToDom: function () {
|
||||
var container = document.createElement('mutation');
|
||||
container.setAttribute('items', this.itemCount_);
|
||||
return container;
|
||||
},
|
||||
|
||||
domToMutation: function (xmlElement) {
|
||||
this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
|
||||
this.updateShape_();
|
||||
},
|
||||
|
||||
decompose: function (workspace) {
|
||||
var containerBlock =
|
||||
workspace.newBlock('inout_print_container');
|
||||
containerBlock.initSvg();
|
||||
var connection = containerBlock.getInput('STACK').connection;
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
var itemBlock = workspace.newBlock('inout_print_item');
|
||||
itemBlock.initSvg();
|
||||
connection.connect(itemBlock.previousConnection);
|
||||
connection = itemBlock.nextConnection;
|
||||
}
|
||||
return containerBlock;
|
||||
},
|
||||
|
||||
compose: function (containerBlock) {
|
||||
var itemBlock = containerBlock.getInputTargetBlock('STACK');
|
||||
// Count number of inputs.
|
||||
var connections = [];
|
||||
var i = 0;
|
||||
while (itemBlock) {
|
||||
connections[i] = itemBlock.valueConnection_;
|
||||
itemBlock = itemBlock.nextConnection &&
|
||||
itemBlock.nextConnection.targetBlock();
|
||||
i++;
|
||||
}
|
||||
this.itemCount_ = i;
|
||||
this.updateShape_();
|
||||
// Reconnect any child blocks.
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
if (connections[i]) {
|
||||
this.getInput('ADD' + i)
|
||||
.connection.connect(connections[i]);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
saveConnections: function (containerBlock) {
|
||||
var itemBlock = containerBlock.getInputTargetBlock('STACK');
|
||||
var i = 0;
|
||||
while (itemBlock) {
|
||||
var input = this.getInput('ADD' + i);
|
||||
itemBlock.valueConnection_ = input && input.connection.targetConnection;
|
||||
i++;
|
||||
itemBlock = itemBlock.nextConnection &&
|
||||
itemBlock.nextConnection.targetBlock();
|
||||
}
|
||||
},
|
||||
|
||||
updateShape_: function () {
|
||||
// Delete everything.
|
||||
if (this.getInput('EMPTY')) {
|
||||
this.removeInput('EMPTY');
|
||||
} else {
|
||||
var i = 0;
|
||||
while (this.getInput('ADD' + i)) {
|
||||
this.removeInput('ADD' + i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// Rebuild block.
|
||||
if (this.itemCount_ == 0) {
|
||||
this.appendDummyInput('EMPTY')
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_EMPTY);
|
||||
} else {
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
var input = this.appendValueInput('ADD' + i);
|
||||
if (i == 0) {
|
||||
input.appendField(Blockly.Msg.MIXLY_SERIAL_PRINTLN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
export const inout_print_container = {
|
||||
init: function () {
|
||||
this.setColour(20);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINTLN);
|
||||
this.appendStatementInput('STACK');
|
||||
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_MANY_CONTAINER_TOOLTIP);
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_print_item = {
|
||||
init: function () {
|
||||
this.setColour(20);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TITLE);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_MANY_ITEM_TOOLTIP);
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
670
mixly/boards/default_src/python_mixpy/blocks/iot.js
Normal file
670
mixly/boards/default_src/python_mixpy/blocks/iot.js
Normal file
@@ -0,0 +1,670 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
import * as Mixly from 'mixly';
|
||||
|
||||
const IOT_HUE = '#526FC3';
|
||||
//'#2FAD7A';
|
||||
|
||||
export const iot_onenet_connect = {
|
||||
init: function () {
|
||||
this.setColour("#78AAE0");
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck("var")
|
||||
.appendField("OneNET" + Blockly.Msg.TUPLE_JOIN);
|
||||
this.appendValueInput('CLIENT')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_ONENET_CLIENT);
|
||||
this.appendValueInput('SERVER')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_ONENET_SERVER);
|
||||
this.appendValueInput('USERNAME')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_ONENET_USERNAME);
|
||||
this.appendValueInput('PASSWORD')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_ONENET_PASSWORD);
|
||||
this.appendValueInput('TOPIC')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_ONENET_TOPIC);
|
||||
this.appendValueInput('SUB')
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_ONENET_SUB);
|
||||
//this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_CONNECT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_onenet_disconnect = {
|
||||
init: function () {
|
||||
this.setColour("#78AAE0");
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck("var")
|
||||
.appendField("OneNET")
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_DISCONNECT_ONENET);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_DISCONNECT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_onenet_check = {
|
||||
init: function () {
|
||||
this.setColour("#78AAE0");
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck("var")
|
||||
.appendField("OneNET")
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_CHECK_ONENET);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_CHECK_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_onenet_publish_dict = {
|
||||
init: function () {
|
||||
this.setColour("#78AAE0");
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck("var")
|
||||
.appendField("OneNET")
|
||||
this.appendValueInput('DICT')
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_PUBLISH_ONENET);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_PRINT_DATA)
|
||||
.appendField(new Blockly.FieldCheckbox('TRUE'), 'is_print');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_PUBLISH_DICT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_onenet_publish = {
|
||||
/**
|
||||
* Block for creating a list with any number of elements of any type.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
init: function () {
|
||||
this.setColour("#78AAE0");
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck("var")
|
||||
.appendField("OneNET")
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldLabel(Blockly.Msg.MIXLY_ESP32_PUBLISH_ONENET), 'TIP')
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
this.itemCount_ = 2;
|
||||
this.updateShape_();
|
||||
this.setInputsInline(false);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setMutator(new Blockly.Mutator(['iot_publish_item']));
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_PUBLISH_TOOLTIP);
|
||||
},
|
||||
/**
|
||||
* Create XML to represent list inputs.
|
||||
* @return {Element} XML storage element.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
mutationToDom: function () {
|
||||
var container = document.createElement('mutation');
|
||||
container.setAttribute('items', this.itemCount_);
|
||||
return container;
|
||||
},
|
||||
/**
|
||||
* Parse XML to restore the list inputs.
|
||||
* @param {!Element} xmlElement XML storage element.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
domToMutation: function (xmlElement) {
|
||||
this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
|
||||
this.updateShape_();
|
||||
},
|
||||
/**
|
||||
* Populate the mutator's dialog with this block's components.
|
||||
* @param {!Blockly.Workspace} workspace Mutator's workspace.
|
||||
* @return {!Blockly.Block} Root block in mutator.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
decompose: function (workspace) {
|
||||
var containerBlock =
|
||||
workspace.newBlock('iot_publish_container');
|
||||
containerBlock.initSvg();
|
||||
var connection = containerBlock.getInput('STACK').connection;
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
var itemBlock = workspace.newBlock('iot_create_with_item');
|
||||
itemBlock.initSvg();
|
||||
connection.connect(itemBlock.previousConnection);
|
||||
connection = itemBlock.nextConnection;
|
||||
}
|
||||
return containerBlock;
|
||||
},
|
||||
/**
|
||||
* Reconfigure this block based on the mutator dialog's components.
|
||||
* @param {!Blockly.Block} containerBlock Root block in mutator.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
compose: function (containerBlock) {
|
||||
var itemBlock = containerBlock.getInputTargetBlock('STACK');
|
||||
// Count number of inputs.
|
||||
var connections = [];
|
||||
var i = 0;
|
||||
while (itemBlock) {
|
||||
connections[i] = itemBlock.valueConnection_;
|
||||
itemBlock = itemBlock.nextConnection &&
|
||||
itemBlock.nextConnection.targetBlock();
|
||||
i++;
|
||||
}
|
||||
this.itemCount_ = i;
|
||||
this.updateShape_();
|
||||
// Reconnect any child blocks.
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
if (connections[i]) {
|
||||
this.getInput('ADD' + i).connection.connect(connections[i]);
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Store pointers to any connected child blocks.
|
||||
* @param {!Blockly.Block} containerBlock Root block in mutator.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
saveConnections: function (containerBlock) {
|
||||
var itemBlock = containerBlock.getInputTargetBlock('STACK');
|
||||
var i = 0;
|
||||
while (itemBlock) {
|
||||
var input = this.getInput('ADD' + i);
|
||||
itemBlock.valueConnection_ = input && input.connection.targetConnection;
|
||||
i++;
|
||||
itemBlock = itemBlock.nextConnection &&
|
||||
itemBlock.nextConnection.targetBlock();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Modify this block to have the correct number of inputs.
|
||||
* @private
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
updateShape_: function () {
|
||||
// Delete everything.
|
||||
if (this.getInput('EMPTY')) {
|
||||
this.removeInput('EMPTY');
|
||||
}
|
||||
var keyNames = [];
|
||||
for (var i = 0; this.getInput('ADD' + i); i++) {
|
||||
//this.getInput('VALUE' + i).removeField("KEY"+i);
|
||||
keyNames.push(this.getFieldValue("KEY" + i))
|
||||
this.removeInput('ADD' + i);
|
||||
}
|
||||
// Rebuild block.
|
||||
if (this.itemCount_ == 0) {
|
||||
//this.getField('TIP')
|
||||
//.setText(Blockly.Msg.MIXLY_ESP32_PUBLISH_ONENET_EMPTY);
|
||||
this.setFieldValue(Blockly.Msg.MIXLY_ESP32_PUBLISH_ONENET_EMPTY, 'TIP');
|
||||
} else {
|
||||
//this.getField('TIP')
|
||||
//.setText(Blockly.Msg.MIXLY_ESP32_PUBLISH_ONENET);
|
||||
this.setFieldValue(Blockly.Msg.MIXLY_ESP32_PUBLISH_ONENET, 'TIP');
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
this.appendValueInput('ADD' + i)
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(
|
||||
new Blockly.FieldTextInput(
|
||||
keyNames.length > i
|
||||
? keyNames[i]
|
||||
: '"key' + (i + 1) + '"'),
|
||||
'KEY' + i)
|
||||
.appendField(":")
|
||||
}
|
||||
}
|
||||
}, getVars: function () {
|
||||
return [this.getFieldValue('VAR')];
|
||||
},
|
||||
renameVar: function (oldName, newName) {
|
||||
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
|
||||
this.setTitleValue(newName, 'VAR');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_publish_container = {
|
||||
/**
|
||||
* Mutator block for list container.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_TYPE_DICT);
|
||||
this.appendStatementInput('STACK');
|
||||
this.setTooltip(Blockly.Msg.DICTS_CREATE_WITH_CONTAINER_TOOLTIP);
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const iot_publish_item = {
|
||||
/**
|
||||
* Mutator bolck for adding items.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.DICTS_CREATE_WITH_ITEM_TITLE);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.DICTS_CREATE_WITH_ITEM_TOOLTIP);
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_create_with_item = {
|
||||
/**
|
||||
* Mutator bolck for adding items.
|
||||
* @this Blockly.Block
|
||||
*/
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.DICTS_CREATE_WITH_ITEM_TITLE);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.DICTS_CREATE_WITH_ITEM_TOOLTIP);
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const iot_mixio_connect = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_CREATE_MQTT_CLIENT_AND_CONNECT);
|
||||
this.appendValueInput('SERVER')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SERVER)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
this.appendValueInput('USERNAME')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_WIFI_USERNAME)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
this.appendValueInput('PASSWORD')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_IOT_PASSWORD)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
this.appendValueInput('PROJECT')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PROJECT)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_MIXIO_PUBLISH = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendValueInput('TOPIC')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_NEW)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_TOPIC);
|
||||
this.appendValueInput('MSG')
|
||||
.appendField(Blockly.Msg.HTML_BODY);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_EMQX_PUBLISH_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_MIXIO_PUBLISHEX = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendValueInput('TOPIC')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_NEW)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_TOPIC);
|
||||
this.appendValueInput('MSG')
|
||||
.appendField(Blockly.Msg.HTML_BODY);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_Service_quality_display)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_AT_MOST_ONCE,"0"],
|
||||
[Blockly.Msg.MIXLY_AT_LEAST_ONCE,"1"]
|
||||
]),"quality")
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_EMQX_PUBLISH_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_MIXIO_SUBSCRIBE = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendValueInput('TOPIC')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SUBSCRIBE + Blockly.Msg.MIXLY_MICROBIT_MSG)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_TOPIC);
|
||||
this.appendValueInput('METHOD')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SET_METHOD);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_EMQX_SUBSCRIBE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_MIXIO_UNSUBSCRIBE = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendValueInput('TOPIC')
|
||||
.appendField(Blockly.Msg.MSG.stop + Blockly.Msg.MIXLY_EMQX_SUBSCRIBE)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_TOPIC);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_EMQX_SUBSCRIBE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_disconnect = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_DISCONNECT_ONENET);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
// this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_DISCONNECT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_connect_only = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_CONNECT);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
// this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_DISCONNECT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_check = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_CHECK_ONENET);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
// this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_CHECK_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_format_topic = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MICROPYTHON_FORMAT)
|
||||
.appendField(Blockly.MQTT_Topic);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_format_msg = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MICROPYTHON_FORMAT)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_MSG);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_FORMATTING = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_IOT_MAP_FORMATING);
|
||||
this.setOutput(true);
|
||||
// this.setTooltip();
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_FORMAT_STRING = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_MICROPYTHON_FORMAT + '(Json)');
|
||||
this.setOutput(true);
|
||||
// this.setTooltip();
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_EMQX_PING = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
// this.appendValueInput('VAR')
|
||||
// .setCheck("var")
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PING);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_EMQX_PING_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_MIXIO_NTP = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
// this.appendValueInput('VAR')
|
||||
// .setCheck("var")
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
.appendField(Blockly.Msg.MIXLY_GET_NTP)
|
||||
this.appendValueInput('addr')
|
||||
.appendField(Blockly.blynk_SERVER_ADD);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_EMQX_INIT_AND_CONNECT_BY_SHARE_CODE = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_CREATE_MQTT_CLIENT_AND_CONNECT);
|
||||
this.appendValueInput('SERVER')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SERVER)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('KEY')
|
||||
.appendField(Blockly.Msg.CONTROLS_FOR_INPUT_WITH + Blockly.Msg.MIXLY_MIXIO_SHARE_KEY)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const IOT_EMQX_INIT_AND_CONNECT_BY_MIXLY_CODE = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_CREATE_MQTT_CLIENT_AND_CONNECT);
|
||||
this.appendValueInput('SERVER')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SERVER)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('KEY')
|
||||
.appendField(Blockly.Msg.CONTROLS_FOR_INPUT_WITH + "Mixly Key")
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const iot_mixly_key_py = {
|
||||
init: function () {
|
||||
this.VISITOR_ID = Mixly.Config.BOARD.visitorId.str32.substring(0, 8).toUpperCase();
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(this.newQuote_(true))
|
||||
.appendField(new Blockly.FieldTextInput(this.visitorId), 'VISITOR_ID')
|
||||
.appendField(this.newQuote_(false));
|
||||
this.setOutput(true, null);
|
||||
},
|
||||
onchange: function () {
|
||||
const nowVisitorId = this.getFieldValue('VISITOR_ID');
|
||||
if (this.VISITOR_ID !== nowVisitorId)
|
||||
this.setFieldValue(this.VISITOR_ID, 'VISITOR_ID');
|
||||
},
|
||||
newQuote_: function (open) {
|
||||
if (open == this.RTL) {
|
||||
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==';
|
||||
} else {
|
||||
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC';
|
||||
}
|
||||
return new Blockly.FieldImage(file, 12, 12, '"');
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixly_key = {
|
||||
init: function () {
|
||||
this.VISITOR_ID = Mixly.Config.BOARD.visitorId.str32.substring(0, 8).toUpperCase();
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldTextInput(this.visitorId), 'VISITOR_ID');
|
||||
this.setOutput(true, null);
|
||||
},
|
||||
onchange: function () {
|
||||
const nowVisitorId = this.getFieldValue('VISITOR_ID');
|
||||
if (this.VISITOR_ID !== nowVisitorId)
|
||||
this.setFieldValue(this.VISITOR_ID, 'VISITOR_ID');
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_client_onboard = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField('MixIO')
|
||||
.appendField(Blockly.Msg.MSG.catEthernet_clinet);
|
||||
this.setOutput(true);
|
||||
this.setInputsInline(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_http_client = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
// this.appendValueInput('VAR')
|
||||
// .setCheck("var")
|
||||
this.appendDummyInput()
|
||||
.appendField("HTTP" + Blockly.Msg.MIXLY_Client)
|
||||
this.appendValueInput('addr')
|
||||
.appendField(Blockly.Msg.DISPLAY_IMAGE_LET2);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_REQUESTS_GET)
|
||||
.appendField(Blockly.Msg.MIXLY_GET_CURRENT_TIME)
|
||||
.appendField(Blockly.Msg.MIXLY_OPEN_DEBUG)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_TRUE, "True"],
|
||||
[Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_FALSE, "False"]
|
||||
]), "key");
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_http_data = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("HTTP" + Blockly.Msg.MIXLY_Client)
|
||||
.appendField(Blockly.Msg.MIXLY_GET)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_REQUESTS_LEN, "client_len"],
|
||||
[Blockly.Msg.MIXLY_REQUESTS_GET_LEN, "server_len"],
|
||||
[Blockly.Msg.MIXLY_REQUESTS_MESSAGE, "text"]
|
||||
]), "key");
|
||||
this.setOutput(true);
|
||||
this.setInputsInline(true);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mqtt_client = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
// this.appendValueInput('VAR')
|
||||
// .setCheck("var")
|
||||
this.appendDummyInput()
|
||||
.appendField("MQTT" + Blockly.Msg.MIXLY_Client)
|
||||
this.appendValueInput('addr')
|
||||
.appendField(Blockly.Msg.MIXLY_CONNECTTO);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_INIT_SUBSCRIBE)
|
||||
.appendField(Blockly.MQTT_Topic)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_GET_CURRENT_TIME, ""],
|
||||
]), "key")
|
||||
.appendField(Blockly.Msg.MIXLY_OPEN_DEBUG)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_TRUE, "True"],
|
||||
[Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_FALSE, "False"]
|
||||
]), "key2");
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mqtt_data = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MQTT" + Blockly.Msg.MIXLY_Client)
|
||||
.appendField(Blockly.Msg.MIXLY_GET)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_REQUESTS_LEN, "client_len"],
|
||||
[Blockly.Msg.MIXLY_REQUESTS_GET_LEN, "server_len"],
|
||||
[Blockly.Msg.MIXLY_REQUESTS_MESSAGE, "time_msg()"]
|
||||
]), "key");
|
||||
this.setOutput(true);
|
||||
this.setInputsInline(true);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// export const iot_wificonnect = iot_wifi_connect;
|
||||
export const iot_onenetconnect = iot_onenet_connect;
|
||||
export const iot_onenetdisconnect = iot_onenet_disconnect;
|
||||
export const iot_checkonenet = iot_onenet_check;
|
||||
export const iot_publish = iot_onenet_publish;
|
||||
|
||||
40
mixly/boards/default_src/python_mixpy/blocks/pins.js
Normal file
40
mixly/boards/default_src/python_mixpy/blocks/pins.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
import { Profile } from 'mixly';
|
||||
|
||||
const PINS_HUE = 230;
|
||||
|
||||
export const pins_digital_write = {
|
||||
init: function () {
|
||||
this.setColour(PINS_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(Profile.default.digital_write), 'PIN');
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const pins_digital_read = {
|
||||
init: function () {
|
||||
this.setColour(PINS_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(Profile.default.digital_read), 'PIN');
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const pins_analog_write = {
|
||||
init: function () {
|
||||
this.setColour(PINS_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(Profile.default.analog_write), 'PIN');
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const pins_analog_read = {
|
||||
init: function () {
|
||||
this.setColour(PINS_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(Profile.default.analog_read), 'PIN');
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
65
mixly/boards/default_src/python_mixpy/blocks/serial.js
Normal file
65
mixly/boards/default_src/python_mixpy/blocks/serial.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const SERIAL_HUE = 40;
|
||||
|
||||
export const serial_open = {
|
||||
init: function () {
|
||||
var bps = [
|
||||
["115200", '115200'], ["256000", '256000'], ["128000", '128000'], ["57600", '57600'], ["56000", '56000'],
|
||||
["43000", '43000'], ["38400", '38400'], ["28800", '28800'], ["19200", '19200'], ["9600", '9600'],
|
||||
["4800", '4800'], ["2400", '2400'], ["1200", '1200'], ["600", '600'], ["300", '300'], ["110", '110']
|
||||
];
|
||||
this.setColour(SERIAL_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldLabel(Blockly.Msg.MIXPY_SERIAL_OPEN))
|
||||
.appendField(new Blockly.FieldTextInput('ser'), 'SER')
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_SERIAL_BEGIN)
|
||||
.appendField(new Blockly.FieldDropdown(bps), 'BPS')
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXPY_SERIAL_OPEN_TIMEOUT);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.MIXPY_SERIAL_OPEN_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const serial_write = {
|
||||
init: function () {
|
||||
this.setColour(SERIAL_HUE);
|
||||
this.appendValueInput('SER')
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXPY_SERIAL_WRITE);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.MIXPY_SERIAL_WRITE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const serial_read_b = {
|
||||
init: function () {
|
||||
this.setColour(SERIAL_HUE);
|
||||
this.appendValueInput('SER')
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXPY_SERIAL_READ);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, String);
|
||||
this.setTooltip(Blockly.Msg.MIXPY_SERIAL_READ_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const serial_close = {
|
||||
init: function () {
|
||||
this.setColour(SERIAL_HUE);
|
||||
this.appendValueInput('SER')
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXPY_SERIAL_CLOSE);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.MIXPY_SERIAL_CLOSE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
702
mixly/boards/default_src/python_mixpy/blocks/sklearn.js
Normal file
702
mixly/boards/default_src/python_mixpy/blocks/sklearn.js
Normal file
@@ -0,0 +1,702 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const SKLEARN_HUE = 80;
|
||||
|
||||
export const sklearn_make_classification = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.SKLEARN_CLASSIFICATION_GENERATION);
|
||||
this.appendValueInput("n_samples")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_SAMPLES);
|
||||
this.appendValueInput("n_features")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_FEATURES);
|
||||
this.appendValueInput("n_informative")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_EFFECTIVE_FEATURES);
|
||||
this.appendValueInput("n_redundant")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_REDUNDANT_FEATURES);
|
||||
this.appendValueInput("n_repeated")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_REPEATED_FEATURES);
|
||||
this.appendValueInput("n_classes")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_CLASSES);
|
||||
this.appendValueInput("n_clusters_per_class")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_CLUSTERS_PER_CLASSES);
|
||||
this.appendValueInput("random_state")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.RANDOM_SEED);
|
||||
this.setInputsInline(false);
|
||||
this.setOutput(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 生成回归样本
|
||||
export const sklearn_make_regression = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.SKLEARN_REGRESSION_GENERATION);
|
||||
this.appendValueInput("n_samples")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_SAMPLES);
|
||||
this.appendValueInput("n_features")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_FEATURES);
|
||||
this.appendValueInput("n_informative")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_EFFECTIVE_FEATURES);
|
||||
this.appendValueInput("n_targets")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_LABELS);
|
||||
this.appendValueInput("bias")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.DEVIATION);
|
||||
this.appendValueInput("noise")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NOISE);
|
||||
this.appendValueInput("random_state")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.RANDOM_SEED);
|
||||
this.setInputsInline(false);
|
||||
this.setOutput(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 生成聚类样本
|
||||
export const sklearn_make_blobs = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.SKLEARN_CLUSTERING_GENERATION);
|
||||
this.appendValueInput("n_samples")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_SAMPLES);
|
||||
this.appendValueInput("n_features")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_FEATURES);
|
||||
this.appendValueInput("centers")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_CLUSTERS);
|
||||
this.appendValueInput("cluster_std")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.STANDARD_DEVIATION_OF_CLUSTER);
|
||||
this.appendValueInput("center_box")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.CLUSTER_BOUNDING_BOX);
|
||||
this.appendValueInput("shuffle")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SHUFFLE_SAMPLES);
|
||||
this.appendValueInput("random_state")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.RANDOM_SEED);
|
||||
this.setInputsInline(false);
|
||||
this.setOutput(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 加载数据集
|
||||
export const sklearn_load = {
|
||||
init: function () {
|
||||
var data = [
|
||||
[Blockly.Msg.SKLEARN_LOAD_IRIS, "load_iris"],
|
||||
[Blockly.Msg.SKLEARN_LOAD_BOSTON, "load_boston"],
|
||||
[Blockly.Msg.SKLEARN_LOAD_DIABETES, "load_diabetes"],
|
||||
[Blockly.Msg.SKLEARN_LOAD_BREAST_CANCER, "load_breast_cancer"],
|
||||
[Blockly.Msg.SKLEARN_LOAD_LINNERUD, "load_linnerud"],
|
||||
[Blockly.Msg.SKLEARN_LOAD_DIGITS, "load_digits"]
|
||||
];
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.LOAD)
|
||||
.appendField(new Blockly.FieldDropdown(data), "type")
|
||||
.appendField(new Blockly.FieldTextInput("iris"), "name");
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
},
|
||||
getVars: function () {
|
||||
return [this.getFieldValue('name')];
|
||||
},
|
||||
renameVar: function (oldName, newName) {
|
||||
if (Blockly.Names.equals(oldName, this.getFieldValue('name'))) {
|
||||
this.setTitleValue(newName, 'name');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 获取特征值/标签值/标签/特征
|
||||
export const sklearn_data_target = {
|
||||
init: function () {
|
||||
this.appendValueInput("name")
|
||||
.setCheck(null)
|
||||
.appendField("sklearn " + Blockly.Msg.DATA_SET);
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MIXLY_GET)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.EIGENVALUES, "data"],
|
||||
[Blockly.Msg.LABEL_VALUE, "target"],
|
||||
[Blockly.Msg.FEATURE, "feature_names"],
|
||||
[Blockly.Msg.mixpy_PYLAB_TICKS_TAG, "target_names"]
|
||||
]), "type");
|
||||
this.setOutput(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 数据集分割
|
||||
export const sklearn_train_test_split = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.DATA_SEGMENTATION);
|
||||
this.appendValueInput("train_data")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.EIGENVALUES);
|
||||
this.appendValueInput("train_target")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.LABEL_VALUE);
|
||||
this.appendValueInput("test_size")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.TEST_SET_PROPORTION);
|
||||
this.appendValueInput("rondom_state")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.RANDOM_SEED);
|
||||
this.setInputsInline(false);
|
||||
this.setOutput(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 数据集分割-无标签值
|
||||
export const sklearn_train_test_split_no_target = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.DATA_SEGMENTATION);
|
||||
this.appendValueInput("train_data")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.EIGENVALUES);
|
||||
this.appendValueInput("test_size")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.TEST_SET_PROPORTION);
|
||||
this.appendValueInput("rondom_state")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.RANDOM_SEED);
|
||||
this.setInputsInline(false);
|
||||
this.setOutput(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 初始化线性回归
|
||||
export const sklearn_LinearRegression = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.SKLEARN_LINEARREGRESSION_INIT);
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("fit_intercept")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_CALCULATE_MODEL_INTERRUPT);
|
||||
this.appendValueInput("normalize")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_REGRESSION_NORMIALIZATION);
|
||||
this.appendValueInput("n_jobs")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_THREADS);
|
||||
this.setInputsInline(false);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 初始化岭回归
|
||||
export const sklearn_Ridge = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.SKLEARN_RIDGE_INIT);
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("alpha")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_REGULA_INTENSITY);
|
||||
this.appendValueInput("fit_intercept")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_CALCULATE_MODEL_INTERRUPT);
|
||||
this.appendValueInput("normalize")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_REGRESSION_NORMIALIZATION);
|
||||
this.appendValueInput("max_iter")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_MAX_ITER);
|
||||
this.appendValueInput("random_state")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.RANDOM_SEED);
|
||||
this.setInputsInline(false);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 初始化决策树 分类/回归算法
|
||||
export const sklearn_DecisionTreeClassifier_Regressor = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.SKLEARN_DECISIONTREE_INIT)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.SKLEARN_CLASSIFICATION_ALGORITHM, "DecisionTreeClassifier"],
|
||||
[Blockly.Msg.SKLEARN_REGRESSION_ALGORITHM, "DecisionTreeRegressor"]
|
||||
]), "type");
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("max_depth")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_MAXIMUM_TREE_DEPTH);
|
||||
this.appendValueInput("random_state")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.RANDOM_SEED);
|
||||
this.setInputsInline(false);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 初始化随机森林 分类/回归算法
|
||||
export const sklearn_RandomForestClassifier_Regressor = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.SKLEARN_RANDOMFOREST_INIT)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.SKLEARN_CLASSIFICATION_ALGORITHM, "RandomForestClassifier"],
|
||||
[Blockly.Msg.SKLEARN_REGRESSION_ALGORITHM, "RandomForestRegressor"]
|
||||
]), "type");
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("n_estimators")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_TREES);
|
||||
this.appendValueInput("max_depth")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_MAXIMUM_TREE_DEPTH);
|
||||
this.appendValueInput("n_jobs")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_THREADS);
|
||||
this.appendValueInput("random_state")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.RANDOM_SEED);
|
||||
this.setInputsInline(false);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 初始化K近邻 分类/回归算法
|
||||
export const sklearn_KNeighborsClassifier_Regressor = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.SKLEARN_KNN_INIT)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.SKLEARN_CLASSIFICATION_ALGORITHM, "KNeighborsClassifier"],
|
||||
[Blockly.Msg.SKLEARN_REGRESSION_ALGORITHM, "KNeighborsRegressor"]
|
||||
]), "type");
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("K")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField("K");
|
||||
this.appendValueInput("n_jobs")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_THREADS);
|
||||
this.setInputsInline(false);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 初始化高斯贝叶斯分类算法
|
||||
export const sklearn_GaussianNB = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.SKLEARN_GAUSSINNB_INIT);
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 初始化PCA降维
|
||||
export const sklearn_pca = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn 初始化 PCA 算法");
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("n_components")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_PCA_N_COMPONENTS);
|
||||
this.setInputsInline(false);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn PCA拟合并转换数据
|
||||
export const sklearn_pca_fit_transform = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn PCA 降维");
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("train_data")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.EIGENVALUES);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 初始化K-均值聚类
|
||||
export const sklearn_KMeans = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.SKLEARN_KMEANS_INIT);
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("n_clusters")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.NUMBER_OF_CLUSTERS_JUST);
|
||||
this.appendValueInput("max_iter")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_MAX_ITER);
|
||||
this.appendValueInput("random_state")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.RANDOM_SEED);
|
||||
this.setInputsInline(false);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn KMeans拟合数据
|
||||
export const sklearn_KMeans_fit = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn K-均值聚类");
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("train_data")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.EIGENVALUES);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 训练模型
|
||||
export const sklearn_fit = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.TRAINING_MODEL);
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("train_data")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.EIGENVALUES);
|
||||
this.appendValueInput("train_target")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.LABEL_VALUE);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 训练模型-无标签值
|
||||
export const sklearn_fit_no_target = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.TRAINING_MODEL);
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("train_data")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.EIGENVALUES);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 模型预测
|
||||
export const sklearn_predict = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.MODEL_PRODICTION);
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("train_data")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.EIGENVALUES);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 计算模型得分
|
||||
export const sklearn_score = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.CALCULATE_THE_SCORE);
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("train_data")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.EIGENVALUES);
|
||||
this.appendValueInput("train_target")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.LABEL_VALUE);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 计算模型得分 - 无标签值
|
||||
export const sklearn_score_no_target = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.CALCULATE_THE_SCORE);
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("train_data")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.EIGENVALUES);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 线性回归 模型获取 斜率/截距
|
||||
export const sklearn_coef_intercept = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.SKLEARN_GENERALIZED_LINEAR_REGRESSION);
|
||||
this.appendValueInput("model_name")
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.setCheck(null)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendDummyInput()
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MIXLY_GET)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.SKLEARN_COEF, "coef_"],
|
||||
[Blockly.Msg.SKLEARN_INTERCEPT, "intercept_"]
|
||||
]), "type");
|
||||
this.setOutput(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn K-均值聚类 模型获取 簇中心坐标/聚类后的标签/所有点到对应簇中心的距离平方和
|
||||
export const sklearn_cluster_centers_labels_inertia = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField("sklearn " + Blockly.Msg.SKLEARN_CLUSTERING);
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_GET)
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.SKLEARN_CLUSTER_CENTER, "cluster_centers_"],
|
||||
[Blockly.Msg.SKLEARN_LABELS_AFTER_CLUSTERING, "labels_"],
|
||||
[Blockly.Msg.SKLEARN_CLUSTERING_SUM_OF_SQUARED_DISTANCES, "inertia_"]
|
||||
]), "type");
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
|
||||
//sklearn 保存/加载模型
|
||||
export const sklearn_save_load_model = {
|
||||
init: function () {
|
||||
this.appendValueInput("model_name")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField("sklearn")
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.SKLEARN_SAVE_MODEL, "dump"],
|
||||
[Blockly.Msg.SKLEARN_LOAD_MODEL, "load"]
|
||||
]), "type")
|
||||
.appendField(" " + Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput("address")
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_THE_PATH);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip("");
|
||||
this.setHelpUrl("");
|
||||
}
|
||||
};
|
||||
126
mixly/boards/default_src/python_mixpy/blocks/system.js
Normal file
126
mixly/boards/default_src/python_mixpy/blocks/system.js
Normal file
@@ -0,0 +1,126 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const SYSTEM_HUE = 120;
|
||||
|
||||
export const base_delay = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendValueInput("DELAY_TIME", Number)
|
||||
.appendField(Blockly.Msg.MIXLY_DELAY + '(' + Blockly.Msg.MIXLY_MILLIS + ')')
|
||||
.setCheck(Number);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_DELAY);
|
||||
}
|
||||
};
|
||||
|
||||
export const controls_millis = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_time_time);
|
||||
this.setOutput(true, Number);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_MILLIS);
|
||||
}
|
||||
};
|
||||
|
||||
export const time_localtime = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME)
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_ALL, "all"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_YEAR, "0"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_MONTH, "1"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_DATE, "2"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_HOUR, "3"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_MINUTE, "4"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_SECOND, "5"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_INWEEK, "6"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_INYEAR, "7"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_DST, "8"]
|
||||
]), "op");
|
||||
this.setOutput(true);
|
||||
this.setInputsInline(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const Panic_with_status_code = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendValueInput("STATUS_CODE", Number)
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_Panic_with_status_code)
|
||||
.setCheck(Number);
|
||||
this.setPreviousStatement(true, null);
|
||||
// this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_DELAY);
|
||||
}
|
||||
};
|
||||
|
||||
export const reset = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_Reset_micro);
|
||||
this.setPreviousStatement(true);
|
||||
// this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const controls_mstimer2 = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendValueInput('TIME')
|
||||
.setCheck(Number)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('MsTimer2')
|
||||
.appendField(Blockly.Msg.MIXLY_MSTIMER2_EVERY);
|
||||
this.appendDummyInput()
|
||||
.appendField('ms');
|
||||
this.appendStatementInput('DO')
|
||||
.appendField(Blockly.Msg.MIXLY_MSTIMER2_DO);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const controls_mstimer2_start = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField('MsTimer2')
|
||||
.appendField(Blockly.Msg.MIXLY_MSTIMER2_START);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const controls_mstimer2_stop = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField('MsTimer2')
|
||||
.appendField(Blockly.Msg.MIXLY_STOP);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const time_sleep = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendValueInput("DELAY_TIME", Number)
|
||||
.appendField(Blockly.Msg.MIXLY_DELAY)
|
||||
.setCheck(Number);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_SECOND)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_DELAY);
|
||||
}
|
||||
};
|
||||
945
mixly/boards/default_src/python_mixpy/blocks/turtle.js
Normal file
945
mixly/boards/default_src/python_mixpy/blocks/turtle.js
Normal file
@@ -0,0 +1,945 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const TURTLE_HUE = 180;
|
||||
|
||||
export const turtle_create = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.blockpy_turtle_create)
|
||||
.appendField(new Blockly.FieldTextInput('tina'), 'VAR')
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.blockpy_turtle_create_TOOLTIP);
|
||||
},
|
||||
getVars: function () {
|
||||
return [this.getFieldValue('VAR')];
|
||||
},
|
||||
renameVar: function (oldName, newName) {
|
||||
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
|
||||
this.setTitleValue(newName, 'VAR');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_done = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_TURTLE_DONE);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_exitonclick = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_PYTHON_TURTLE_EXITONCLICK);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_move = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var front_back =
|
||||
[[Blockly.Msg.blockpy_forward, 'forward'], [Blockly.Msg.blockpy_backward, 'backward']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MOVE_BY)
|
||||
.appendField(new Blockly.FieldDropdown(front_back), 'DIR')
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MOVE_BY_num);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'forward': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_FORWARD,
|
||||
'backward': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_BACKWARD
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_rotate = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var front_back =
|
||||
[[Blockly.Msg.blockpy_left, 'left'], [Blockly.Msg.blockpy_right, 'right']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_rotate)
|
||||
.appendField(new Blockly.FieldDropdown(front_back), 'DIR')
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_BY_ANGLE);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'left': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_LEFT,
|
||||
'right': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_RIGHT
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_setheading = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_setheading);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_setheading_degree);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_screen_delay = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_SCREEN_DELAY);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MILLIS);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SCREEN_DELAY);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_goto = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
|
||||
.appendField(Blockly.Msg.blockpy_turtle_goto);
|
||||
this.appendValueInput('val')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_goto_y);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_goto_position);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_setxy = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var set_xy =
|
||||
[[Blockly.Msg.PYLAB_LABEL_X, 'x'], [Blockly.Msg.PYLAB_LABEL_Y, 'y']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(new Blockly.FieldDropdown(set_xy), 'DIR')
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_SETXY);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_TURTLE_SETXY_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_pos_shape = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
var pos_shape =
|
||||
[[Blockly.Msg.TURTLE_POS, 'pos'], [Blockly.Msg.TURTLE_SHAPE, 'shape'], [Blockly.Msg.TURTLE_HEADING, 'heading'], [Blockly.Msg.MIXLY_MIXPY_TURTLE_WIDTH, 'width'], [Blockly.Msg.MIXLY_TURTEL_GET_SHAPESIZE, 'shapesize'], [Blockly.Msg.MIXLY_SPEED, 'speed']];
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.TURTLE_POS_SHAPE)
|
||||
.appendField(new Blockly.FieldDropdown(pos_shape), 'DIR')
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'pos': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_POS,
|
||||
'shape': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SHAPE,
|
||||
'heading': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_HEADING,
|
||||
'width': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_WIDTH,
|
||||
'speed': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_GET_SPEED,
|
||||
'shapesize': Blockly.Msg.MIXLY_TURTEL_GET_SHAPESIZE_TOOLTIP
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
this.setOutput(true);
|
||||
this.setInputsInline(true);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_stamp = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.TURTLE_STAMP);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_clear = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var clear_reset =
|
||||
[[Blockly.Msg.MIXLY_LCD_STAT_CLEAR, 'clear'], [Blockly.Msg.blockpy_turtle_reset, 'reset']
|
||||
, [Blockly.Msg.blockpy_turtle_home, 'home']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(clear_reset), 'DIR')
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'clear': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_CLEAR,
|
||||
'reset': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_RESET,
|
||||
'home': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_HOME
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_penup = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var penup_down =
|
||||
[[Blockly.Msg.blockpy_turtle_penup, 'penup'], [Blockly.Msg.blockpy_turtle_pendown, 'pendown']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(penup_down), 'DIR')
|
||||
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'penup': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_PENUP,
|
||||
'pendown': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_PENDOWN
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_fill = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var fill =
|
||||
[[Blockly.Msg.blockpy_turtle_beginfill, 'begin'], [Blockly.Msg.blockpy_turtle_endfill, 'end']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(fill), 'DIR')
|
||||
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'begin': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_BEGINFILL,
|
||||
'end': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_ENDFILL
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const turtle_size_speed = {
|
||||
init: function () {
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldTextInput('tina'), 'TUR')
|
||||
var size_speed =
|
||||
[[Blockly.Msg.blockpy_turtle_size, 'pensize'], [Blockly.Msg.MIXLY_SPEED, 'speed']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_set)
|
||||
.appendField(new Blockly.FieldDropdown(size_speed), 'DIR')
|
||||
.appendField(Blockly.Msg.blockpy_turtle_set_num);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'pensize': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SIZE,
|
||||
'speed': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SPEED
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_size = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_set_size);
|
||||
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SIZE);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const turtle_speed = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_set_speed);
|
||||
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SPEED);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_circle = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var circle_dot =
|
||||
[[Blockly.Msg.blockpy_turtle_circle, 'circle'], [Blockly.Msg.blockpy_turtle_dot, 'dot']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_draw)
|
||||
.appendField(new Blockly.FieldDropdown(circle_dot), 'DIR')
|
||||
.appendField(Blockly.Msg.blockpy_turtle_radius);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'circle': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_CIRCLE,
|
||||
'dot': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_DOT
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_circle_advanced = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_DRAW_CIRCLE)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_radius);
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_angle);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TURTEL_CIRCLE);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_visible = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var visible =
|
||||
[[Blockly.Msg.blockpy_turtle_hide, 'hideturtle'], [Blockly.Msg.blockpy_turtle_show, 'showturtle']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(visible), 'DIR')
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'hideturtle': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_HIDE,
|
||||
'showturtle': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SHOW
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_bgcolor = {
|
||||
init: function () {
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_bgcolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_TRACER);
|
||||
this.appendValueInput('STEP')
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_TRACER_STEP);
|
||||
this.appendValueInput('DELAY')
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_TRACER_DELAY_MS);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_pencolor = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_fillcolor = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_clone = {
|
||||
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.TURTLE_CLONE);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_CLONE_TOOLTIP);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_bgcolor_hex_new = {
|
||||
init: function () {
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_bgcolor);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_pencolor_hex_new = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_fillcolor_hex_new = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_color = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME');
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME2');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_color_hex = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR1')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor);
|
||||
this.appendValueInput('VAR2')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_bgcolor_hex = {
|
||||
init: function () {
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_bgcolor_hex);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_pencolor_hex = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor_hex);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_fillcolor_hex = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor_hex);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_shape = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var shape = [
|
||||
[Blockly.Msg.blockpy_turtle_shape_arrow, 'arrow'], [Blockly.Msg.blockpy_turtle_shape_turtle, 'turtle'],
|
||||
[Blockly.Msg.blockpy_turtle_shape_circle, 'circle'], [Blockly.Msg.blockpy_turtle_shape_square, 'square'],
|
||||
[Blockly.Msg.blockpy_turtle_shape_triangle, 'triangle'], [Blockly.Msg.blockpy_turtle_shape_classic, 'classic']
|
||||
];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.blockpy_turtle_shape)
|
||||
.appendField(new Blockly.FieldDropdown(shape), 'DIR');
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_SHAPE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_shapesize = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SHAPESIZE);
|
||||
this.appendValueInput('WID')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SHAPESIZE_WID);
|
||||
this.appendValueInput('LEN')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SHAPESIZE_LEN);
|
||||
this.appendValueInput('OUTLINE')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SHAPESIZE_OUTLINE);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_SHAPESIZE);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_numinput = {
|
||||
init: function () {
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_NUMINPUT)
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TITLE')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT_TITLE);
|
||||
this.appendValueInput('PROMPT')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT_PROMPT);
|
||||
this.appendValueInput('DEFAULT')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.DICTS_DEFAULT_VALUE);
|
||||
this.appendValueInput('MIN')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MATH_ONLIST_OPERATOR_MIN);
|
||||
this.appendValueInput('MAX')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MATH_ONLIST_OPERATOR_MAX);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, Number);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_NUMINPUT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_textinput = {
|
||||
init: function () {
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT)
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TITLE')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT_TITLE);
|
||||
this.appendValueInput('PROMPT')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT_PROMPT);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, String);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_TEXTINPUT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_write = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_write);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_WRITE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_write_format = {
|
||||
init: function () {
|
||||
var move =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_FALSE, 'False'], [Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_TRUE, 'True']];
|
||||
var align =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_LEFT, 'left'], [Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_CENTER, 'center'], [Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_RIGHT, 'right']];
|
||||
var fonttype =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_NORMAL, 'normal'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_BOLD, 'bold'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_ITALIC, 'italic'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_BOLD_ITALIC, 'bold","italic']];
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_write);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE)
|
||||
.appendField(new Blockly.FieldDropdown(move), 'MOVE');
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN)
|
||||
.appendField(new Blockly.FieldDropdown(align), 'ALIGN');
|
||||
this.appendValueInput('FONTNAME')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NAME);
|
||||
this.appendValueInput('FONTNUM')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NUM);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE)
|
||||
.appendField(new Blockly.FieldDropdown(fonttype), 'FONTTYPE');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_WRITE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_write_format_skulpt = {
|
||||
init: function () {
|
||||
var move =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_FALSE, 'False'], [Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_TRUE, 'True']];
|
||||
var align =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_LEFT, 'left'], [Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_CENTER, 'center'], [Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_RIGHT, 'right']];
|
||||
var fonttype =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_NORMAL, 'normal'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_BOLD, 'bold'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_ITALIC, 'italic']];
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_write);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE)
|
||||
.appendField(new Blockly.FieldDropdown(move), 'MOVE');
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN)
|
||||
.appendField(new Blockly.FieldDropdown(align), 'ALIGN');
|
||||
this.appendValueInput('FONTNAME')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NAME);
|
||||
this.appendValueInput('FONTNUM')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NUM);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE)
|
||||
.appendField(new Blockly.FieldDropdown(fonttype), 'FONTTYPE');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_WRITE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const turtle_color_seclet = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(new Blockly.FieldColour("ff0000"), "COLOR");
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, String);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_getscreen = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendDummyInput("")
|
||||
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_GETSCREEN)
|
||||
.appendField(new Blockly.FieldTextInput('screen'), 'VAR')
|
||||
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TURTEL_GETSCREEN_TOOLTIP);
|
||||
},
|
||||
getVars: function () {
|
||||
return [this.getFieldValue('VAR')];
|
||||
},
|
||||
renameVar: function (oldName, newName) {
|
||||
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
|
||||
this.setTitleValue(newName, 'VAR');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_EVENT_ONKEY);
|
||||
this.appendValueInput('callback')
|
||||
.appendField(Blockly.Msg.MIXLY_PYTHON_CONTROLS_THREAD_USE)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TURTEL_EVENT_ONKEY_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_onclick = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_EVENT_ONCLICK);
|
||||
this.appendValueInput('callback')
|
||||
.appendField(Blockly.Msg.MIXLY_PYTHON_CONTROLS_THREAD_USE)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TURTEL_EVENT_ONCLICK_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_ontimer = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_EVENT_ONTIMER);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_mSecond);
|
||||
this.appendValueInput('callback')
|
||||
.appendField(Blockly.Msg.MIXLY_PYTHON_CONTROLS_THREAD_USE)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TURTEL_EVENT_ONTIMER_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_listen = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SCREEN_LISTEN);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_screen_savefig = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendValueInput("FILE")
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.mixpy_PL_SAVEFIG);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setOutput(false);
|
||||
this.setTooltip(Blockly.Msg.mixpy_TURTLE_SAVEFIG_TOOLTIP);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user