12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566 |
- /**
- * An object that manages the various editors, where users can edit their program. Also manages the
- * movement between editors.
- * There are currently four editors:
- * - Blocks: A Blockly instance
- * - Text: A CodeMirror instance
- * - Instructor: Features for changing the assignment and environment settings
- *
- * @constructor
- * @this {BlockPyEditor}
- * @param {Object} main - The main BlockPy instance
- * @param {HTMLElement} tag - The HTML object this is attached to.
- */
- function BlockPyEditor(main, tag) {
- this.main = main;
- this.tag = tag;
- // This tool is what actually converts text to blocks!
- this.converter = new PythonToBlocks();
- // HTML DOM accessors
- this.blockTag = tag.find('.blockpy-blocks');
- this.blocklyDiv = this.blockTag.find('.blockly-div');
- this.textTag = tag.find('.blockpy-text');
- this.instructorTag = tag.find('.blockpy-instructor');
- this.textSidebarTag = this.textTag.find(".blockpy-text-sidebar");
- // Blockly and CodeMirror instances
- this.blockly = null;
- this.codeMirror = null;
- // The updateStack keeps track of whether an update is percolating, to prevent duplicate update events.
- this.silenceBlock = false;
- this.silenceBlockTimer = null;
- this.silenceText = false;
- this.silenceModel = 0;
- this.blocksFailed = false;
- this.blocksFailedTimeout = null;
- // Hack to prevent chrome errors. Forces audio to load on demand.
- // See: https://github.com/google/blockly/issues/299
- Blockly.WorkspaceSvg.prototype.preloadAudio_ = function () { };
- // Keep track of the toolbox width
- this.blocklyToolboxWidth = 0;
- // Initialize subcomponents
- this.initText();
- this.initBlockly();
- this.initInstructor();
- this.triggerOnChange = null;
- var editor = this;
- var firstEdit = true;
- this.main.model.program.subscribe(function () {
- editor.updateBlocksFromModel();
- editor.updateTextFromModel();
- if (editor.main.model.settings.filename() == "__main__" &&
- !firstEdit) {
- // if (editor.triggerOnChange) {
- // clearTimeout(editor.triggerOnChange);
- // }
- // var engine = editor.main.components.engine;
- // editor.triggerOnChange = setTimeout(engine.on_change.bind(engine), 1000);
- }
- firstEdit = false;
- });
- // Handle mode switching
- var settings = this.main.model.settings;
- settings.editor.subscribe(function () { editor.setMode() });
- var updateReadOnly = function () {
- var newValue = !!(settings.read_only() && !settings.instructor());
- //editor.codeMirror.setOption('readOnly', newValue);
- tag.toggleClass("blockpy-read-only", newValue);
- };
- settings.read_only.subscribe(updateReadOnly);
- settings.instructor.subscribe(updateReadOnly);
- // Handle filename switching
- this.main.model.settings.filename.subscribe(function (name) {
- if (name == 'give_feedback') {
- editor.setMode('Text');
- }
- });
- // Handle Upload mode turned on
- this.main.model.assignment.upload.subscribe(function (uploadsMode) {
- if (uploadsMode) {
- editor.setMode('Text');
- }
- });
- // Have to force a manual block update
- //this.updateText();
- this.updateBlocksFromModel();
- this.updateTextFromModel();
- }
- /**
- * Initializes the Blockly instance (handles all the blocks). This includes
- * attaching a number of ChangeListeners that can keep the internal code
- * representation updated and enforce type checking.
- */
- BlockPyEditor.prototype.initBlockly = function () {
- this.blockly = Blockly.inject(this.blocklyDiv[0], {
- path: this.main.model.constants.blocklyPath,
- scrollbars: this.main.model.constants.blocklyScrollbars,
- readOnly: this.main.model.settings.read_only(), //"nocursor", //
- oneBasedIndex: false,
- comments: false,
- toolbox: this.updateToolbox(false),
- collapse: true,
- css: true,
- disable: true,
- grid: false,
- maxBlocks: Infinity,
- //media: blocklyPath + '/media/',
- rtl: false,
- sounds: true,
- trashcan: true,
- zoom: {
- controls: true,
- wheel: false,
- startScale: 1.0,
- maxScale: 2,
- minScale: 0.2,
- scaleSpeed: 1.2
- }
- });
- // Register model changer
- var editor = this;
- this.blockly.addChangeListener(function (evt) {
- //editor.main.components.feedback.clearEditorErrors();
- editor.blockly.highlightBlock(null);
- editor.updateBlocks();
- });
- this.main.model.settings.filename.subscribe(function () {
- /*if (editor.main.model.settings.editor() == "Blocks") {
- editor.updateBlocksFromModel()
- }*/
- });
- this.main.model.assignment.modules.subscribe(function () { editor.updateToolbox(true) });
- // Force the proper window size
- this.blockly.resize();
- // Keep the toolbox width set
- this.blocklyToolboxWidth = this.getToolbarWidth();
- Blockly.captureDialog_ = this.copyImage.bind(this);
- // Enable static type checking!
- /*
- this.blockly.addChangeListener(function() {
- if (!editor.main.model.settings.disable_variable_types()) {
- var variables = editor.main.components.engine.analyzeVariables()
- editor.blockly.getAllBlocks().filter(function(r) {return r.type == 'variables_get'}).forEach(function(block) {
- var name = block.inputList[0].fieldRow[0].value_;
- if (name in variables) {
- var type = variables[name];
- if (type.type == "Num") {
- block.setOutput(true, "Number");
- } else if (type.type == "List") {
- block.setOutput(true, "Array");
- } else if (type.type == "Str") {
- block.setOutput(true, "String");
- } else {
- block.setOutput(true, null);
- }
- }
- })
- }
- });
- */
- };
- /**
- * Retrieves the current width of the Blockly Toolbox, unless
- * we're in read-only mode (when there is no toolbox).
- * @returns {Number} The current width of the toolbox.
- */
- BlockPyEditor.prototype.getToolbarWidth = function () {
- if (this.main.model.settings.read_only()) {
- return 0;
- }
- else if (this.blockly.toolbox_) {
- return this.blockly.toolbox_.width;
- }
- else {
- return 0;
- }
- }
- /**
- * Initializes the CodeMirror instance. This handles text editing (with syntax highlighting)
- * and also attaches a listener for change events to update the internal code represntation.
- */
- BlockPyEditor.prototype.initText = function () {
- var codeMirrorDiv = this.textTag.find('.codemirror-div')[0];
- this.codeMirror = CodeMirror.fromTextArea(codeMirrorDiv, {
- mode: {
- name: "python",
- version: 3,
- singleLineStringErrors: false
- },
- readOnly: this.main.model.settings.read_only(),//"nocursor", //
- showCursorWhenSelecting: true,
- lineNumbers: true,
- firstLineNumber: 1,
- indentUnit: 4,
- //tabSize: 4,
- indentWithTabs: false,
- matchBrackets: true,
- extraKeys: {
- "Tab": "indentMore",
- "Shift-Tab": "indentLess"
- },
- });
- // Register model changer
- var editor = this;
- this.codeMirror.on("change", function () {
- //editor.main.components.feedback.clearEditorErrors();
- editor.updateText()
- editor.unhighlightLines();
- });
- // Ensure that it fills the editor area
- this.codeMirror.setSize(null, "100%");
- };
- BlockPyEditor.prototype.reloadIntroduction = function () {
- var introductionEditor = this.tag.find('.blockpy-presentation-body-editor');
- var model = this.main.model;
- introductionEditor.code(model.assignment.introduction());
- }
- /**
- * Initializes the Instructor tab, which has a number of buttons and menus for
- * manipulating assignments and the environment. One important job is to register the
- * SummerNote instance used for editing the Introduction of the assignment.
- */
- BlockPyEditor.prototype.initInstructor = function () {
- var introductionEditor = this.tag.find('.blockpy-presentation-body-editor');
- var model = this.main.model;
- introductionEditor.summernote({
- codemirror: { // codemirror options
- theme: 'monokai'
- },
- onChange: model.assignment.introduction,
- toolbar: [
- ['style', ['bold', 'italic', 'underline', 'clear']],
- ['font', ['fontname', 'fontsize']],
- ['insert', ['link', 'table', 'ul', 'ol', 'image']],
- ['misc', ['codeview', 'help']]
- ]
- });
- this.reloadIntroduction();
- this.availableModules = this.tag.find('.blockpy-available-modules');
- this.availableModules.multiSelect({ selectableOptgroup: true });
- }
- /**
- * Makes the module available in the availableModules multi-select menu by adding
- * it to the list.
- *
- * @param {String} name - The name of the module (human-friendly version, as opposed to the slug) to be added.
- */
- BlockPyEditor.prototype.addAvailableModule = function (name) {
- this.availableModules.multiSelect('addOption', {
- 'value': name,
- 'text': name
- });
- this.availableModules.multiSelect('select', name);
- };
- /**
- * Hides the Text tab, which involves shrinking it and hiding its CodeMirror too.
- */
- BlockPyEditor.prototype.hideSplitMenu = function () {
- this.hideTextMenu();
- this.hideBlockMenu();
- }
- /**
- * Shows the Text tab, which requires restoring its height, showing AND refreshing
- * the CodeMirror instance.
- */
- BlockPyEditor.prototype.showSplitMenu = function () {
- this.showBlockMenu();
- this.showTextMenu();
- this.textTag.css('width', '100%');
- this.blockTag.css('width', '100%');
- this.textSidebarTag.css('width', '0px');
- // this.textTag.addClass('col-md-12');
- // this.blockTag.addClass('col-md-12');
- Blockly.svgResize(this.blockly);
- }
- /**
- * Hides the Text tab, which involves shrinking it and hiding its CodeMirror too.
- */
- BlockPyEditor.prototype.hideTextMenu = function () {
- this.textTag.css('height', '0%');
- $(this.codeMirror.getWrapperElement()).hide();
- this.textSidebarTag.hide();
- this.textTag.hide();
- }
- /**
- * Shows the Text tab, which requires restoring its height, showing AND refreshing
- * the CodeMirror instance.
- */
- BlockPyEditor.prototype.showTextMenu = function () {
- this.textTag.show();
- // Adjust height
- this.textTag.css('height', '100%');
- this.textTag.css('width', '100%');
- // Show CodeMirror
- $(this.codeMirror.getWrapperElement()).show();
- // CodeMirror doesn't know its changed size
- this.codeMirror.refresh();
- // Resize sidebar
- var codemirrorGutterWidth = $('.CodeMirror-gutters').width();
- var sideBarWidth = this.blocklyToolboxWidth - codemirrorGutterWidth - 2;
- this.textSidebarTag.css('width', sideBarWidth + 'px');
- this.textSidebarTag.show();
- // this.textTag.removeClass('col-md-6');
- }
- /**
- * Hides the Block tab, which involves shrinking it and hiding the Blockly instance.
- */
- BlockPyEditor.prototype.hideBlockMenu = function () {
- this.blocklyToolboxWidth = this.getToolbarWidth();
- this.blockTag.css('height', '0%');
- this.blocklyDiv.css("width", "0");
- this.blockly.setVisible(false);
- }
- /**
- * Shows the Block tab, which involves restoring its height and showing the Blockly instance.
- */
- BlockPyEditor.prototype.showBlockMenu = function () {
- this.blockTag.css('height', '100%');
- this.blockTag.css('width', '100%');
- this.blocklyDiv.css("width", "100%");
- this.blockly.resize();
- this.blockly.setVisible(true);
- this.blockTag.removeClass('col-md-6');
- Blockly.svgResize(this.blockly);
- }
- /**
- * Hides the Instructor tab, which shrinking it.
- */
- BlockPyEditor.prototype.hideInstructorMenu = function () {
- this.instructorTag.hide();
- this.instructorTag.css('height', '0%');
- }
- /**
- * Shows the Instructor tab, which involves restoring its height.
- */
- BlockPyEditor.prototype.showInstructorMenu = function () {
- this.instructorTag.css('height', '100%');
- this.instructorTag.show();
- }
- /**
- * Sets the current editor mode to Text, hiding the other menus.
- * Also forces the text side to update.
- */
- BlockPyEditor.prototype.setModeToText = function () {
- this.hideBlockMenu();
- this.hideInstructorMenu();
- this.showTextMenu();
- // Update the text model from the blocks
- }
- /**
- * Sets the current editor mode to Blocks, hiding the other menus.
- * Also forces the block side to update.
- * There is a chance this could fail, if the text side is irredeemably
- * awful. So then the editor bounces back to the text side.
- */
- BlockPyEditor.prototype.setModeToBlocks = function () {
- this.hideTextMenu();
- this.hideInstructorMenu();
- this.showBlockMenu();
- if (this.blocksFailed !== false) {
- this.showConversionError();
- var main = this.main;
- main.model.settings.editor("Text");
- setTimeout(function () {
- main.components.toolbar.tags.mode_set_text.click();
- }, 0);
- }
- // Update the blocks model from the text
- /*
- success = this.updateBlocksFromModel();
- if (!success) {
- var main = this.main;
- main.components.editor.updateTextFromModel();
- main.model.settings.editor("Text");
- setTimeout(function() {
- main.components.toolbar.tags.mode_set_text.click();
- }, 0);
- }*/
- }
- /**
- * Sets the current editor mode to Split mode, hiding the other menus.
- */
- BlockPyEditor.prototype.setModeToSplit = function () {
- this.hideTextMenu();
- this.hideInstructorMenu();
- this.hideBlockMenu();
- this.showSplitMenu();
- if (this.blocksFailed !== false) {
- this.showConversionError();
- }
- }
- /**
- * Sets the current editor mode to the Instructor mode, hiding the other menus.
- */
- BlockPyEditor.prototype.setModeToInstructor = function () {
- this.hideTextMenu();
- this.hideBlockMenu();
- this.showInstructorMenu();
- //TODO: finish upload mode
- //this.main.reportError("editor", "Instructor mode has not been implemented");
- }
- BlockPyEditor.prototype.changeMode = function () {
- if (main.model.settings.editor() == "Blocks") {
- main.model.settings.editor("Text");
- } else {
- main.model.settings.editor("Blocks");
- }
- }
- /**
- * Dispatch method to set the mode to the given argument.
- * If the mode is invalid, an editor error is reported. If the
- *
- * @param {String} mode - The new mode to set to ("Blocks", "Text", or "Instructor")
- */
- BlockPyEditor.prototype.setMode = function (mode) {
- // Either update the model, or go with the model's
- if (mode === undefined) {
- mode = this.main.model.settings.editor();
- } else {
- this.main.model.settings.editor(mode);
- }
- // Dispatch according to new mode
- if (mode == 'Blocks') {
- this.setModeToBlocks();
- } else if (mode == 'Text') {
- this.setModeToText();
- } else if (mode == 'Split') {
- this.setModeToSplit();
- } else if (mode == 'Instructor') {
- this.setModeToInstructor();
- } else if (mode == 'Upload') {
- this.setModeToText();
- }
- // else {
- // this.main.components.feedback.internalError("" + mode, "Invalid Mode", "The editor attempted to change to an invalid mode.")
- // }
- }
- /**
- * Actually changes the value of the CodeMirror instance
- *
- * @param {String} code - The new code for the CodeMirror
- */
- BlockPyEditor.prototype.setText = function (code) {
- if (code == undefined || code.trim() == "") {
- this.codeMirror.setValue("\n");
- } else {
- this.codeMirror.setValue(code);
- }
- // Ensure that we maintain proper highlighting
- this.refreshHighlight();
- }
- BlockPyEditor.prototype.showConversionError = function () {
- var error = this.blocksFailed;
- //this.main.components.feedback.convertSkulptSyntax(error);
- }
- BlockPyEditor.prototype.setBlocks = function (python_code) {
- if (!(!this.main.model.assignment.upload() &&
- (this.main.model.settings.filename() == "__main__" ||
- this.main.model.settings.filename() == "starting_code"))) {
- return false;
- }
- var xml_code = "";
- if (python_code !== '' && python_code !== undefined && python_code.trim().charAt(0) !== '<') {
- var result = this.converter.convertSource(python_code);
- xml_code = result.xml;
- window.clearTimeout(this.blocksFailedTimeout);
- if (result.error !== null) {
- this.blocksFailed = result.error;
- var editor = this;
- this.blocksFailedTimeout = window.setTimeout(function () {
- if (editor.main.model.settings.editor() != 'Text') {
- editor.showConversionError();
- }
- }, 500)
- } else {
- this.blocksFailed = false;
- //this.main.components.feedback.clearEditorErrors();
- }
- }
- var error_code = this.converter.convertSourceToCodeBlock(python_code);
- var errorXml = Blockly.Xml.textToDom(error_code);
- if (python_code == '' || python_code == undefined || python_code.trim() == '') {
- this.blockly.clear();
- } else if (xml_code !== '' && xml_code !== undefined) {
- var blocklyXml = Blockly.Xml.textToDom(xml_code);
- try {
- this.setBlocksFromXml(blocklyXml);
- pythonnewcode = python_code;
- } catch (e) {
- console.error(e);
- this.setBlocksFromXml(errorXml);
- }
- } else {
- this.setBlocksFromXml(errorXml);
- }
- Blockly.Events.disable();
- /*
- // Parsons shuffling
- if (this.main.model.assignment.parsons()) {
- this.blockly.shuffle();
- } else {
- this.blockly.align();
- }
- */
- Blockly.Events.enable();
- if (this.previousLine !== null) {
- this.refreshBlockHighlight(this.previousLine);
- }
- }
- BlockPyEditor.prototype.clearDeadBlocks = function () {
- var all_blocks = this.blockly.getAllBlocks();
- all_blocks.forEach(function (elem) {
- if (!Blockly.Python[elem.type]) {
- elem.dispose(true);
- }
- });
- }
- /**
- * Attempts to update the model for the current code file from the
- * block workspace. Might be prevented if an update event was already
- * percolating.
- */
- BlockPyEditor.prototype.updateBlocks = function () {
- if (!this.silenceBlock) {
- try {
- var newCode = Blockly.Python.workspaceToCode(this.blockly);
- pythonnewcode = newCode;
- } catch (e) {
- this.clearDeadBlocks();
- //this.main.components.feedback.editorError("Unknown Block", "It looks like you attempted to paste or load some blocks that were not known. Typically, this is because you failed to load in the dataset before trying to paste in a data block. If there are any black blocks on the canvas, delete them before continuing.", "Unknown Block");
- }
- // Update Model
- this.silenceModel = 2;
- var changed = this.main.setCode(newCode);
- if (!changed) {
- this.silenceModel = 0;
- } else {
- // Update Text
- this.silenceText = true;
- this.setText(newCode);
- }
- }
- }
- /**
- * Attempts to update the model for the current code file from the
- * text editor. Might be prevented if an update event was already
- * percolating. Also unhighlights any lines.
- */
- var timerGuard = null;
- BlockPyEditor.prototype.updateText = function (code) {
- if (!this.silenceText) {
- var newCode = code || this.codeMirror.getValue();
- // Update Model
- this.silenceModel = 2;
- this.main.setCode(newCode);
- // Update Blocks
- this.silenceBlock = true;
- this.setBlocks(newCode);
- this.unhighlightLines();
- this.resetBlockSilence();
- }
- this.silenceText = false;
- }
- /**
- * Resets the silenceBlock after a short delay
- */
- BlockPyEditor.prototype.resetBlockSilence = function () {
- var editor = this;
- if (editor.silenceBlockTimer != null) {
- clearTimeout(editor.silenceBlockTimer);
- }
- this.silenceBlockTimer = window.setTimeout(function () {
- editor.silenceBlock = false;
- editor.silenceBlockTimer = null;
- }, 40);
- };
- /**
- * Updates the text editor from the current code file in the
- * model. Might be prevented if an update event was already
- * percolating.
- */
- BlockPyEditor.prototype.updateTextFromModel = function () {
- if (this.silenceModel == 0) {
- var code = this.main.model.program();
- this.silenceText = true;
- this.setText(code);
- } else {
- this.silenceModel -= 1;
- }
- }
- /**
- * Updates the block editor from the current code file in the
- * model. Might be prevented if an update event was already
- * percolating. This can also report an error if one occurs.
- *
- * @returns {Boolean} Returns true upon success.
- */
- BlockPyEditor.prototype.updateBlocksFromModel = function () {
- if (this.silenceModel == 0) {
- var code = this.main.model.program().trim();
- this.silenceBlock = true;
- this.setBlocks(code);
- this.resetBlockSilence();
- } else {
- this.silenceModel -= 1;
- }
- }
- /**
- * Helper function for retrieving the current Blockly workspace as
- * an XML DOM object.
- *
- * @returns {XMLDom} The blocks in the current workspace.
- */
- BlockPyEditor.prototype.getBlocksFromXml = function () {
- return Blockly.Xml.workspaceToDom(this.blockly);
- }
- /**
- * Helper function for setting the current Blockly workspace to
- * whatever XML DOM is given. This clears out any existing blocks.
- */
- BlockPyEditor.prototype.setBlocksFromXml = function (xml) {
- //this.blockly.clear();
- Blockly.Xml.domToWorkspaceDestructive(xml, this.blockly);
- //console.log(this.blockly.getAllBlocks());
- }
- BlockPyEditor.prototype.clearBlocksFromXml = function () {
- this.blockly.clear();
- }
- /**
- * @property {Number} previousLine - Keeps track of the previously highlighted line.
- */
- BlockPyEditor.prototype.previousLine = null;
- /**
- * Assuming that a line has been highlighted previously, this will set the
- * line to be highlighted again. Used when we need to restore a highlight.
- */
- BlockPyEditor.prototype.refreshHighlight = function () {
- if (this.previousLine !== null) {
- if (this.previousLine < this.codeMirror.lineCount()) {
- this.codeMirror.addLineClass(this.previousLine, 'text', 'editor-error-line');
- }
- }
- // TODO: Shouldn't this refresh the highlight in the block side too?
- }
- /**
- * Highlights a line of code in the CodeMirror instance. This applies the "active" style
- * which is meant to bring attention to a line, but not suggest it is wrong.
- *
- * @param {Number} line - The line of code to highlight. I think this is zero indexed?
- */
- BlockPyEditor.prototype.highlightLine = function (line) {
- if (this.previousLine !== null) {
- if (this.previousLine < this.codeMirror.lineCount()) {
- this.codeMirror.removeLineClass(this.previousLine, 'text', 'editor-active-line');
- this.codeMirror.removeLineClass(this.previousLine, 'text', 'editor-error-line');
- }
- }
- if (line < this.codeMirror.lineCount()) {
- this.codeMirror.addLineClass(line, 'text', 'editor-active-line');
- }
- this.previousLine = line;
- }
- /**
- * Highlights a line of code in the CodeMirror instance. This applies the "error" style
- * which is meant to suggest that a line is wrong.
- *
- * @param {Number} line - The line of code to highlight. I think this is zero indexed?
- */
- BlockPyEditor.prototype.highlightError = function (line) {
- if (this.previousLine !== null) {
- if (this.previousLine < this.codeMirror.lineCount()) {
- this.codeMirror.removeLineClass(this.previousLine, 'text', 'editor-active-line');
- this.codeMirror.removeLineClass(this.previousLine, 'text', 'editor-error-line');
- }
- }
- if (line < this.codeMirror.lineCount()) {
- this.codeMirror.addLineClass(line, 'text', 'editor-error-line');
- }
- this.refreshBlockHighlight(line);
- this.previousLine = line;
- }
- /**
- * Highlights a block in Blockly. Unfortunately, this is the same as selecting it.
- *
- * @param {Number} block - The ID of the block object to highlight.
- */
- BlockPyEditor.prototype.highlightBlock = function (block) {
- //this.blockly.highlightBlock(block);
- }
- /**
- * Used to restore a block's highlight when travelling from the code tab. This
- * uses a mapping between the blocks and text that is generated from the parser.
- * The parser has stored the relevant line numbers for each block in the XML of the
- * block. Very sophisticated, and sadly fairly fragile.
- * TODO: I believe there's some kind of off-by-one error here...
- *
- * @param {Number} line - The line of code to highlight. I think this is zero indexed?
- */
- BlockPyEditor.prototype.refreshBlockHighlight = function (line) {
- if (this.blocksFailed) {
- this.blocksFailed = false;
- return;
- }
- if (this.main.model.settings.editor() != "Blocks" &&
- this.main.model.settings.editor() != "Split") {
- return;
- }
- var all_blocks = this.blockly.getAllBlocks();
- //console.log(all_blocks.map(function(e) { return e.lineNumber }));
- var blockMap = {};
- all_blocks.forEach(function (elem) {
- var lineNumber = parseInt(elem.lineNumber, 10);
- if (lineNumber in blockMap) {
- blockMap[lineNumber].push(elem);
- } else {
- blockMap[lineNumber] = [elem];
- }
- });
- if (1 + line in blockMap) {
- var hblocks = blockMap[1 + line];
- var blockly = this.blockly;
- hblocks.forEach(function (elem) {
- //elem.addSelect();
- blockly.highlightBlock(elem.id, true);
- });
- /*if (hblocks.length > 0) {
- this.blockly.highlightBlock(hblocks[0].id, true);
- }*/
- }
- }
- /**
- * Removes the outline around a block. Currently unused.
- */
- BlockPyEditor.prototype.unhighlightBlock = function () {
- // TODO:
- }
- /**
- * Removes any highlight in the text code editor.
- *
- */
- BlockPyEditor.prototype.unhighlightLines = function () {
- if (this.previousLine !== null) {
- if (this.previousLine < this.codeMirror.lineCount()) {
- this.codeMirror.removeLineClass(this.previousLine, 'text', 'editor-active-line');
- this.codeMirror.removeLineClass(this.previousLine, 'text', 'editor-error-line');
- }
- }
- this.previousLine = null;
- }
- /**
- * Removes any highlight in the text code editor.
- *
- */
- BlockPyEditor.prototype.unhighlightAllLines = function () {
- var editor = this.codeMirror;
- var count = editor.lineCount(),
- i;
- for (i = 0; i < count; i++) {
- editor.removeLineClass(i, 'text', 'editor-error-line');
- }
- }
- /**
- * DEPRECATED, thankfully
- * Builds up an array indicating the relevant block ID for a given step.
- * Operates on the current this.blockly instance
- * It works by injecting __HIGHLIGHT__(id); at the start of every line of code
- * and then extracting that with regular expressions. This makes it vulnerable
- * if someone decides to use __HIGHLIGHT__ in their code. I'm betting on that
- * never being a problem, though. Still, this was a miserable way of accomplishing
- * the desired behavior.
- */
- BlockPyEditor.prototype.getHighlightMap = function () {
- // Protect the current STATEMENT_PREFIX
- var backup = Blockly.Python.STATEMENT_PREFIX;
- Blockly.Python.STATEMENT_PREFIX = '__HIGHLIGHT__(%1);';
- Blockly.Python.addReservedWords('__HIGHLIGHT__');
- // Get the source code, injected with __HIGHLIGHT__(id)
- var highlightedCode = Blockly.Python.workspaceToCode(this.blockly);
- Blockly.Python.STATEMENT_PREFIX = backup;
- // Build up the array by processing the highlighted code line-by-line
- var highlightMap = [];
- var lines = highlightedCode.split("\n");
- for (var i = 0; i < lines.length; i++) {
- // Get the block ID from the line
- var id = lines[i].match(/\W*__HIGHLIGHT__\(\'(.+?)\'\)/);
- if (id !== null) {
- // Convert it into a base-10 number, because JavaScript.
- highlightMap[i] = parseInt(id[1], 10);
- }
- }
- return highlightMap;
- }
- /**
- * Updates the current file being edited in the editors.
- * This appears to be deprecated.
- *
- * @param {String} name - The name of the file being edited (e.g, "__main__", "starting_code")
- */
- /*
- BlockPyEditor.prototype.changeProgram = function(name) {
- console.log("TEST")
- this.silentChange_ = true;
- if (name == 'give_feedback') {
- this.setMode('Text');
- }
- this.model.settings.filename = name;
- this.editor.setPython(this.model.programs[name]);
- this.toolbar.elements.programs.find("[data-name="+name+"]").click();
- }*/
- /**
- * Eventually will be used to update "levels" of sophistication of the code interface.
- * Currently unimplemented and unused.
- */
- BlockPyEditor.prototype.setLevel = function () {
- var level = this.main.model.settings.level();
- }
- /**
- * Maps short category names in the toolbox to the full XML used to
- * represent that category as usual. This is kind of a clunky mechanism
- * for managing the different categories, and doesn't allow us to specify
- * individual blocks.
- */
- BlockPyEditor.CATEGORY_MAP = {
- 'Decisions': '<category id="catLogic" name="Logic" colour="#4c97ff">' +
- '<block type="controls_if"></block>' +
- '<block type="logic_compare">' +
- '</block>' +
- '<block type="logic_operation"></block>' +
- '<block type="logic_negate"></block>' +
- '<block type="logic_boolean"></block>' +
- '<block type="logic_null"></block>' +
- '<block type="logic_ternary"></block>' +
- '<block type="CocoRobo_return"></block>' +
- '<block type="CocoRobo_try_except"></block>' +
- '<block type="CocoRobo_try_except_finally"></block>' +
- '<block type="CocoRobo_type"></block>' +
- '<block type="CocoRobo_type_is"></block>' +
- '<block type="CocoRobo_eval"></block>' +
- '</category>',
- 'Iteration': '<category id="catLoops" name="Loops" colour="#9d64fd">' +
- '<block type="controls_repeat_forever"></block>' +
- '<block type="controls_repeat_ext">' +
- '<value name="TIMES">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">10</field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<block type="controls_whileUntil"></block>' +
- '<block type="controls_for">' +
- '<value name="FROM">' +
- '<shadow type="math_number">' +
- '<field name="NUM">1</field>' +
- '</shadow>' +
- '</value>' +
- '<value name="TO">' +
- '<shadow type="math_number">' +
- '<field name="NUM">10</field>' +
- '</shadow>' +
- '</value>' +
- '<value name="BY">' +
- '<shadow type="math_number">' +
- '<field name="NUM">1</field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<block type="controls_forEach"></block>' +
- '<block type="controls_flow_statements"></block>' +
- '</category>',
- 'Calculation': '<category id="catMath" name="Math" colour="#5472ea">' +
- '<block type="math_number" gap="32"></block>' +
- '<block type="math_arithmetic">' +
- ' <value name="A">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- '</shadow>' +
- '</value>' +
- '<value name="B">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<block type="math_degrad"></block>' +
- '<block type="math_single">' +
- '<value name="NUM">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">9</field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<block type="math_trig">' +
- '<value name="NUM">' +
- '<shadow type="math_angle">' +
- ' <field name="angle">45</field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<!--block type="math_trig">' +
- ' <value name="NUM">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">45</field>' +
- '</shadow>' +
- '</value>' +
- '</block-->' +
- '<block type="math_constant"></block>' +
- '<block type="math_number_property">' +
- '<value name="NUMBER_TO_CHECK">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<block type="math_round">' +
- '<value name="NUM">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">3.1</field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<block type="math_keep_decimal">' +
- '<value name="NUM">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">3.1415926</field>' +
- '</shadow>' +
- '</value>' +
- '<value name="PLACE">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">2</field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<block type="math_on_list"></block>' +
- '<block type="math_modulo">' +
- '<value name="DIVIDEND">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">64</field>' +
- '</shadow>' +
- '</value>' +
- ' <value name="DIVISOR">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">10</field>' +
- '</shadow>' +
- '</value>' +
- ' </block>' +
- '<block type="math_division_consult">' +
- ' <value name="DIVIDEND">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">64</field>' +
- '</shadow>' +
- '</value>' +
- '<value name="DIVISOR">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">10</field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<block type="math_constrain">' +
- ' <value name="VALUE">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">50</field>' +
- '</shadow>' +
- '</value>' +
- '<value name="LOW">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- '</shadow>' +
- '</value>' +
- ' <value name="HIGH">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">100</field>' +
- '</shadow>' +
- ' </value>' +
- '</block>' +
- ' <block type="labplus_mapping">' +
- '<value name="inputNum"><shadow type="math_number"><field name="NUM">10</field></shadow></value>' +
- '<value name="bMin"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' +
- '<value name="bMax"><shadow type="math_number"><field name="NUM">100</field></shadow></value>' +
- '<value name="cMin"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' +
- '<value name="cMax"><shadow type="math_number"><field name="NUM">200</field></shadow></value>' +
- '</block>' +
- '<block type="math_random_int">' +
- '<value name="FROM">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- '</shadow>' +
- '</value>' +
- '<value name="TO">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">100</field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<block type="math_random_randrange">' +
- '<value name="start"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' +
- ' <value name="stop"><shadow type="math_number"><field name="NUM">10</field></shadow></value>' +
- '<value name="step"><shadow type="math_number"><field name="NUM">2</field></shadow></value>' +
- '</block>' +
- '<block type="math_random_float"></block>' +
- '<block type="math_convert"></block>' +
- '<block type="math_number_bits_ops">' +
- '<value name="A">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- '</shadow>' +
- '</value>' +
- '<value name="B">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<block type="bit_inversion">' +
- '<value name="data"><shadow type="math_number"><field name="NUM">60</field></shadow></value>' +
- '</block>' +
- '<block type="CocoRobo_ten_convert_to">' +
- ' <value name="int_num"><shadow type="math_number"><field name="NUM">10</field></shadow></value>' +
- '</block>' +
- '<block type="CocoRobo_convert_to_ten">' +
- ' <value name="convert_str"><shadow type="text"><field name="TEXT">11</field></shadow></value>' +
- '</block>' +
- '<block type="CocoRobo_ten_converted_to_bytes">' +
- ' <value name="convert_num"><shadow type="math_number"><field name="NUM">11</field></shadow></value>' +
- '</block>' +
- '<block type="CocoRobo_int_to_chr">' +
- ' <value name="convert_num"><shadow type="math_number"><field name="NUM">97</field></shadow></value>' +
- '</block>' +
- '<block type="CocoRobo_chr_to_int">' +
- ' <value name="convert_chr"><shadow type="text"><field name="TEXT">a</field></shadow></value>' +
- ' </block>' +
- ' <block type="CocoRobo_str_to_hex">' +
- '<value name="convert_chr"><shadow type="text"><field name="TEXT">abcdfg</field></shadow></value>' +
- '</block>' +
- '<block type="CocoRobo_hex_to_bin_str">' +
- '<value name="convert_chr"><shadow type="text"><field name="TEXT">313233</field></shadow></value>' +
- ' </block>' +
- '<block type="CocoRobo_data_to_base64">' +
- ' <value name="data"><shadow type="text"><field name="TEXT">cocorobo</field></shadow></value>' +
- '</block>' +
- '<block type="CocoRobo_base64_to_data">' +
- ' <value name="data"><shadow type="text"><field name="TEXT">bXB5dGhvbg==</field></shadow></value>' +
- '</block>' +
- '</category>',
- 'Variables': '<category id="catVariables" name="Variables" custom="VARIABLE" colour="#ffab2f">' +
- '</category>',
- 'Values': '<category id="catText" name="Text" colour="#33cc99">' +
- // '<block type="esp32_main_controller_text_print">' +
- // '<value name="TEXT">' +
- // '<shadow type="esp32_main_controller_text">' +
- // '<field name="TEXT"></field>' +
- // '</shadow>' +
- // ' </value>' +
- // '</block>' +
- ' <block type="text"><field name="TEXT"></field></block>' +
- // '<block type="esp32_main_controller_text"></block>' +
- '<block type="text_join"><mutation items="1"></mutation></block>' +
- ' <block type="text_join"></block>' +
- '<block type="text_split_string_by_delimiter">' +
- '</block>' +
- ' <block type="text_format">' +
- ' <value name="FORMAT">' +
- ' <shadow type="text"><field name="TEXT">Value: %.2f</field></shadow>' +
- ' </value>' +
- ' <value name="CONTENT">' +
- ' <block type="tuple_create_with_items_insert">' +
- ' <mutation items="1"></mutation>' +
- ' <value name="ADD0">' +
- ' <block type="math_number">' +
- ' <field name="NUM">3.1415926</field>' +
- ' </block>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' </block>' +
- ' <block type="text_format2">' +
- ' <value name="FORMAT">' +
- ' <shadow type="text"><field name="TEXT">Value: {:.3}</field></shadow>' +
- ' </value>' +
- ' <value name="CONTENT">' +
- ' <block type="tuple_create_with_items_insert">' +
- ' <mutation items="1"></mutation>' +
- ' <value name="ADD0">' +
- ' <block type="math_number">' +
- ' <field name="NUM">3.1415926</field>' +
- ' </block>' +
- ' </value>' +
- '</block>' +
- '</value>' +
- ' </block>' +
- '<block type="CocoRobo_text_ESC">' +
- '</block>' +
- '<block type="text_append_text">' +
- '<value name="text_abc"><shadow type="text"><field name="TEXT">abc</field></shadow></value>' +
- '<value name="append_text"><shadow type="text"><field name="TEXT">def</field></shadow></value>' +
- '</block>' +
- '<block type="text_is_number">' +
- '<value name="TEXT">' +
- ' <shadow type="text">' +
- '<field name="TEXT"></field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<block type="text_length">' +
- '<value name="VALUE">' +
- '<shadow type="text">' +
- ' <field name="TEXT"></field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<block type="text_isEmpty">' +
- '<value name="VALUE">' +
- '<shadow type="text">' +
- ' <field name="TEXT"></field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<block type="text_indexOf">' +
- '<value name="VALUE">' +
- ' <shadow type="text">' +
- '<field name="TEXT">abc</field>' +
- '</shadow>' +
- '</value>' +
- '<value name="FIND">' +
- ' <shadow type="text">' +
- '<field name="TEXT">b</field>' +
- ' </shadow>' +
- '</value>' +
- '</block>' +
- '<block type="text_charAt">' +
- '<value name="VALUE">' +
- '<shadow type="text">' +
- '<field name="TEXT">abc</field>' +
- ' </shadow>' +
- '</value>' +
- ' </block>' +
- ' <block type="text_getSubstring">' +
- '<value name="STRING">' +
- ' <shadow type="text">' +
- '<field name="TEXT">abc</field>' +
- ' </shadow>' +
- '</value>' +
- ' </block>' +
- ' <block type="text_changeCase">' +
- '<value name="TEXT">' +
- ' <shadow type="text">' +
- ' <field name="TEXT"></field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' <block type="text_trim">' +
- ' <value name="TEXT">' +
- ' <shadow type="text">' +
- ' <field name="TEXT"></field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' <block type="text_to_byte">' +
- ' <value name="TEXT">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">abc</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' <block type="CocoRobo_bytes_decode">' +
- ' <value name="bytes_decode"></value>' +
- '</block>' +
- '<block type="CocoRobo_ujson_dumps">' +
- ' <value name="data"><shadow type="text_dict"><field name="TEXT">"Age":8</field></shadow></value>' +
- '</block>' +
- '<block type="CocoRobo_ujson_loads">' +
- '<value name="data"><shadow type="text"><field name="TEXT">{"Age":8}</field></shadow></value>' +
- '</block>' +
- '<block type="CocoRobo_code_annotation">' +
- '<value name="data"><shadow type="text"><field name="TEXT"></field></shadow></value>' +
- '</block>' +
- '</category>',
- 'Lists': '<category id="catLists" name="Lists" colour="#40bfe4">' +
- '<block type="lists_create_with"><mutation items="0"></mutation></block>' +
- '<block type="lists_create_with"></block>' +
- ' <block type="text_list"><field name="TEXT">0, 0, 0</field></block>' +
- ' <!--block type="file_to_list">' +
- ' <value name="file_path"><shadow type="text"><field name="TEXT">1.txt</field></shadow></value>' +
- ' </block-->' +
- ' <block type="CocoRobo_return_list">' +
- ' <value name="list_name"><block type="variables_get"><field name="VAR">my_list</field></block></value>' +
- ' <value name="list_items"><shadow type="text_list"><field name="TEXT">0, 0, 0</field></shadow></value>' +
- ' </block>' +
- ' <block type="list_order_item">' +
- ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' +
- ' <value name="list_order_item"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' +
- ' </block>' +
- ' <block type="lists_append">' +
- ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' +
- ' </block>' +
- ' <block type="list_item_exist">' +
- ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' +
- ' <value name="list_item"><shadow type="text"><field name="TEXT">cocorobo</field></shadow></value>' +
- ' </block>' +
- ' <block type="lists_extend">' +
- ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' +
- ' <value name="extend_list"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' +
- ' </block>' +
- ' <block type="lists_clear">' +
- ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' +
- ' </block>' +
- ' <block type="lists_repeat">' +
- '<value name="NUM">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">5</field>' +
- ' </shadow>' +
- '</value>' +
- ' </block>' +
- ' <block type="lists_length"></block>' +
- ' <block type="lists_isEmpty"></block>' +
- ' <block type="list_first_index">' +
- ' <value name="elem"><shadow type="text"><field name="TEXT">cocorobo</field></shadow></value>' +
- ' <value name="my_list"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' +
- ' </block>' +
- ' <block type="set_list_order_item">' +
- ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' +
- ' <value name="list_order_item"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' +
- ' <value name="set_value"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' +
- ' </block>' +
- ' <block type="insert_list_order_item">' +
- ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' +
- ' <value name="list_order_item"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' +
- ' <value name="set_value"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' +
- ' </block>' +
- ' <block type="parts_of_list">' +
- ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' +
- ' <value name="start_item"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' +
- ' <value name="end_item"><shadow type="math_number"><field name="NUM">2</field></shadow></value>' +
- ' </block>' +
- '<block type="lists_getIndex">' +
- ' <mutation statement="true" at="true"></mutation>' +
- ' <field name="MODE">REMOVE</field>' +
- ' <field name="WHERE">FROM_START</field>' +
- ' <value name="VALUE">' +
- ' <shadow type="text_list"><field name="TEXT"></field></shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="lists_getIndex">' +
- ' <mutation statement="false" at="true"></mutation>' +
- ' <field name="MODE">GET_REMOVE</field>' +
- ' <field name="WHERE">FROM_START</field>' +
- ' <value name="VALUE">' +
- ' <shadow type="text_list"><field name="TEXT"></field></shadow>' +
- ' </value>' +
- '</block>' +
- ' <block type="lists_split">' +
- ' <value name="DELIM"><shadow type="text"><field name="TEXT">,</field></shadow></value>' +
- ' </block>' +
- ' <block type="lists_sort"></block>' +
- '</category>',
- 'Dictionary': '<category id="catDictionary" name="Dictionary" colour="32">' +
- ' <block type="dict_create_with_items_insert"></block>' +
- ' <block type="text_dict"><field name="TEXT">"Age":8</field></block>' +
- ' <block type="dict_create_with">' +
- ' <value name="dict_name"><block type="variables_get"><field name="VAR">my_dict</field></block></value>' +
- ' <value name="dict_items"><shadow type="text_dict"><field name="TEXT">"Age":8</field></shadow></value>' +
- ' </block>' +
- ' <block type="add_dict_key_value">' +
- ' <value name="dict_name"><shadow type="text_dict"><field name="TEXT"></field></shadow></value>' +
- ' <value name="dict_items"><shadow type="text"><field name="TEXT">Age</field></shadow></value>' +
- ' <value name="add_value"><shadow type="math_number"><field name="NUM">10</field></shadow></value>' +
- ' </block>' +
- ' <block type="dict_key_value">' +
- ' <value name="dict_name"><shadow type="text_dict"><field name="TEXT"></field></shadow></value>' +
- ' <value name="dict_items"><shadow type="text"><field name="TEXT">Age</field></shadow></value>' +
- ' </block>' +
- ' <block type="dict_length">' +
- ' <value name="dict_name"><shadow type="text_dict"><field name="TEXT"></field></shadow></value>' +
- ' </block>' +
- ' <block type="dict_key_exist">' +
- ' <value name="dict_name"><shadow type="text_dict"><field name="TEXT"></field></shadow></value>' +
- ' <value name="dict_items"><shadow type="text"><field name="TEXT">Age</field></shadow></value>' +
- ' </block>' +
- ' <block type="dict_key_or_val_list">' +
- ' <value name="dict_name"><shadow type="text_dict"><field name="TEXT"></field></shadow></value>' +
- ' </block>' +
- '</category>',
- // 'Tuples': '<category id="catTuples" name="Tuples" colour="#0090d1">' +
- // '</category>',
- 'Tuples': '<category id="catTuples" name="Tuples" colour="192">' +
- ' <block type="tuple_create_with_items_insert"></block>' +
- '<block type="text_tuple"><field name="TEXT">"cocorobo",</field></block>' +
- '<block type="tuple_create_with">' +
- ' <value name="tuple_name"><block type="variables_get"><field name="VAR">my_tuple</field></block></value>' +
- ' <value name="tuple_items"><shadow type="text_tuple"><field name="TEXT">"cocorobo",</field></shadow></value>' +
- ' </block>' +
- ' <block type="tuple_order_item">' +
- ' <value name="tuple_name"><shadow type="text_tuple"><field name="TEXT"></field></shadow></value>' +
- ' <value name="tuple_order_item"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' +
- '</block>' +
- '<block type="tuple_min_max_len">' +
- ' <value name="tuple_name"><shadow type="text_tuple"><field name="TEXT"></field></shadow></value>' +
- ' </block>' +
- '<block type="tuple_item_exist">' +
- ' <value name="tuple_name"><shadow type="text_tuple"><field name="TEXT"></field></shadow></value>' +
- ' <value name="tuple_item"><shadow type="text"><field name="TEXT">cocorobo</field></shadow></value>' +
- '</block>' +
- '<block type="parts_of_tuple">' +
- ' <value name="tuple_name"><shadow type="text_tuple"><field name="TEXT"></field></shadow></value>' +
- ' <value name="tuple_item"><shadow type="math_number"><field name="NUM">2</field></shadow></value>' +
- '</block>' +
- ' <block type="parts_of_tuple2">' +
- ' <value name="tuple_name"><shadow type="text_tuple"><field name="TEXT"></field></shadow></value>' +
- ' <value name="start_item"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' +
- ' <value name="end_item"><shadow type="math_number"><field name="NUM">2</field></shadow></value>' +
- '</block>' +
- '<block type="list_to_tuple">' +
- ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' +
- '</block>' +
- '</category>',
- 'Set': '<category id="catSet" name="Set" colour="160">' +
- '<block type="set_create_with_items_insert"></block>' +
- ' <block type="text_set"><field name="TEXT">"string", 0.9, ("tuple",)</field></block>' +
- ' <block type="set_create_with">' +
- ' <value name="set_name"><block type="variables_get"><field name="VAR">my_set</field></block></value>' +
- ' <value name="set_items"><shadow type="text_set"></shadow></value>' +
- ' </block>' +
- ' <block type="sets_update_ways">' +
- ' <value name="set_name"><block type="variables_get"><field name="VAR">my_set</field></block></value>' +
- ' <value name="set_1_name"><shadow type="text_set"></shadow></value>' +
- ' </block>' +
- ' <block type="set_update_with">' +
- ' <value name="set_name"><shadow type="text_set"></shadow></value>' +
- ' <value name="set_items"></value>' +
- ' </block>' +
- ' <block type="set_subset_superset">' +
- ' <value name="set_name"><shadow type="text_set"></shadow></value>' +
- ' <value name="set_1_name"><shadow type="text_set"></shadow></value>' +
- ' </block>' +
- ' <block type="intersection_of_sets">' +
- ' <value name="set_name"><shadow type="text_set"></shadow></value>' +
- ' <value name="set_1_name"><shadow type="text_set"></shadow></value>' +
- ' </block>' +
- ' <block type="len_of_sets">' +
- ' <value name="set_name"><shadow type="text_set"></shadow></value>' +
- '</block>' +
- ' <block type="get_sets_pop">' +
- ' <value name="set_name"><shadow type="text_set"></shadow></value>' +
- '</block>' +
- '</category>',
- 'Functionsa': '<category id="catFunctions" name="Functions" custom="PROCEDURE" colour="#ff6381">' +
- '</category>',
- 'Python': '<category name="Python" colour="180">' +
- '<block type="raw_block"></block>' +
- '<block type="raw_expression"></block>' +
- '</category>',
- 'Output': '<category id="catOutput" name="Output" colour="#ff8b2c">' +
- // '<block type="esp32_main_controller_io_from_digital_pin">' +
- // ' <value name="digital_pin_input">' +
- // '<shadow type="math_number">' +
- // ' <field name="NUM">1</field>' +
- // '</shadow>' +
- // '</value>' +
- // '</block>' +
- // '<block type="esp32_main_controller_io_set_digital_pin">' +
- // ' <value name="digital_pin_input">' +
- // '<shadow type="math_number">' +
- // ' <field name="NUM">1</field>' +
- // '</shadow>' +
- // '</value>' +
- // ' <value name="high_low">' +
- // '<shadow type="esp32_main_controller_io_high_low">' +
- // '</shadow>' +
- // '</value>' +
- // '</block>' +
- // '<block type="esp32_main_controller_io_set_analog_pin">' +
- // ' <value name="analog_pin_input">' +
- // '</value>' +
- // ' <value name="pwm">' +
- // '</value>' +
- // '</block>' +
- // // PWM ai
- // '<block type="ai_main_controller_io_set_analog_pin">' +
- // ' <value name="analog_pin_input">' +
- // '</value>' +
- // ' <value name="pwm">' +
- // '</value>' +
- // '</block>' +
- // '<block type="esp32_main_controller_io_from_analog_pin">' +
- // '</block>' +
- // '<block type="esp32_main_controller_io_out_pwm"></block>' +
- // '<block type="esp32_main_controller_io_high_low"></block>' +
- // '<block type="esp32_main_controller_io_analog_pin_1"></block>' +
- // '<block type="esp32_main_controller_io_analog_pin_2"></block>' +
- '</category>',
- 'Files': '<category id="catFiles" name="Files" colour="32">' +
- '<block type="iot_system_run">' +
- ' <value name="PATH">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/your_python_code.py</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="iot_system_create_file">' +
- ' <value name="filename">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">cocorobo.txt</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="PATH">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="iot_system_open_file">' +
- ' <value name="filename">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">cocorobo.txt</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="PATH">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="iot_system_write_file">' +
- ' <value name="WPATH">' +
- ' <shadow type="text">' +
- ' <field name="TEXT"></field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="iot_system_close_file"></block>' +
- '<block type="iot_system_input_file">' +
- ' <value name="filename">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">cocorobo.txt</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="PATH">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/</field>' +
- ' </shadow>' +
- ' </value>' + '</block>' +
- '<block type="iot_system_delete_file">' +
- ' <value name="PATH">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/cocorobo.txt</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '</category>',
- 'Time': '<category id="catTime" name="Time" colour="#fabe23">' +
- ' <block type="time_delay">' +
- ' <value name="DELAY_TIME_MILI">' +
- ' <block type="math_number">' +
- ' <field name="NUM">1000</field>' +
- ' </block>' +
- ' </value>' +
- ' </block>' +
- // ' <block type="time_delay">' +
- // ' <value name="DELAY_TIME_MICRO">' +
- // ' <block type="math_number">' +
- // ' <field name="NUM">1000</field>' +
- // ' </block>' +
- // ' </value>' +
- // ' </block>' +
- ' <block type="time_delayseconds">' +
- ' <value name="DELAY_TIME_MICRO">' +
- ' <block type="math_number">' +
- ' <field name="NUM">1</field>' +
- ' </block>' +
- ' </value>' +
- ' </block>' +
- // ' <block type="time_millis"></block>' +
- // ' <block type="time_micros"></block>' +
- ' <block type="esp32_get_current_date"></block>' +
- ' <block type="esp32_main_controller_time_timer_init"></block>' +
- ' <block type="esp32_main_controller_time_timer_get_current"></block>' +
- ' <block type="esp32_main_controller_time_timer_clear"></block>' +
- ' <block type="esp32_main_controller_time_period_timer"></block>' +
- ' <block type="esp32_main_controller_time_period_timer_clear"></block>' +
- '</category>',
- 'Serial Comm.': '<category id="catSerialComm" name="SerialComm" colour="#22b845">' +
- '<block type="serial_comm_print">' +
- ' <value name="serial_comm_input">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">Hello World!</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="serial_write_data_coco">' +
- ' <value name="ADD0">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">Data</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="serial_write_data">' +
- ' <value name="ADD1">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">Data</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="serial_read_data_setup"></block>' +
- '<block type="serial_read_data_setup_arduino"></block>' +
- '<block type="serial_read_data_all"></block>' +
- // '<block type="serial_read_data_all_usb"></block>' +
- '<block type="serial_read_data"></block>' +
- '<block type="serial_send_data_to_microbit">' +
- ' <value name="NAME">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">Data</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="serial_send_data_to_control_panel">' +
- ' <value name="NAME">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">Data</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="serial_send_data_to_arduino">' +
- ' <value name="NAME">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">Data</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '</category>',
- 'MainBoard':
- '<category id="catMainBoard" name="Main Board" colour="#3163ed">' +
- '<category id="catBasics" name="Basics" colour="#d42b03">' +
- '</category>' +
- '<category id="catMainWifi" name="Wi-Fi" colour="#386dc8">' +
- '</category>' +
- '<category id="catWeb" name="Web" colour="#183895">' +
- '</category>' +
- '<category id="catIoTService" name="IoT Service" colour="#3c7683">' +
- '</category>' +
- '</category>',
- 'A.I.Board': '<category id="catAI" name="基础硬件" colour="#f76734">' +
- /*
- _ ___ ____ _
- / \ |_ _| | __ ) __ _ ___(_) ___
- / _ \ | | | _ \ / _` / __| |/ __|
- / ___ \ | | | |_) | (_| \__ \ | (__
- /_/ \_\___| |____/ \__,_|___/_|\___|
-
- */
- '<category id="catAIBasic" name="Basic" colour="#d42b03">' +//基础
- '<label id="basis_button" text="Basis button" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="ai_v831_button_read_pressed"></block>' +
- '<block type="ai_v831_button_read_released"></block>' +
- '<block type="ai_v831_button_loosen"></block>' +
- // '<block type="ai_v831_button_del"></block>' +
- '<label id="catFASTLED" text="灯光" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="ai_v831_led_light_up"></block>' +
- '<block type="ai_v831_led_light_off"></block>' +
- // '<block type="ai_v831_button_read_released_to"></block>' +
- '<label id="rgb_light" text="RGB灯光" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="ai_v831_rgb_light_up">' +
- ' <value name="rgb_value">' +
- ' <block type="ai_lcd_rgb_value_input">' +
- ' <value name="rgb_value_r">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="rgb_value_g">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="rgb_value_b">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_v831_rgb_light_off"></block>' +
- '</category>' +
- '<category id="catOutput" name="输入 / 输出" colour="#ff8b2c">' +
- '<block type="esp32_main_controller_io_from_digital_pin">' +
- '</block>' +
- '<block type="esp32_main_controller_io_set_digital_pin">' +
- ' <value name="digital_pin_input">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- '</shadow>' +
- '</value>' +
- ' <value name="high_low">' +
- '<shadow type="esp32_main_controller_io_high_low">' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- '<block type="esp32_main_controller_io_set_analog_pin">' +
- ' <value name="analog_pin_input">' +
- // '<shadow type="math_number">' +
- // ' <field name="NUM">1</field>' +
- // '</shadow>' +
- ' <block type="esp32_main_controller_io_set_pin"></block>' +
- '</value>' +
- ' <value name="pwm">' +
- '<shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- '</shadow>' +
- '</value>' +
- '</block>' +
- // // PWM ai
- // '<block type="ai_main_controller_io_set_analog_pin">' +
- // ' <value name="analog_pin_input">' +
- // '</value>' +
- // ' <value name="pwm">' +
- // '</value>' +
- // '</block>' +
- '<block type="esp32_main_controller_io_from_analog_pin">' +
- '</block>' +
- // '<block type="esp32_main_controller_io_out_pwm"></block>' +
- // '<block type="esp32_main_controller_io_high_low"></block>' +
- // '<block type="esp32_main_controller_io_analog_pin_1"></block>' +
- // '<block type="esp32_main_controller_io_analog_pin_2"></block>' +
- '</category>' +
- /*
- _ ___ __ __ _ _
- / \ |_ _| | \/ (_) ___ _ __ ___ _ __ | |__ ___ _ __ ___
- / _ \ | | | |\/| | |/ __| '__/ _ \| '_ \| '_ \ / _ \| '_ \ / _ \
- / ___ \ | | | | | | | (__| | | (_) | |_) | | | | (_) | | | | __/
- /_/ \_\___| |_| |_|_|\___|_| \___/| .__/|_| |_|\___/|_| |_|\___|
- |_|
- */
- // 传感器
- '<category id="catSensor" name="传感器" colour="#5fcd8e">' +
- '<label id="basis_light" text="光照传感器" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="esp32_main_controller_get_light"></block>' +
- '<label id="basis_environmental" text="温湿度传感器" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="esp32_main_controller_get_environmental_value"></block>' +
- '<label id="" text="QMI8658" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="esp32_main_controller_motion_acceleration"></block>' +
- // '<block type="esp32_main_controller_motion_rotation_measurement"></block>' +
- '<block type="esp32_main_controller_motion_tilt_angle"></block>' +
- '<block type="esp32_main_controller_motion_when_tilting_STATEMENT"></block>' +
- '</category>' +
- '<category id="catPower" name="动力" colour="#386dc8">' +
- '<label id="catServo" text="舵机" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="extension_servo_setup_on_ai"></block>' +
- '<block type="extension_servo_write_on_ai">' +
- ' <value name="degree">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">90</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<label id="catMOTOR" text="电机" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_motor_setup"></block>' +
- '<block type="ai_motor_run">' +
- ' <value name="speed">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">150</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_motor_stop">' +
- '</block>' +
- '</category>' +
- '<category id="catAIScreen" name="Screen" colour="#5cb2d6">' +
- '<label id="basis_function" text="Basis function" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="ai_lcd_screeninit"></block>' +
- // '<block type="ai_lcd_rotation"></block>' +
- // '<block type="ai_lcd_filp"></block>' +
- // '<block type="ai_lcd_screen"></block>' +
- // '<block type="ai_lcd_clear"></block>' +
- // '<block type="ai_lcd_rgb_value_input">' +
- // ' <value name="rgb_value_r">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">0</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' <value name="rgb_value_g">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">0</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' <value name="rgb_value_b">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">0</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // '</block>' +
- // '<block type="ai_lcd_XY">' +
- // ' <value name="A">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">0</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' <value name="B">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">0</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // '</block>' +
- // ' <block type="lcd_set_width_height">' +
- // ' <value name="WIDTH">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">320</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' <value name="HEIGHT">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">240</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' </block>' +
- '<block type="ai_lcd_font">' +
- ' <value name="save_path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/preset/fonts/CascadiaCodePL-Italic.ttf</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<label id="basis_carvas_draw" text="Basis carvas drawing" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="ai_lcd_showcarvas_set_cord">' +
- ' <value name="xy">' +
- ' <block type="lcd_set_position">' +
- ' <value name="POSX">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="POSY">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- '</block>' +
- // '<block type="ai_lcd_createnonecarvas">' +
- // ' <value name="wh">' +
- // ' <block type="lcd_set_width_height">' +
- // ' <value name="WIDTH">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">320</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' <value name="HEIGHT">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">240</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // '</block>' +
- // ' </value>' +
- // '</block>' +
- '<block type="ai_lcd_fill_screen_with_rgb">' +
- ' <value name="rgb_value">' +
- ' <block type="ai_lcd_rgb_value_input">' +
- ' <value name="rgb_value_r">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="rgb_value_g">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="rgb_value_b">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_lcd_textcarvas">' +
- ' <value name="POSA">' +
- ' <block type="lcd_set_position">' +
- ' <value name="POSX">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="POSY">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="CONTENT">' +
- ' <shadow type="text">' +
- ' <field name="TEXT"></field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="COLOR">' +
- ' <block type="lcd_set_color">' +
- ' </block>' +
- ' </value>' +
- ' <value name="Scale">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_lcd_textcarvas_new_line">' +
- ' <value name="POSA">' +
- ' <block type="lcd_set_position">' +
- ' <value name="POSX">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="POSY">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="CONTENT">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">假如我是一只鸟, 我也应该用嘶哑的喉咙歌唱: 这被暴风雨所打击着的土地, 这永远汹涌着我们的悲愤的河流, 这无止息地吹刮着的激怒的风, 和那来自林间的无比温柔的黎明…… ——然后我死了, 连羽毛也腐烂在土地里面。 为什么我的眼里常含泪水? 因为我对这土地爱得深沉……</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="dispalyStr">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">20</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="buttonUp">' +
- ' <shadow type="text">' +
- ' <field name="TEXT"></field>' +
- ' </shadow>' +
- ' <block type="ai_v831_button_read_pressed_canvas">' +
- ' <field name="button_type">C</field>' +
- ' </block>' +
- ' </value>' +
- ' <value name="buttonDown">' +
- ' <shadow type="text">' +
- ' <field name="TEXT"></field>' +
- ' </shadow>' +
- ' <block type="ai_v831_button_read_pressed_canvas">' +
- ' <field name="button_type">D</field>' +
- ' </block>' +
- ' </value>' +
- ' <value name="COLOR">' +
- ' <block type="lcd_set_color">' +
- ' </block>' +
- ' </value>' +
- ' <value name="Scale">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="LineNum">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">20</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- ' <block type="ai_lcd_linecarvas">' +
- ' <value name="POSA">' +
- ' <block type="lcd_set_position">' +
- ' <value name="POSX">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="POSY">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="POSB">' +
- ' <block type="lcd_set_position">' +
- ' <value name="POSX">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="POSY">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="COLOR">' +
- ' <block type="lcd_set_color">' +
- ' </block>' +
- ' </value>' +
- ' <value name="Scale">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' <block type="ai_lcd_draw_rectangle">' +
- ' <value name="POSA">' +
- ' <block type="lcd_set_position">' +
- ' <value name="POSX">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="POSY">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="POSB">' +
- ' <block type="lcd_set_width_height">' +
- ' <value name="WIDTH">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">320</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="HEIGHT">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">240</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="COLOR">' +
- ' <block type="lcd_set_color">' +
- ' </block>' +
- ' </value>' +
- ' <value name="Scale">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' <block type="ai_lcd_drawcirclecarvas">' +
- ' <value name="POSA">' +
- ' <block type="lcd_set_position">' +
- ' <value name="POSX">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="POSY">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="Scale">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">2</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="COLOR">' +
- ' <block type="lcd_set_color">' +
- ' </block>' +
- ' </value>' +
- ' <value name="Scale_0">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' <block type="ai_lcd_draw_image_on_canvas">' +
- ' <value name="image_path">' +
- ' <block type="v831_img_open">' +
- ' <value name="save_path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/preset/img/cocorobo_logo.jpg</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="alpha">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="scale_y">' +
- ' <block type="lcd_set_position">' +
- ' <value name="POSX">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="POSY">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' </block>' +
- '<block type="ai_lcd_rotation"></block>' +
- '<block type="ai_lcd_showcarvas_set_display">' +
- '</block>' +
- '<block type="ai_lcd_clearcanvas"></block>' +
- '</category>' +
- '<category id="catCamera" name="Camera" colour="#60c1bb">' +
- // '<block type="ai_camera_init"></block>' +
- '<block type="ai_camera_fit_to_screen_size"></block>' +
- // '<block type="ai_camera_windows">' +
- // '</block>' +
- '<block type="ai_camera_snapshot"></block>' +
- // '<block type="ai_model_class_start_load"></block>' +
- '<block type="v831_camera_graph_transmission">' +
- '</block>' +
- '<block type="v831_camera_internet_transmission">' +
- '</block>' +
- // '<block type="ai_camera_vflip"></block>' +
- // '<block type="ai_camera_hmirror"></block>' +
- // '<block type="ai_camera_auto_whitebal">' +
- // '</block>' +
- // '<block type="ai_camera_auto_gain"></block>' +
- // '<block type="ai_camera_auto_exposure"></block>' +
- '</category>' +
- '<category id="catMicrophone" name="Camera" colour="#5fcd8e">' +
- '<label id="catMicrophone" text="麦克风" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_mphone_record_init"></block>' +
- '<block type="ai_mphone_record_setting">' +
- ' <value name="path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/user/audio/record.wav</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="record_time">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">4</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- // '<block type="ai_mphone_Record_audio_start">' +
- // '</block>' +
- '</category>' +
- '<category id="catAISpeaker" name="Camera" colour="#603ea0">' +
- '<label id="catAISpeaker" text="扬声器" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_audio_play_init"></block>' +
- // '<block type="ai_audio_play_volume"></block>' +
- '<block type="ai_audio_play_song" inline="false">' +
- ' <value name="path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/preset/audio/luckystar.wav</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- // '<block type="ai_audio_play_start"></block>' +
- // '<block type="ai_audio_play_finish"></block>' +
- // '<block type="ai_audio_get_play_status"></block>' +
- '</category>' +
- '<category id="catSystem" name="系統" colour="#22398e">' +
- ' <block type="ai_system_off"></block>' +
- ' <block type="ai_system_restart"></block>' +
- ' <block type="ai_system_refresh"></block>' +
- ' <block type="ai_system_volume"></block>' +
- '<block type="ai_system_thread">' +
- '<field name="thread">1</field>' +
- '<value name="callBack">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- ' </shadow>' +
- ' <block type="procedures_callNothirdreturn">' +
- ' <mutation name="做点什么">' +
- ' <arg name="x"></arg>' +
- ' </mutation>' +
- ' <value name="ARG0">' +
- ' <block type="text">' +
- ' <field name="TEXT"></field>' +
- ' </block>' +
- ' </value>' +
- ' </block>' +
- '</value>' +
- '<value name="ADD0">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- ' </shadow>' +
- '</value>' +
- '</block>' +
- '<block type="ai_system_thread_set_setDaemon"></block>' +
- '<block type="ai_system_thread_set_join"></block>' +
- ' <block type="ai_system_thread_start"></block>' +
- ' <block type="ai_system_set_queue">' +
- ' <value name="queueVaritem">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">""</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- ' <block type="ai_system_get_queue"></block>' +
- '</category>' +
- '</category>',
- 'ExtendedFunctions':
- '<category id="ExtendedFunction" name="媒体处理" colour="#2fc67b">' +
- /*
- _ ___ ____
- / \ |_ _| / ___| ___ _ __ ___ ___ _ __
- / _ \ | | \___ \ / __| '__/ _ \/ _ \ '_ \
- / ___ \ _ | | _ ___) | (__| | | __/ __/ | | |
- /_/ \_(_)___(_) |____/ \___|_| \___|\___|_| |_|
-
- */
- '<category id="catVision" name="Vision" colour="#f2a247">' +
- '<label id="basis_function" text="Basis function" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="v831_img_save">' +
- ' <value name="save_path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">saved</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="v831_img_text"><field name="TEXT">/root/user/img/</field></block>' +
- '<block type="v831_img_open">' +
- ' <value name="save_path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/user/img/saved.jpg</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="v831_lcd_invert"></block>' +
- '<block type="v831_lcd_rotating">' +
- ' <value name="spend">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">50</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- // '<block type="ai_lcd_invert_color"></block>' +
- '<block type="v831_lcd_resizecanvas">' +
- ' <value name="wh">' +
- ' <block type="ai_lcd_WH_vision">' +
- ' <value name="A">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- '</block>' +
- // '<block type="ai_lcd_color_scheme"></block>' +
- // '<block type="ai_lcd_ai_pix"></block>' +
- '<block type="v831_lcd_img_cut">' +
- ' <value name="xy">' +
- ' <block type="ai_lcd_XY_vision">' +
- ' <value name="A">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="wh">' +
- ' <block type="ai_lcd_WH_vision">' +
- ' <value name="A">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- '</block>' +
- '<label id="advanced_function" text="进阶功能" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="ai_vision_get_threshold_default"></block>' +
- '<block type="ai_lane_tracking_run">' +
- ' <value name="rgb_value">' +
- ' <block type="ai_lcd_rgb_value_input">' +
- ' <value name="rgb_value_r">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="rgb_value_g">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="rgb_value_b">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- '</block>' +
- // '<block type="ai_vision_find_rects">' +
- // ' <value name="xy">' +
- // ' <block type="ai_lcd_XY_vision">' +
- // ' <value name="A">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">0</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' <value name="B">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">0</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' </block>' +
- // ' </value>' +
- // ' <value name="wh">' +
- // ' <block type="ai_lcd_WH_vision">' +
- // ' <value name="A">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">0</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' <value name="B">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">0</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' </block>' +
- // ' </value>' +
- // '</block>' +
- '<block type="ai_vision_find_lines">' +
- ' <value name="color">' +
- ' <block type="ai_vision_get_threshold_default">' +
- ' </block>' +
- ' </value>' +
- ' <value name="xy">' +
- ' <block type="ai_lcd_XY_vision">' +
- ' <value name="A">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="wh">' +
- ' <block type="ai_lcd_WH_vision">' +
- ' <value name="A">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="area_threshold">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">10</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="pixels_threshold">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">10</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="margin">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">10</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_vision_get_blobs"></block>' +
- '<block type="ai_vision_find_blobs">' +
- ' <value name="color">' +
- ' <block type="ai_vision_get_threshold_default">' +
- ' </block>' +
- ' </value>' +
- ' <value name="xy">' +
- ' <block type="ai_lcd_XY_vision">' +
- ' <value name="A">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="wh">' +
- ' <block type="ai_lcd_WH_vision">' +
- ' <value name="A">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="area_threshold">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">10</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="pixels_threshold">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">10</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="margin">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">10</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_vision_find_blobs_result"></block>' +
- '<block type="ai_lane_tracking_setup">' +
- ' <value name="color">' +
- ' <block type="ai_vision_get_threshold_default">' +
- ' </block>' +
- ' </value>' +
- ' <value name="lsize">' +
- '<block type="ai_canvas_area_tuple">' +
- ' <value name="xy">' +
- ' <block type="ai_lcd_XY_vision">' +
- ' <value name="A">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">140</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="wh">' +
- ' <block type="ai_lcd_WH_vision">' +
- ' <value name="A">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">100</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">240</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- '</block>' +
- ' </value>' +
- ' <value name="rsize">' +
- '<block type="ai_canvas_area_tuple">' +
- ' <value name="xy">' +
- ' <block type="ai_lcd_XY_vision">' +
- ' <value name="A">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">220</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">140</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="wh">' +
- ' <block type="ai_lcd_WH_vision">' +
- ' <value name="A">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">320</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">240</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- '</block>' +
- ' </value>' +
- ' <value name="axis">' +
- ' <block type="math_number"><field name="NUM">112</field></block>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_vision_color_analyze">' +
- ' <value name="xy">' +
- ' <block type="ai_lcd_XY_vision">' +
- ' <value name="A">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- ' <value name="wh">' +
- ' <block type="ai_lcd_WH_vision">' +
- ' <value name="A">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- '</block>' +
- '<label id="graphics_decoding" text="Graphics decoding" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="ai_vision_find_qrcode"></block>' +
- '<block type="ai_vision_find_qrcode_result"></block>' +
- '<block type="ai_vision_qrcode_get_info"></block>' +
- '<block type="ai_vision_find_apriltag"></block>' +
- '<block type="ai_vision_apriltag_get_info"></block>' +
- '<block type="ai_vision_find_datamatrices"></block>' +
- // '<block type="ai_vision_datamatrices_get_info"></block>' +
- '<block type="ai_vision_find_barcodes"></block>' +
- '<block type="ai_vision_barcodes_get_info"></block>' +
- '<block type="ai_vision_barcodes_get_info_result"></block>' +
- '</category>' +
- /*
- _ ___ __ ___ _
- / \ |_ _| \ \ / (_) __| | ___ ___
- / _ \ | | \ \ / /| |/ _` |/ _ \/ _ \
- / ___ \ | | \ V / | | (_| | __/ (_) |
- /_/ \_\___| \_/ |_|\__,_|\___|\___/
- */
- '<category id="catIV" name="Video" colour="#4d9994">' +
- '<block type="ai_video_set_init"></block>' +
- '<block type="ai_video_set">' +
- ' <value name="path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/user/video/record.mp4</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_video_set_play"></block>' +
- '<block type="ai_video_set_stats"></block>' +
- '<block type="ai_video_stop_play"></block>' +
- '<block type="ai_video_record_init">' +
- ' <value name="save_path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/user/video/record.mp4</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="w">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">320</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="h">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">240</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_video_record_get"></block>' +
- '<block type="ai_video_record_stop"></block>' +
- '</category>' +
- '</category>',
- 'AI':
- '<category id="AI" name="人工智能" colour="#ee783a">' +
- '<category id="catModels" name="Models" colour="#ee783a">' +//模型
- '<label id="edge_detection" text="边缘检测" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_model_edge_init"></block>' +
- '<block type="ai_model_edge_loading"></block>' +
- '<block type="ai_model_edge_result"></block>' +
- '<label id="basis_number_recognition" text="Basis number recognition" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_model_digital_init"></block>' +
- '<block type="ai_model_digital_init_loding"></block>' +
- // '<block type="ai_model_digital_attribute"></block>' +
- '<block type="ai_model_digital"></block>' +
- '<block type="ai_model_digital_new"></block>' +
- '<block type="ai_model_digital_result"></block>' +
- '<label id="basis_object_recognition" text="Basis object recognition" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_model_object_init">' +
- // '</block>' +
- '<block type="ai_model_object_load"></block>' +
- '<block type="ai_model_look_attribute"></block>' +
- // '<block type="ai_model_look"></block>' +
- '<block type="ai_model_look_new"></block>' +
- '<block type="ai_model_get"></block>' +
- '<label id="Guesswork_recognition" text="猜拳识别" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_model_Guesswork_init">' +
- // '</block>' +
- '<block type="ai_model_Guesswork_load"></block>' +
- '<block type="ai_model_Guesswork_look"></block>' +
- '<block type="ai_model_Guesswork_look_new"></block>' +
- '<block type="ai_model_Guesswork_get"></block>' +
- // '<block type="ai_model_Guesswork_look_attribute"></block>' +
- '<label id="basis_face_recognition" text="Basis face recognition" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_model_face_recognition_init"></block>' +
- '<block type="ai_model_face_recognition_load"></block>' +
- '<block type="ai_model_face"></block>' +
- '<block type="ai_model_face_new"></block>' +
- '<block type="ai_model_xy"></block>' +
- // '<block type="ai_model_face_attribute"></block>' +
- // 车牌识别
- '<label id="basis_card_recognition" text="车牌识别" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_model_card_recognition_init"></block>' +
- '<block type="ai_model_card_recognition_load"></block>' +
- '<block type="ai_model_card_xy"></block>' +
- '<block type="ai_model_card_xy_new"></block>' +
- '<block type="ai_model_card_get"></block>' +
- // '<block type="ai_model_card_result"></block>' +
- '<label id="basis_face_recognition_1" text="人脸识别" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="face_recognition_load">' +
- ' <value name="class_input">' +
- ' <block type="lists_create_with">' +
- ' <value name="ADD0">' +
- ' <block type="text"><field name="TEXT">Name1</field></block>' +
- ' </value>' +
- ' <value name="ADD1">' +
- ' <block type="text"><field name="TEXT">Name2</field></block>' +
- ' </value>' +
- ' <value name="ADD2">' +
- ' <block type="text"><field name="TEXT">Name3</field></block>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- '</block>' +
- '<block type="face_recognition_if_face"></block>' +
- '<block type="face_recognition_if_face_new"></block>' +
- '<block type="face_recognition_detection_rectangle"></block>' +
- // '<block type="face_recognition_map_face"></block>' +
- // '<block type="face_recognition_face_result"></block>' +
- '<block type="face_recognition_add"></block>' +
- '<block type="face_recognition_remove"></block>' +
- '<block type="face_recognition_data_load">' +
- ' <value name="class_input">' +
- ' <block type="text"><field name="TEXT">/root/user/model/recorded_face_features.py</field></block>' +
- ' </value>' +
- '</block>' +
- // '<block type="face_recognition_data_results"></block>' +
- // '<block type="ai_model_self_learning_result"></block>' +
- '<label id="self_learning" text="自我学习" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_model_self_learning_init">' +
- // ' <value name="class_input">' +
- // ' <block type="lists_create_with">' +
- // ' <value name="ADD0">' +
- // ' <block type="text"><field name="TEXT">Object 1 Name</field></block>' +
- // ' </value>' +
- // ' <value name="ADD1">' +
- // ' <block type="text"><field name="TEXT">Object 2 Name</field></block>' +
- // ' </value>' +
- // ' <value name="ADD2">' +
- // ' <block type="text"><field name="TEXT">Object 3 Name</field></block>' +
- // ' </value>' +
- // ' </block>' +
- // ' </value>' +
- // '</block>' +
- '<block type="ai_model_self_learning_load">' +
- ' <value name="class_input">' +
- ' <block type="lists_create_with">' +
- ' <value name="ADD0">' +
- ' <block type="text"><field name="TEXT">Object 1 Name</field></block>' +
- ' </value>' +
- ' <value name="ADD1">' +
- ' <block type="text"><field name="TEXT">Object 2 Name</field></block>' +
- ' </value>' +
- ' <value name="ADD2">' +
- ' <block type="text"><field name="TEXT">Object 3 Name</field></block>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_model_self_learning_recognize_load">' +
- ' <value name="class_input">' +
- ' <block type="lists_create_with">' +
- ' <value name="ADD0">' +
- ' <block type="text"><field name="TEXT">Object 1 Name</field></block>' +
- ' </value>' +
- ' <value name="ADD1">' +
- ' <block type="text"><field name="TEXT">Object 2 Name</field></block>' +
- ' </value>' +
- ' <value name="ADD2">' +
- ' <block type="text"><field name="TEXT">Object 3 Name</field></block>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_model_self_learning_add_class"></block>' +
- // '<block type="ai_model_self_learning_make_data_set"></block>' +
- '<block type="ai_model_self_learning_picture"></block>' +
- // '<block type="ai_model_self_learning_save_modal"></block>' +
- '<block type="ai_model_self_learning_class_verification"></block>' +
- '<block type="ai_model_self_learning_result"></block>' +
- // '<block type="ai_model_card_attribute_new"></block>' +
- '<label id="basis_model_recognition" text="Basis model recognition" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_model_customized_init_setup_definition"></block>' +
- // '<block type="ai_model_customized_init_setup">' +
- // ' <value name="class_input">' +
- // ' <block type="lists_create_with">' +
- // ' <value name="ADD0">' +
- // ' <block type="text"><field name="TEXT">Object 1 Name</field></block>' +
- // ' </value>' +
- // ' <value name="ADD1">' +
- // ' <block type="text"><field name="TEXT">Object 2 Name</field></block>' +
- // ' </value>' +
- // ' <value name="ADD2">' +
- // ' <block type="text"><field name="TEXT">Object 3 Name</field></block>' +
- // ' </value>' +
- // ' </block>' +
- // ' </value>' +
- // '</block>' +
- '<block type="ai_model_customized_load_setup">' +
- ' <value name="class_input">' +
- ' <block type="lists_create_with">' +
- ' <value name="ADD0">' +
- ' <block type="text"><field name="TEXT">Object 1 Name</field></block>' +
- ' </value>' +
- ' <value name="ADD1">' +
- ' <block type="text"><field name="TEXT">Object 2 Name</field></block>' +
- ' </value>' +
- ' <value name="ADD2">' +
- ' <block type="text"><field name="TEXT">Object 3 Name</field></block>' +
- ' </value>' +
- ' </block>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_model_customized_if_got"></block>' +
- '<block type="ai_model_customized_if_got_new"></block>' +
- // '<block type="ai_model_customized_if_got"></block>' +
- '<block type="ai_model_customized_get_result">' +
- '</block>' +
- // '<label id="basis_speech_recognition" text="Speech Recording Recognition" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="speech_recognition_new_setup"></block>' +
- // '<block type="speech_recognition_record_start_result"></block>' +
- // '<block type="speech_recognition_new_start_recognition"></block>' +
- // '<block type="speech_recognition_new_recognition_get_any_result"></block>' +
- // '<block type="speech_recognition_new_recognition_get_result"></block>' +
- // yuyin zhuan pinyin blocks
- '<label id="basis_speech_pinyin_recognition" text="Speech Phonetic Recognition" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="speech_recognition_phonetic_to_pinyin_setup"></block>' +
- '<block type="speech_recognition_phonetic_to_pinyin_set_param">' +
- ' <mutation items="3"></mutation>' +
- ' <value name="PINYIN0">'+
- ' <shadow type="math_number">'+
- ' <field name="NUM">0</field>'+
- ' </shadow>'+
- ' <block type="set_pinyin_dict_create_with_items_insert">'+
- ' <mutation items="2"></mutation>'+
- ' <field name="KEY0">ni</field>'+
- ' <field name="toneADD00">1</field>'+
- ' <field name="KEY1">hao</field>'+
- ' <field name="toneADD11">3</field>'+
- ' </block>'+
- ' </value>'+
- ' <value name="PINYIN1">'+
- ' <block type="set_pinyin_dict_create_with_items_insert">'+
- ' <mutation items="2"></mutation>'+
- ' <field name="KEY0">hao</field>'+
- ' <field name="toneADD00">3</field>'+
- ' <field name="KEY1">de</field>'+
- ' <field name="toneADD11">1</field>'+
- ' </block>'+
- ' </value>'+
- ' <value name="PINYIN2">'+
- ' <block type="set_pinyin_dict_create_with_items_insert">'+
- ' <mutation items="3"></mutation>'+
- ' <field name="KEY0">wan</field>'+
- ' <field name="toneADD00">1</field>'+
- ' <field name="KEY1">shang</field>'+
- ' <field name="toneADD11">4</field>'+
- ' <field name="KEY2">hao</field>'+
- ' <field name="toneADD22">3</field>'+
- ' </block>'+
- ' </value>' +
- '</block>' +
- '<block type="speech_recognition_set_pinyin_tone"></block>' +
- '<block type="speech_recognition_phonetic_to_pinyin_start_recognition"></block>' +
- '<block type="speech_recognition_phonetic_to_pinyin_stop_recognition"></block>' +
- '<block type="speech_recognition_phonetic_to_pinyin_pause_recognition"></block>' +
- '<block type="speech_recognition_phonetic_to_pinyin_get_result"></block>' +
- '<label id="" text="Numpy 神经网络" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="Numpy_Neural_Network_init">' +
- '</block>' +
- '<block type="Numpy_Neural_Network_load">' +
- '</block>' +
- '<block type="Numpy_Neural_Network_LOading_test_train">' +
- ' <value name="class_input">' +
- ' <block type="text"><field name="TEXT">/root/preset/training/res/mnist_train_100.csv</field></block>' +
- ' </value>' +
- ' <value name="class_input1">' +
- ' <block type="text"><field name="TEXT">/root/preset/training/res/mnist_test_10.csv</field></block>' +
- ' </value>' +
- '</block>' +
- '<block type="Numpy_Neural_Network_numpy_isStart">' +
- '</block>' +
- '<block type="Numpy_Neural_Network_setting_training_argument">' +
- ' <value name="class_input">' +
- ' <block type="text"><field name="TEXT">784</field></block>' +
- ' </value>' +
- ' <value name="class_input1">' +
- ' <block type="text"><field name="TEXT">128</field></block>' +
- ' </value>' +
- ' <value name="class_input2">' +
- ' <block type="text"><field name="TEXT">10</field></block>' +
- ' </value>' +
- ' <value name="class_input3">' +
- ' <block type="text"><field name="TEXT">0.1</field></block>' +
- ' </value>' +
- ' <value name="class_input4">' +
- ' <block type="text"><field name="TEXT">10</field></block>' +
- ' </value>' +
- ' <value name="class_input5">' +
- ' <block type="text"><field name="TEXT">/root/user/model/NN.pkl</field></block>' +
- ' </value>' +
- '</block>' +
- '<block type="Numpy_Neural_Network_numpy_loading_model">' +
- ' <value name="class_input">' +
- ' <block type="text"><field name="TEXT">/root/user/model/NN.pkl</field></block>' +
- ' </value>' +
- '</block>' +
- '<block type="Numpy_Neural_Network_numpy_loading_model_fun">' +
- '</block>' +
- '<block type="Numpy_Neural_Network_numpy_loading_model_result">' +
- '</block>' +
- '<block type="Numpy_Neural_Network_numpy_clear">' +
- '</block>' +
- '</category>' +
- // 讯飞在线识别
- '<category id="OnlineIdentify" name="Motor" colour="#0000FF">' +
- '<label id="online_face_recognition" text="在线人脸识别" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_online_ident_init">' +
- // ' <value name="A">' +
- // ' <shadow type="text">' +
- // ' <field name="TEXT">2a588b52</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' <value name="B">' +
- // ' <shadow type="text">' +
- // ' <field name="TEXT">MzQyZDE3MmQ1ZThhNjBiODI3ZDEzY2Nk</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' <value name="C">' +
- // ' <shadow type="text">' +
- // ' <field name="TEXT">a61f7532ed97cb4506752047c9221f6c</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // '</block>' +
- '<block type="ai_online_ident_loading">' +
- ' <value name="A">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">2a588b52</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">MzQyZDE3MmQ1ZThhNjBiODI3ZDEzY2Nk</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="C">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">a61f7532ed97cb4506752047c9221f6c</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/preset/img/cocorobo_logo.jpg</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_online_ident_result"></block>' +
- '<block type="ai_online_ident_result_people"></block>' +
- '<label id="online_text_to_voice" text="在线文本转语音" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_audio_init">' +
- // ' <value name="A">' +
- // ' <shadow type="text">' +
- // ' <field name="TEXT">2a588b52</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' <value name="B">' +
- // ' <shadow type="text">' +
- // ' <field name="TEXT">MzQyZDE3MmQ1ZThhNjBiODI3ZDEzY2Nk</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' <value name="C">' +
- // ' <shadow type="text">' +
- // ' <field name="TEXT">a61f7532ed97cb4506752047c9221f6c</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // '</block>' +
- '<block type="ai_audio_play_state">' +
- ' <value name="A">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">2a588b52</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">MzQyZDE3MmQ1ZThhNjBiODI3ZDEzY2Nk</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="C">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">a61f7532ed97cb4506752047c9221f6c</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="NAME">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">hello world</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/demo.pcm</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<label id="online_speech_recognition" text="在线语音识别" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_online_voice_init">' +
- // '</block>' +
- '<block type="ai_online_voice_loading">' +
- ' <value name="A">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">2a588b52</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">MzQyZDE3MmQ1ZThhNjBiODI3ZDEzY2Nk</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="C">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">a61f7532ed97cb4506752047c9221f6c</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/user/audio/record.wav</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_online_voice_result"></block>' +
- '<label id="machine_translation" text="机器翻译" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_online_machine_translation_init">' +
- // '</block>' +
- '<block type="ai_online_machine_translation_loading">' +
- ' <value name="A">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">8810558b</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">ZTIzYjM5NmIzMmRiZWNiMzk4MzkzZjk2</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="C">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">14975be8b286996b1f9002e81e0a4f3c</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="NAME">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">hello world</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_online_machine_translation_result"></block>' +
- '<label id="handwritten_text" text="手写文字识别" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_online_handwritten_text_init">' +
- // ' <value name="A">' +
- // ' <shadow type="text">' +
- // ' <field name="TEXT">2a588b52</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' <value name="C">' +
- // ' <shadow type="text">' +
- // ' <field name="TEXT">a92e45658833435660a5b4eb16495bbf</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // '</block>' +
- '<block type="ai_online_handwritten_text_loading">' +
- ' <value name="A">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">2a588b52</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="C">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">a92e45658833435660a5b4eb16495bbf</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/preset/img/cocorobo_logo.jpg</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_online_handwritten_text_result"></block>' +
- '<label id="formula" text="公式识别" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_online_formula_init">' +
- // '</block>' +
- '<block type="ai_online_formula_loading">' +
- ' <value name="A">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">2a588b52</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="B">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">MzQyZDE3MmQ1ZThhNjBiODI3ZDEzY2Nk</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="C">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">a61f7532ed97cb4506752047c9221f6c</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/preset/img/cocorobo_logo.jpg</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_online_formula_result"></block>' +
- '<label id="AI_emotion" text="情绪识别" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_online_emotion_init">' +
- // '</block>' +
- '<block type="ai_online_emotion_loading">' +
- ' <value name="path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/preset/img/cocorobo_logo.jpg</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_online_emotion_result"></block>' +
- '<label id="gesturesTitle" text="手势识别" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="ai_online_gesture_init">' +
- // '</block>' +
- '<block type="ai_online_gesture_loading">' +
- ' <value name="path">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/preset/img/cocorobo_logo.jpg</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="ai_online_gesture_result"></block>' +
- '</category>' +
- '<category id="" name="AIGC" colour="#7e3cca">' +
- // '<block type="cocopi_chatGpt_init">' +
- // '</block>' +
- // '<block type="cocopi_chatGpt_result"></block>' +
- '<label id="text_to_img" text="文字转图片" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="cocopi_chatGpt_text_to_img_loading">' +
- ' <value name="NAME">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">Smile</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- // '<block type="cocopi_chatGpt_text_to_img_result"></block>' +
- '<label id="img_to_text" text="图片转文字" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="cocopi_chatGpt_image_to_text_loading">' +
- ' <value name="NAME">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/preset/img/face/face21.jpg</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="NAME1">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">图片什么内容</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<label id="text_to_voice" text="文字转语音" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="cocopi_chatGpt_text_to_voice_loading">' +
- ' <value name="NAME">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">hello world</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<label id="voice_to_text" text="语音转文字" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="cocopi_chatGpt_voice_to_text_loading">' +
- ' <value name="NAME">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">/root/user/audio/record.wav</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- // '<block type="cocopi_chatGpt_voice_to_text_result"></block>' +
- '<label id="gpt_answer" text="文字对话" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="cocopi_chatGpt_post_chatgpt_loading">' +
- ' <value name="NAME">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">who are you</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<label id="ai_agent_chat" text="AI 智能体" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="cocopi_chatGpt_AI_loading">' +
- ' <value name="NAME">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">ENTER_YOUR_EVENT_API_KEY</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="NAME1">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">Problem</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="cocopi_chatGpt_AI_loading_more">' +
- ' <value name="NAME">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">ENTER_YOUR_EVENT_API_KEY</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="NAME1">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">Problem</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- // '<block type="cocopi_chatGpt_post_chatgpt_result"></block>' +
- '</category>' +
- '</category>',
- 'IOT':
- '<category id="IOT" name="IOT" colour="#7e3cca">' +
- '<category id="" name="Wi-Fi" colour="#3062c1">' +
- '<block type="V831_code_scanning_network"></block>' +
- '<block type="esp32_main_controller_wifi_connect_internet">' +
- ' <value name="ssid">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">ENTER_YOUR_SSID</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="password">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">ENTER_YOUR_PASSWORD</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="esp32_main_controller_get_wifi_connection_status"></block>' +
- '<block type="esp32_main_controller_wifi_get_info"></block>' +
- '<block type="esp32_main_controller_wifi_disconnect"></block>' +
- '<block type="esp32_main_controller_wifi_ntptime"></block>' +
- '</category>' +
- '<category id="" name="Web" colour="#3062c1">' +
- '<label id="Get_weather" text="获取天气信息" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="v831_get_weather_init"></block>' +
- '<block type="v831_set_city_and_time"></block>' +
- '<block type="v831_set_city_and_time_new"></block>' +
- '<block type="v831_get_weather_result"></block>' +
- '<label id="basis_ifttt" text="ifttt" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="esp32_main_controller_ifttt_send_data">' +
- ' <value name="ifttt_data_1">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="ifttt_data_2">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="ifttt_data_3">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="esp32_main_controller_ifttt_touched"></block>' +
- '<label id="basis_service_thingspeak" text="Basis service thingspeak" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="iot_service_thingspeak">' +
- ' <value name="ADD0">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="iot_service_thingspeak_read"></block>' +
- '<block type="iot_service_thingspeak_read_total"></block>' +
- '<block type="iot_service_thingspeak_read_specific">' +
- ' <value name="entry">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="field">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<label id="basis_http" text="Basis http" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="esp32_network_http_get">' +
- ' <value name="http_get_url">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">HTTP://ENTER_AN_URL</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="esp32_network_http_post">' +
- ' <value name="http_post_url">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">HTTP://ENTER_AN_URL</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="data">' +
- ' <block type="dict_create_with_items_insert"></block>' +
- ' </value>' +
- '</block>' +
- '<block type="CocoRobo_get"></block>' +
- '<block type="esp32_network_http_get_data_from_local_server"></block>' +
- '</category>' +
- '<category id="catCloudData" name="云端" colour="#3062c1">' +
- '<label id="basis_service_cococloud" text="Basis service cococloud" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- // '<block type="iot_service_cococloud">' +
- // ' <value name="ADD0">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">0</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // '</block>' +
- '<block type="v831_service_cococloud">' +
- ' <value name="KEY0">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">Property</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="ADD0">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">value</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="iot_service_cococloud_read"></block>' +
- '<block type="iot_service_cococloud_read_data">' +
- ' <value name="property">' +
- ' <shadow type="text">' +
- ' <field name="TEXT">property</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '</category>' +
- '</category>',
- 'ExtendedFunction':
- '<category id="extension_module" name="extension_module" colour="#3163ed">' +
- '<category id="LEDstrip" name="LED strip" colour="#e8795b">' +
- // '<block type="esp32_main_controller_led_strip_setup">' +
- // ' <value name="io">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">1</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // ' <value name="count">' +
- // ' <shadow type="math_number">' +
- // ' <field name="NUM">16</field>' +
- // ' </shadow>' +
- // ' </value>' +
- // '</block>' +
- '<block type="esp32_main_controller_led_strip_set">' +
- ' <value name="location">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="color">' +
- ' <block type="iot_led_matrix_color_picker"></block>' +
- ' </value>' +
- ' <value name="brightness">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">50</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="esp32_main_controller_led_strip_set_one">' +
- ' <value name="location">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">1</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="location1">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">5</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="color">' +
- ' <block type="iot_led_matrix_color_picker"></block>' +
- ' </value>' +
- ' <value name="brightness">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">50</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="esp32_main_controller_led_strip_set_all">' +
- ' <value name="color">' +
- ' <block type="iot_led_matrix_color_picker"></block>' +
- ' </value>' +
- ' <value name="brightness">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">50</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="esp32_main_controller_led_strip_set_all_off"></block>' +
- '<block type="iot_led_matrix_color_picker"></block>' +
- '<block type="led_strip_color_rgb">' +
- ' <value name="rgb_value_r">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="rgb_value_g">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- ' <value name="rgb_value_b">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">0</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '</category>' +
- '<category id="" name="第三方传感器" colour="#d42b03">' +
- '<label id="basis_buzzer" text="蜂鸣器" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="esp32_main_controller_set_buzzer_init"></block>' +
- '<block type="esp32_main_controller_set_buzzer">' +
- ' <value name="esp32_var_num">' +
- ' <shadow type="math_number">' +
- ' <field name="NUM">31</field>' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<block type="esp32_main_controller_turn_off_buzzer"></block>' +
- '<block type="esp32_main_controller_turn_off_buzzer_music">' +
- ' <value name="beat">' +
- ' <shadow type="esp32_main_controller_buzzer_set_beat_lite">' +
- ' </shadow>' +
- ' </value>' +
- '</block>' +
- '<label id="" text="室温/水温" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="v831_room_water_temperature"></block>' +
- '<label id="" text="实时时钟" web-class="myLabelStyle" style="font-size:20px;"></label>' +
- '<block type="v831_set_real_time_clock"></block>' +
- '<block type="v831_real_time_clock"></block>' +
- '</category>' +
- '</category>',
- };
- /**
- * Creates an updated representation of the Toolboxes XML as currently specified in the
- * model, using whatever modules have been added or removed. This method can either set it
- * or just retrieve it for future use.
- *
- * @param {Boolean} only_set - Whether to return the XML string or to actually set the XML. False means that it will not update the toolbox!
- * @returns {String?} Possibly returns the XML of the toolbox as a string.
- */
- BlockPyEditor.prototype.updateToolbox = function (only_set) {
- // let blocklyXml = Blockly.Xml.textToDom(BlockPyEditor.CATEGORY_MAP)
- // var categoryNodes = blocklyXml.getElementsByTagName('category');
- // for (var i = 0, cat; cat = categoryNodes[i]; i++) {
- // var catId = cat.getAttribute('id');
- // var catText = Ardublockly.getLocalStr(catId);
- // if (catText) {
- // cat.setAttribute('name', catText);
- // }
- // }
- var xml = '<xml id="toolbox" style="display: none">';
- var modules = this.main.model.assignment.modules();
- var started_misc = false,
- started_values = false,
- started_data = false;
- for (var i = 0, length = modules.length; i < length; i = i + 1) {
- var module = modules[i];
- if (!started_misc && ['Calculation', 'Output', 'Python'].indexOf(module) != -1) {
- started_misc = true;
- // xml += BlockPyEditor.CATEGORY_MAP['Separator'];
- }
- if (!started_values && ['Values', 'Lists', 'Dictionaries'].indexOf(module) != -1) {
- started_values = true;
- // xml += BlockPyEditor.CATEGORY_MAP['Separator'];
- }
- if (!started_data && module.slice(0, 6) == 'Data -') {
- started_data = true;
- // xml += BlockPyEditor.CATEGORY_MAP['Separator'];
- }
- if (typeof module == 'string') {
- xml += BlockPyEditor.CATEGORY_MAP[module];
- } else {
- var category = '<category name="' + module.name + '" colour="' + module.color + '">';
- for (var j = 0; category_length = module.blocks.length; j = j + 1) {
- var block = module.blocks[j];
- category += '<block type="' + block + '"></block>';
- }
- category += '</category>';
- }
- //'<sep></sep>'+
- }
- xml += '</xml>';
- Ardublockly.initLanguage();
- Ardublockly.updateToolboxLanguage(xml);
- xml = Ardublockly.xmlTree;
- if (only_set && !this.main.model.settings.read_only()) {
- this.blockly.updateToolbox(xml);
- this.blockly.resize();
- } else {
- return xml;
- }
- };
- BlockPyEditor.prototype.DOCTYPE = '<?xml version="1.0" standalone="no"?>' + '<' + '!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">';
- BlockPyEditor.prototype.cssData = null;
- BlockPyEditor.prototype.loadCss = function () {
- if (this.cssData == null) {
- var txt = '.blocklyDraggable {}\n';
- txt += Blockly.Css.CONTENT.join('\n');
- if (Blockly.FieldDate) {
- txt += Blockly.FieldDate.CSS.join('\n');
- }
- // Strip off any trailing slash (either Unix or Windows).
- this.cssData = txt.replace(/<<<PATH>>>/g, Blockly.Css.mediaPath_);
- }
- }
- /**
- * Generates a PNG version of the current workspace. This PNG is stored in a Base-64 encoded
- * string as part of a data URL (e.g., "data:image/png;base64,...").
- * TODO: There seems to be some problems capturing blocks that don't start with
- * statement level blocks (e.g., expression blocks).
- *
- * @param {Function} callback - A function to be called with the results. This function should take two parameters, the URL (as a string) of the generated base64-encoded PNG and the IMG tag.
- */
- BlockPyEditor.prototype.getPngFromBlocks = function (callback) {
- this.loadCss();
- try {
- // Retreive the entire canvas, strip some unnecessary tags
- var blocks = this.blockly.svgBlockCanvas_.cloneNode(true);
- blocks.removeAttribute("width");
- blocks.removeAttribute("height");
- // Ensure that we have some content
- if (blocks.childNodes[0] !== undefined) {
- // Remove tags that offset
- blocks.removeAttribute("transform");
- blocks.childNodes[0].removeAttribute("transform");
- blocks.childNodes[0].childNodes[0].removeAttribute("transform");
- // Add in styles
- var linkElm = document.createElementNS("http://www.w3.org/1999/xhtml", "style");
- linkElm.textContent = this.cssData + '\n\n';
- blocks.insertBefore(linkElm, blocks.firstChild);
- // Get the bounding box
- var bbox = document.getElementsByClassName("blocklyBlockCanvas")[0].getBBox();
- // Create the XML representation of the SVG
- var xml = new XMLSerializer().serializeToString(blocks);
- xml = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' + bbox.width + '" height="' + bbox.height + '" viewBox="0 0 ' + bbox.width + ' ' + bbox.height + '"><rect width="100%" height="100%" fill="white"></rect>' + xml + '</svg>';
- // create a file blob of our SVG.
- // Unfortunately, this crashes modern chrome for unknown reasons.
- //var blob = new Blob([ this.DOCTYPE + xml], { type: 'image/svg+xml' });
- //var url = window.URL.createObjectURL(blob);
- // Old method: this failed on IE
- var url = "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(xml)));
- // Create an IMG tag to hold the new element
- var img = document.createElement("img");
- img.style.display = 'block';
- img.onload = function () {
- var canvas = document.createElement('canvas');
- canvas.width = bbox.width;
- canvas.height = bbox.height;
- var ctx = canvas.getContext('2d');
- ctx.drawImage(img, 0, 0);
- var canvasUrl;
- try {
- canvasUrl = canvas.toDataURL("image/png");
- } catch (e) {
- canvasUrl = url;
- }
- img.onload = null;
- callback(canvasUrl, img);
- }
- img.onerror = function () {
- callback("", img);
- }
- img.setAttribute('src', url);
- } else {
- callback("", document.createElement("img"))
- }
- } catch (e) {
- callback("", document.createElement("img"));
- console.error("PNG image creation not supported!", e);
- }
- }
- /**
- * Shows a dialog window with the current block workspace encoded as a
- * downloadable PNG image.
- */
- BlockPyEditor.prototype.copyImage = function () {
- var dialog = this.main.components.dialog;
- this.getPngFromBlocks(function (canvasUrl, img) {
- img.onload = function () {
- var p = document.createElement('p');
- p.textContent = "Right click the image below and choose to copy or save it."
- var div = document.createElement('div');
- div.appendChild(p);
- div.appendChild(img);
- dialog.show("Save Blocks As Image", div);
- };
- img.src = canvasUrl;
- });
- }
|