A monorepo containing jupyter-blocks and jupyter-tidyblocks. Blockly extension for JupyterLab.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #24 from hbcarlos/niryo

Adds a dropdown to select a toolbox

authored by

Carlos Herrero and committed by
GitHub
24b2db39 a6b5f4fa

+2054 -11
+16 -1
src/index.ts
··· 208 208 } 209 209 }; 210 210 211 - export default plugin; 211 + import BlocklyNiryo from './niryo/niryo_one_python_generators'; 212 + 213 + /** 214 + * Initialization data for the jupyterlab-blocky extension. 215 + */ 216 + const niryo: JupyterFrontEndPlugin<void> = { 217 + id: 'jupyterlab-blocky:niryo', 218 + autoStart: true, 219 + requires: [IBlocklyRegisty], 220 + activate: (app: JupyterFrontEnd, blockly: IBlocklyRegisty): void => { 221 + console.log('JupyterLab extension jupyterlab-blocky-niryo is activated!'); 222 + blockly.registerToolbox('niryo', BlocklyNiryo.Toolbox); 223 + } 224 + }; 225 + 226 + export default [plugin, niryo];
+3
src/layout.ts
··· 186 186 this._cell.model.sharedModel.setSource(code); 187 187 this._cell.model.mimeType = this._manager.mimeType; 188 188 } 189 + if (change === 'toolbox') { 190 + this._workspace.updateToolbox(this._manager.toolbox as any); 191 + } 189 192 } 190 193 }
+31 -5
src/manager.ts
··· 16 16 * user wants to use on a specific document. 17 17 */ 18 18 export class BlocklyManager { 19 - private _toolbox: JSONObject; 19 + private _toolbox: string; 20 20 private _generator: Blockly.Generator; 21 21 private _registry: BlocklyRegistry; 22 22 private _selectedKernel: KernelSpec.ISpecModel; ··· 36 36 this._sessionContext = sessionContext; 37 37 this._mimetypeService = mimetypeService; 38 38 39 - this._toolbox = this._registry.toolboxes.get('default'); 39 + this._toolbox = 'default'; 40 40 this._generator = this._registry.generators.get('python'); 41 41 42 42 this._changed = new Signal<this, BlocklyManager.Change>(this); ··· 47 47 * Returns the selected toolbox. 48 48 */ 49 49 get toolbox(): JSONObject { 50 - return this._toolbox; 50 + return this._registry.toolboxes.get(this._toolbox); 51 51 } 52 52 53 53 /** ··· 95 95 } 96 96 97 97 /** 98 + * Get the selected toolbox's name. 99 + * 100 + * @returns The name of the toolbox. 101 + */ 102 + getToolbox() { 103 + return this._toolbox; 104 + } 105 + 106 + /** 98 107 * Set the selected toolbox. 99 108 * 100 109 * @argument name The name of the toolbox. 101 110 */ 102 111 setToolbox(name: string) { 103 - this._toolbox = this._registry.toolboxes.get(name); 112 + if (this._toolbox !== name) { 113 + const toolbox = this._registry.toolboxes.get(name); 114 + this._toolbox = toolbox ? name : 'default'; 115 + this._changed.emit('toolbox'); 116 + } 117 + } 118 + 119 + /** 120 + * List the available toolboxes. 121 + * 122 + * @returns the list of available toolboxes for Blockly 123 + */ 124 + listToolboxes(): { label: string; value: string }[] { 125 + const list: { label: string; value: string }[] = []; 126 + this._registry.toolboxes.forEach((toolbox, name) => { 127 + list.push({ label: name, value: name }); 128 + }); 129 + return list; 104 130 } 105 131 106 132 /** ··· 113 139 } 114 140 115 141 /** 116 - * Set the selected toolbox. 142 + * List the available kernels. 117 143 * 118 144 * @returns the list of available kernels for Blockly 119 145 */
+1939
src/niryo/niryo_one_python_generators.js
··· 1 + /* 2 + niryo_one_python_generators.js 3 + Copyright (C) 2017 Niryo 4 + All rights reserved. 5 + 6 + This program is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + This program is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with this program. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + // adds Custom Niryo One blocks + Python generators 21 + 22 + import * as Blockly from 'blockly'; 23 + 24 + var niryo_one_color = '#3D4D9A'; 25 + 26 + // Interface color 27 + var logic_color = '#00876d'; 28 + var loop_color = '#49a563'; 29 + var math_color = '#5769a1'; 30 + var list_color = '#765da1'; 31 + var variable_color = '#ad5a7e'; 32 + var function_color = '#9f5ca1'; 33 + var movement_color = '#4f87c0'; 34 + var io_color = '#c05150'; 35 + var tool_color = '#bf964b'; 36 + var utility_color = '#bead76'; 37 + var vision_color = '#546e7a'; 38 + var conveyor_color = '#00838f'; 39 + 40 + // Color object for vision 41 + //TODO Should be in a class 42 + const g_color_values = { 43 + COLOR_RED: 'RED', 44 + COLOR_GREEN: 'GREEN', 45 + COLOR_BLUE: 'BLUE', 46 + COLOR_ANY: 'ANY' 47 + }; 48 + 49 + // Shape object for vision 50 + //TODO Should be in a class 51 + const g_shape_values = { 52 + SHAPE_SQUARE: 'SQUARE', 53 + SHAPE_CIRCLE: 'CIRCLE', 54 + SHAPE_ANY: 'ANY' 55 + }; 56 + 57 + /* 58 + * Blocks definition 59 + */ 60 + 61 + // Movement 62 + 63 + Blockly.Blocks['niryo_one_move_joints'] = { 64 + init: function () { 65 + this.appendDummyInput().appendField('Move Joints'); 66 + this.appendDummyInput() 67 + .appendField('j1') 68 + .appendField( 69 + new Blockly.FieldNumber(0, -Infinity, Infinity, 0.001), 70 + 'JOINTS_1' 71 + ) 72 + .appendField('j2') 73 + .appendField( 74 + new Blockly.FieldNumber(0, -Infinity, Infinity, 0.001), 75 + 'JOINTS_2' 76 + ) 77 + .appendField('j3') 78 + .appendField( 79 + new Blockly.FieldNumber(0, -Infinity, Infinity, 0.001), 80 + 'JOINTS_3' 81 + ) 82 + .appendField('j4') 83 + .appendField( 84 + new Blockly.FieldNumber(0, -Infinity, Infinity, 0.001), 85 + 'JOINTS_4' 86 + ) 87 + .appendField('j5') 88 + .appendField( 89 + new Blockly.FieldNumber(0, -Infinity, Infinity, 0.001), 90 + 'JOINTS_5' 91 + ) 92 + .appendField('j6') 93 + .appendField( 94 + new Blockly.FieldNumber(0, -Infinity, Infinity, 0.001), 95 + 'JOINTS_6' 96 + ); 97 + this.setInputsInline(true); 98 + this.setPreviousStatement(true, null); 99 + this.setNextStatement(true, null); 100 + this.setColour(movement_color); 101 + this.setTooltip('Give all 6 joints to move the robot'); 102 + this.setHelpUrl(''); 103 + } 104 + }; 105 + 106 + Blockly.Blocks['niryo_one_move_pose'] = { 107 + init: function () { 108 + this.appendDummyInput().appendField('Move Pose'); 109 + this.appendDummyInput() 110 + .appendField('x') 111 + .appendField( 112 + new Blockly.FieldNumber(0, -Infinity, Infinity, 0.001), 113 + 'POSE_X' 114 + ) 115 + .appendField('y') 116 + .appendField( 117 + new Blockly.FieldNumber(0, -Infinity, Infinity, 0.001), 118 + 'POSE_Y' 119 + ) 120 + .appendField('z') 121 + .appendField( 122 + new Blockly.FieldNumber(0, -Infinity, Infinity, 0.001), 123 + 'POSE_Z' 124 + ) 125 + .appendField('roll') 126 + .appendField( 127 + new Blockly.FieldNumber(0, -Infinity, Infinity, 0.001), 128 + 'POSE_ROLL' 129 + ) 130 + .appendField('pitch') 131 + .appendField( 132 + new Blockly.FieldNumber(0, -Infinity, Infinity, 0.001), 133 + 'POSE_PITCH' 134 + ) 135 + .appendField('yaw') 136 + .appendField( 137 + new Blockly.FieldNumber(0, -Infinity, Infinity, 0.001), 138 + 'POSE_YAW' 139 + ); 140 + this.setInputsInline(true); 141 + this.setPreviousStatement(true, null); 142 + this.setNextStatement(true, null); 143 + this.setColour(movement_color); 144 + this.setTooltip(''); 145 + this.setHelpUrl(''); 146 + } 147 + }; 148 + 149 + Blockly.Blocks['niryo_one_shift_pose'] = { 150 + init: function () { 151 + this.appendDummyInput().appendField('Shift'); 152 + this.appendDummyInput() 153 + .appendField( 154 + new Blockly.FieldDropdown([ 155 + ['pos. x', '0'], 156 + ['pos. y', '1'], 157 + ['pos. z', '2'], 158 + ['rot. x', '3'], 159 + ['rot. y', '4'], 160 + ['rot. z', '5'] 161 + ]), 162 + 'SHIFT_POSE_AXIS' 163 + ) 164 + .appendField('by') 165 + .appendField( 166 + new Blockly.FieldNumber(0, -Infinity, Infinity, 0.001), 167 + 'SHIFT_POSE_VALUE' 168 + ); 169 + this.setInputsInline(true); 170 + this.setPreviousStatement(true, null); 171 + this.setNextStatement(true, null); 172 + this.setColour(movement_color); 173 + this.setTooltip(''); 174 + this.setHelpUrl(''); 175 + } 176 + }; 177 + 178 + Blockly.Blocks['niryo_one_set_arm_max_speed'] = { 179 + init: function () { 180 + this.appendValueInput('SET_ARM_MAX_SPEED') 181 + .setCheck('Number') 182 + .appendField('Set Arm max. speed to'); 183 + this.appendDummyInput().appendField('%'); 184 + this.setInputsInline(true); 185 + this.setPreviousStatement(true, null); 186 + this.setNextStatement(true, null); 187 + this.setColour(movement_color); 188 + this.setTooltip(''); 189 + this.setHelpUrl(''); 190 + } 191 + }; 192 + 193 + Blockly.Blocks['niryo_one_calibrate_auto'] = { 194 + init: function () { 195 + this.appendDummyInput().appendField('Calibrate motors (auto)'); 196 + this.setPreviousStatement(true, null); 197 + this.setNextStatement(true, null); 198 + this.setColour(movement_color); 199 + this.setTooltip( 200 + 'Will auto calibrate motors. If already calibrated, will do nothing.' 201 + ); 202 + this.setHelpUrl(''); 203 + } 204 + }; 205 + 206 + Blockly.Blocks['niryo_one_calibrate_manual'] = { 207 + init: function () { 208 + this.appendDummyInput().appendField('Calibrate motors (manual)'); 209 + this.setPreviousStatement(true, null); 210 + this.setNextStatement(true, null); 211 + this.setColour(movement_color); 212 + this.setTooltip( 213 + 'Will manually calibrate motors (robot needs to be in home position). If already calibrated, will do nothing.' 214 + ); 215 + this.setHelpUrl(''); 216 + } 217 + }; 218 + 219 + Blockly.Blocks['niryo_one_activate_learning_mode'] = { 220 + init: function () { 221 + this.appendDummyInput() 222 + .appendField( 223 + new Blockly.FieldDropdown([ 224 + ['Activate', '1'], 225 + ['Deactivate', '0'] 226 + ]), 227 + 'LEARNING_MODE_VALUE' 228 + ) 229 + .appendField('learning mode'); 230 + this.setPreviousStatement(true, null); 231 + this.setNextStatement(true, null); 232 + this.setColour(movement_color); 233 + this.setTooltip(''); 234 + this.setHelpUrl(''); 235 + } 236 + }; 237 + 238 + Blockly.Blocks['niryo_one_joint'] = { 239 + init: function () { 240 + this.appendDummyInput().appendField('Joints'); 241 + this.appendValueInput('j1').setCheck('Number').appendField('j1'); 242 + this.appendValueInput('j2').setCheck('Number').appendField('j2'); 243 + this.appendValueInput('j3').setCheck('Number').appendField('j3'); 244 + this.appendValueInput('j4').setCheck('Number').appendField('j4'); 245 + this.appendValueInput('j5').setCheck('Number').appendField('j5'); 246 + this.appendValueInput('j6').setCheck('Number').appendField('j6'); 247 + this.setInputsInline(true); 248 + this.setOutput(true, null); 249 + this.setColour(movement_color); 250 + this.setTooltip('Represents an object pose'); 251 + this.setHelpUrl(''); 252 + } 253 + }; 254 + 255 + Blockly.Blocks['niryo_one_move_joint_from_joint'] = { 256 + init: function () { 257 + this.appendValueInput('JOINT') 258 + .setCheck('niryo_one_joint') 259 + .appendField('Move joint'); 260 + this.setTooltip('Move joint with an object pose given'); 261 + this.setPreviousStatement(true, null); 262 + this.setNextStatement(true, null); 263 + this.setColour(movement_color); 264 + this.setHelpUrl(''); 265 + } 266 + }; 267 + 268 + Blockly.Blocks['niryo_one_move_pose_from_pose'] = { 269 + init: function () { 270 + this.appendValueInput('POSE') 271 + .setCheck('niryo_one_pose') 272 + .appendField('Move pose'); 273 + this.setPreviousStatement(true, null); 274 + this.setNextStatement(true, null); 275 + this.setColour(movement_color); 276 + this.setTooltip('Move pose with an object pose given'); 277 + this.setHelpUrl(''); 278 + } 279 + }; 280 + 281 + Blockly.Blocks['niryo_one_pose'] = { 282 + init: function () { 283 + this.appendDummyInput().appendField('Pose'); 284 + this.appendValueInput('x').setCheck('Number').appendField('x'); 285 + this.appendValueInput('y').setCheck('Number').appendField('y'); 286 + this.appendValueInput('z').setCheck('Number').appendField('z'); 287 + this.appendValueInput('roll').setCheck('Number').appendField('roll'); 288 + this.appendValueInput('pitch').setCheck('Number').appendField('pitch'); 289 + this.appendValueInput('yaw').setCheck('Number').appendField('yaw'); 290 + this.setInputsInline(true); 291 + this.setOutput(true, null); 292 + this.setColour(movement_color); 293 + this.setTooltip('Represents an object pose'); 294 + this.setHelpUrl(''); 295 + } 296 + }; 297 + 298 + Blockly.Blocks['niryo_one_move_pose_from_pose'] = { 299 + init: function () { 300 + this.appendValueInput('POSE') 301 + .setCheck('niryo_one_pose') 302 + .appendField('Move pose'); 303 + this.setPreviousStatement(true, null); 304 + this.setNextStatement(true, null); 305 + this.setColour(movement_color); 306 + this.setTooltip('Move pose with an object pose given'); 307 + this.setHelpUrl(''); 308 + } 309 + }; 310 + 311 + Blockly.Blocks['niryo_one_pick_from_pose'] = { 312 + init: function () { 313 + this.appendValueInput('POSE') 314 + .setCheck('niryo_one_pose') 315 + .appendField('Pick from pose'); 316 + this.setPreviousStatement(true, null); 317 + this.setNextStatement(true, null); 318 + this.setColour(movement_color); 319 + this.setTooltip('Pick an object at a pose given'); 320 + this.setHelpUrl(''); 321 + } 322 + }; 323 + 324 + Blockly.Blocks['niryo_one_place_from_pose'] = { 325 + init: function () { 326 + this.appendValueInput('POSE') 327 + .setCheck('niryo_one_pose') 328 + .appendField('Place from pose'); 329 + this.setPreviousStatement(true, null); 330 + this.setNextStatement(true, null); 331 + this.setColour(movement_color); 332 + this.setTooltip('Place an object at a pose given'); 333 + this.setHelpUrl(''); 334 + } 335 + }; 336 + 337 + // I/O 338 + 339 + Blockly.Blocks['niryo_one_gpio_select'] = { 340 + init: function () { 341 + this.appendDummyInput().appendField( 342 + new Blockly.FieldDropdown([ 343 + ['1A', 'GPIO_1A'], 344 + ['1B', 'GPIO_1B'], 345 + ['1C', 'GPIO_1C'], 346 + ['2A', 'GPIO_2A'], 347 + ['2B', 'GPIO_2B'], 348 + ['2C', 'GPIO_2C'] 349 + ]), 350 + 'GPIO_SELECT' 351 + ); 352 + this.setOutput(true, 'niryo_one_gpio_select'); 353 + this.setColour(io_color); 354 + this.setTooltip(''); 355 + this.setHelpUrl(''); 356 + } 357 + }; 358 + 359 + Blockly.Blocks['niryo_one_set_pin_mode'] = { 360 + init: function () { 361 + this.appendValueInput('SET_PIN_MODE_PIN') 362 + .setCheck('niryo_one_gpio_select') 363 + .setAlign(Blockly.ALIGN_RIGHT) 364 + .appendField('Set Pin'); 365 + this.appendDummyInput() 366 + .appendField('to mode') 367 + .appendField( 368 + new Blockly.FieldDropdown([ 369 + ['INPUT', 'PIN_MODE_INPUT'], 370 + ['OUTPUT', 'PIN_MODE_OUTPUT'] 371 + ]), 372 + 'PIN_MODE_SELECT' 373 + ); 374 + this.setInputsInline(true); 375 + this.setPreviousStatement(true, null); 376 + this.setNextStatement(true, null); 377 + this.setColour(io_color); 378 + this.setTooltip(''); 379 + this.setHelpUrl(''); 380 + } 381 + }; 382 + 383 + Blockly.Blocks['niryo_one_digital_write'] = { 384 + init: function () { 385 + this.appendValueInput('DIGITAL_WRITE_PIN') 386 + .setCheck('niryo_one_gpio_select') 387 + .appendField('Set Pin'); 388 + this.appendDummyInput() 389 + .appendField('to state') 390 + .appendField( 391 + new Blockly.FieldDropdown([ 392 + ['HIGH', 'PIN_HIGH'], 393 + ['LOW', 'PIN_LOW'] 394 + ]), 395 + 'PIN_WRITE_SELECT' 396 + ); 397 + this.setInputsInline(true); 398 + this.setPreviousStatement(true, null); 399 + this.setNextStatement(true, null); 400 + this.setColour(io_color); 401 + this.setTooltip(''); 402 + this.setHelpUrl(''); 403 + } 404 + }; 405 + 406 + Blockly.Blocks['niryo_one_digital_read'] = { 407 + init: function () { 408 + this.appendValueInput('DIGITAL_READ_PIN') 409 + .setCheck('niryo_one_gpio_select') 410 + .appendField('Get Pin'); 411 + this.appendDummyInput().appendField('state'); 412 + this.setInputsInline(true); 413 + this.setOutput(true, 'niryo_one_gpio_state'); 414 + this.setColour(io_color); 415 + this.setTooltip(''); 416 + this.setHelpUrl(''); 417 + } 418 + }; 419 + 420 + Blockly.Blocks['niryo_one_gpio_state'] = { 421 + init: function () { 422 + this.appendDummyInput() 423 + .appendField('state') 424 + .appendField( 425 + new Blockly.FieldDropdown([ 426 + ['HIGH', 'PIN_HIGH'], 427 + ['LOW', 'PIN_LOW'] 428 + ]), 429 + 'GPIO_STATE_SELECT' 430 + ); 431 + this.setOutput(true, 'niryo_one_gpio_state'); 432 + this.setColour(io_color); 433 + this.setTooltip(''); 434 + this.setHelpUrl(''); 435 + } 436 + }; 437 + 438 + Blockly.Blocks['niryo_one_sw_select'] = { 439 + init: function () { 440 + this.appendDummyInput().appendField( 441 + new Blockly.FieldDropdown([ 442 + ['SW1', 'SW_1'], 443 + ['SW2', 'SW_2'] 444 + ]), 445 + 'SW_SELECT' 446 + ); 447 + this.setOutput(true, 'niryo_one_sw_select'); 448 + this.setColour(io_color); 449 + this.setTooltip(''); 450 + this.setHelpUrl(''); 451 + } 452 + }; 453 + 454 + Blockly.Blocks['niryo_one_set_12v_switch'] = { 455 + init: function () { 456 + this.appendValueInput('SET_12V_SWITCH') 457 + .setCheck('niryo_one_sw_select') 458 + .appendField('Set 12V Switch'); 459 + this.appendDummyInput() 460 + .appendField('to state') 461 + .appendField( 462 + new Blockly.FieldDropdown([ 463 + ['HIGH', 'PIN_HIGH'], 464 + ['LOW', 'PIN_LOW'] 465 + ]), 466 + 'SET_12V_SWITCH_SELECT' 467 + ); 468 + this.setPreviousStatement(true, null); 469 + this.setNextStatement(true, null); 470 + this.setColour(io_color); 471 + this.setTooltip(''); 472 + this.setHelpUrl(''); 473 + } 474 + }; 475 + 476 + // Tool 477 + 478 + Blockly.Blocks['niryo_one_tool_select'] = { 479 + init: function () { 480 + this.appendDummyInput().appendField( 481 + new Blockly.FieldDropdown([ 482 + ['Standard gripper', 'TOOL_GRIPPER_1_ID'], 483 + ['Large gripper', 'TOOL_GRIPPER_2_ID'], 484 + ['Adaptive gripper ', 'TOOL_GRIPPER_3_ID'], 485 + ['electromagnet 1', 'TOOL_ELECTROMAGNET_1_ID'], 486 + ['vacuum pump 1', 'TOOL_VACUUM_PUMP_1_ID'] 487 + ]), 488 + 'TOOL_SELECT' 489 + ); 490 + this.setOutput(true, 'niryo_one_tool_select'); 491 + this.setColour(tool_color); 492 + this.setTooltip(''); 493 + this.setHelpUrl(''); 494 + } 495 + }; 496 + 497 + Blockly.Blocks['niryo_one_change_tool'] = { 498 + init: function () { 499 + this.appendValueInput('NEW_TOOL_ID') 500 + .setCheck('niryo_one_tool_select') 501 + .appendField('Change tool to'); 502 + this.setInputsInline(true); 503 + this.setPreviousStatement(true, null); 504 + this.setNextStatement(true, null); 505 + this.setColour(tool_color); 506 + this.setTooltip(''); 507 + this.setHelpUrl(''); 508 + } 509 + }; 510 + 511 + Blockly.Blocks['niryo_one_detach_tool'] = { 512 + init: function () { 513 + this.appendDummyInput().appendField('Detach current tool'); 514 + this.setPreviousStatement(true, null); 515 + this.setNextStatement(true, null); 516 + this.setColour(tool_color); 517 + this.setTooltip(''); 518 + this.setHelpUrl(''); 519 + } 520 + }; 521 + 522 + Blockly.Blocks['niryo_one_open_gripper'] = { 523 + init: function () { 524 + this.appendValueInput('OPEN_GRIPPER_ID') 525 + .setCheck('niryo_one_tool_select') 526 + .appendField('Open Gripper'); 527 + this.appendDummyInput() 528 + .appendField('at speed') 529 + .appendField( 530 + new Blockly.FieldDropdown([ 531 + ['1/5', '100'], 532 + ['2/5', '250'], 533 + ['3/5', '500'], 534 + ['4/5', '750'], 535 + ['5/5', '1000'] 536 + ]), 537 + 'OPEN_SPEED' 538 + ); 539 + this.setInputsInline(true); 540 + this.setPreviousStatement(true, null); 541 + this.setNextStatement(true, null); 542 + this.setColour(tool_color); 543 + this.setTooltip(''); 544 + this.setHelpUrl(''); 545 + } 546 + }; 547 + 548 + Blockly.Blocks['niryo_one_close_gripper'] = { 549 + init: function () { 550 + this.appendValueInput('CLOSE_GRIPPER_ID') 551 + .setCheck('niryo_one_tool_select') 552 + .appendField('Close Gripper'); 553 + this.appendDummyInput() 554 + .appendField('at speed') 555 + .appendField( 556 + new Blockly.FieldDropdown([ 557 + ['1/5', '100'], 558 + ['2/5', '250'], 559 + ['3/5', '500'], 560 + ['4/5', '750'], 561 + ['5/5', '1000'] 562 + ]), 563 + 'CLOSE_SPEED' 564 + ); 565 + this.setInputsInline(true); 566 + this.setPreviousStatement(true, null); 567 + this.setNextStatement(true, null); 568 + this.setColour(tool_color); 569 + this.setTooltip(''); 570 + this.setHelpUrl(''); 571 + } 572 + }; 573 + 574 + Blockly.Blocks['niryo_one_pull_air_vacuum_pump'] = { 575 + init: function () { 576 + this.appendValueInput('PULL_AIR_VACUUM_PUMP_ID') 577 + .setCheck('niryo_one_tool_select') 578 + .appendField('Pull air with Vacuum Pump'); 579 + this.setInputsInline(true); 580 + this.setPreviousStatement(true, null); 581 + this.setNextStatement(true, null); 582 + this.setColour(tool_color); 583 + this.setTooltip(''); 584 + this.setHelpUrl(''); 585 + } 586 + }; 587 + 588 + Blockly.Blocks['niryo_one_push_air_vacuum_pump'] = { 589 + init: function () { 590 + this.appendValueInput('PUSH_AIR_VACUUM_PUMP_ID') 591 + .setCheck('niryo_one_tool_select') 592 + .appendField('Push air with Vacuum Pump'); 593 + this.setInputsInline(true); 594 + this.setPreviousStatement(true, null); 595 + this.setNextStatement(true, null); 596 + this.setColour(tool_color); 597 + this.setTooltip(''); 598 + this.setHelpUrl(''); 599 + } 600 + }; 601 + 602 + Blockly.Blocks['niryo_one_setup_electromagnet'] = { 603 + init: function () { 604 + this.appendValueInput('SETUP_ELECTROMAGNET_ID') 605 + .setCheck('niryo_one_tool_select') 606 + .appendField('Setup Electromagnet'); 607 + this.appendValueInput('SETUP_ELECTROMAGNET_PIN') 608 + .setCheck('niryo_one_gpio_select') 609 + .setAlign(Blockly.ALIGN_RIGHT) 610 + .appendField('with pin'); 611 + this.setInputsInline(true); 612 + this.setPreviousStatement(true, null); 613 + this.setNextStatement(true, null); 614 + this.setColour(tool_color); 615 + this.setTooltip(''); 616 + this.setHelpUrl(''); 617 + } 618 + }; 619 + 620 + Blockly.Blocks['niryo_one_activate_electromagnet'] = { 621 + init: function () { 622 + this.appendValueInput('ACTIVATE_ELECTROMAGNET_ID') 623 + .setCheck('niryo_one_tool_select') 624 + .appendField('Activate Electromagnet'); 625 + this.appendValueInput('ACTIVATE_ELECTROMAGNET_PIN') 626 + .setCheck('niryo_one_gpio_select') 627 + .setAlign(Blockly.ALIGN_RIGHT) 628 + .appendField('with pin'); 629 + this.setInputsInline(true); 630 + this.setPreviousStatement(true, null); 631 + this.setNextStatement(true, null); 632 + this.setColour(tool_color); 633 + this.setTooltip(''); 634 + this.setHelpUrl(''); 635 + } 636 + }; 637 + 638 + Blockly.Blocks['niryo_one_deactivate_electromagnet'] = { 639 + init: function () { 640 + this.appendValueInput('DEACTIVATE_ELECTROMAGNET_ID') 641 + .setCheck('niryo_one_tool_select') 642 + .appendField('Deactivate Electromagnet'); 643 + this.appendValueInput('DEACTIVATE_ELECTROMAGNET_PIN') 644 + .setCheck('niryo_one_gpio_select') 645 + .setAlign(Blockly.ALIGN_RIGHT) 646 + .appendField('with pin'); 647 + this.setInputsInline(true); 648 + this.setPreviousStatement(true, null); 649 + this.setNextStatement(true, null); 650 + this.setColour(tool_color); 651 + this.setTooltip(''); 652 + this.setHelpUrl(''); 653 + } 654 + }; 655 + 656 + // Utility 657 + 658 + Blockly.Blocks['niryo_one_sleep'] = { 659 + init: function () { 660 + this.appendValueInput('SLEEP_TIME') 661 + .setCheck('Number') 662 + .appendField('Wait for '); 663 + this.appendDummyInput().appendField('seconds'); 664 + this.setInputsInline(true); 665 + this.setPreviousStatement(true, null); 666 + this.setNextStatement(true, null); 667 + this.setColour(utility_color); 668 + this.setTooltip(''); 669 + this.setHelpUrl(''); 670 + } 671 + }; 672 + 673 + Blockly.Blocks['niryo_one_comment'] = { 674 + init: function () { 675 + this.appendDummyInput() 676 + .appendField('Comment :') 677 + .appendField(new Blockly.FieldTextInput(''), 'COMMENT_TEXT'); 678 + this.setPreviousStatement(true, null); 679 + this.setNextStatement(true, null); 680 + this.setColour(utility_color); 681 + this.setTooltip('This block will not be executed.'); 682 + this.setHelpUrl(''); 683 + } 684 + }; 685 + 686 + Blockly.Blocks['niryo_one_break_point'] = { 687 + init: function () { 688 + this.appendDummyInput().appendField('Break Point'); 689 + this.setPreviousStatement(true, null); 690 + this.setNextStatement(true, null); 691 + this.setColour(utility_color); 692 + this.setTooltip( 693 + "Stop the execution of the program. Press 'Play' to resume." 694 + ); 695 + this.setHelpUrl(''); 696 + } 697 + }; 698 + 699 + // Vision 700 + 701 + Blockly.Blocks['niryo_one_vision_color'] = { 702 + init: function () { 703 + this.appendDummyInput() 704 + .appendField('Color') 705 + .appendField( 706 + new Blockly.FieldDropdown([ 707 + ['RED', 'COLOR_RED'], 708 + ['GREEN', 'COLOR_GREEN'], 709 + ['BLUE', 'COLOR_BLUE'], 710 + ['ANY', 'COLOR_ANY'] 711 + ]), 712 + 'COLOR_SELECT' 713 + ); 714 + this.setOutput(true, 'niryo_one_vision_color'); 715 + this.setColour(vision_color); 716 + this.setTooltip("Color object (must be used with Vision's blocks)"); 717 + } 718 + }; 719 + 720 + Blockly.Blocks['niryo_one_vision_shape'] = { 721 + init: function () { 722 + this.appendDummyInput() 723 + .appendField('Shape') 724 + .appendField( 725 + new Blockly.FieldDropdown([ 726 + ['SQUARE', 'SHAPE_SQUARE'], 727 + ['CIRCLE', 'SHAPE_CIRCLE'], 728 + ['OBJECT', 'SHAPE_ANY'] 729 + ]), 730 + 'SHAPE_SELECT' 731 + ); 732 + this.setOutput(true, 'niryo_one_vision_shape'); 733 + this.setColour(vision_color); 734 + this.setTooltip("Shape object (must be used with Vision's blocks)"); 735 + } 736 + }; 737 + 738 + Blockly.Blocks['niryo_one_vision_pick'] = { 739 + init: function () { 740 + this.appendValueInput('COLOR_SWITCH') 741 + .setCheck('niryo_one_vision_color') 742 + .appendField('Vision pick'); 743 + 744 + this.appendValueInput('SHAPE_SWITCH').setCheck('niryo_one_vision_shape'); 745 + this.appendDummyInput().appendField('in workspace'); 746 + 747 + this.appendValueInput('WORKSPACE_NAME').setCheck('String'); 748 + 749 + this.appendValueInput('HEIGHT_OFFSET') 750 + .setCheck('Number') 751 + .appendField('with height offset (mm)'); 752 + 753 + this.setOutput(true, 'Boolean'); 754 + this.setColour(vision_color); 755 + this.setHelpUrl(''); 756 + this.setTooltip( 757 + 'Pick an object of SHAPE / COLOR given, with gripper close position at HEIGHT_OFFSET cm.' 758 + ); 759 + this.setInputsInline(false); 760 + } 761 + }; 762 + 763 + Blockly.Blocks['niryo_one_vision_is_object_detected'] = { 764 + init: function () { 765 + this.appendValueInput('COLOR_SWITCH') 766 + .setCheck('niryo_one_vision_color') 767 + .appendField('Is object detected'); 768 + 769 + this.appendValueInput('SHAPE_SWITCH').setCheck('niryo_one_vision_shape'); 770 + this.appendDummyInput().appendField('in workspace'); 771 + 772 + this.appendValueInput('WORKSPACE_NAME').setCheck('String'); 773 + 774 + this.setOutput(true, 'Boolean'); 775 + this.setColour(vision_color); 776 + this.setHelpUrl(''); 777 + this.setTooltip( 778 + 'Detect is there is an object of SHAPE / COLOR in the WORKSPACE given.' 779 + ); 780 + this.setInputsInline(false); 781 + } 782 + }; 783 + 784 + // Conveyor 785 + 786 + Blockly.Blocks['niryo_one_conveyor_models'] = { 787 + init: function () { 788 + this.appendDummyInput().appendField( 789 + new Blockly.FieldDropdown([ 790 + ['Conveyor 1', 'CONVEYOR_1'], 791 + ['Conveyor 2', 'CONVEYOR_2'] 792 + ]), 793 + 'CONVEYOR_SELECT' 794 + ); 795 + this.setOutput(true, 'niryo_one_conveyor_models'); 796 + 797 + this.setColour(conveyor_color); 798 + this.setHelpUrl(''); 799 + this.setTooltip('Conveyors available with Niryo One.'); 800 + } 801 + }; 802 + 803 + Blockly.Blocks['niryo_one_conveyor_use'] = { 804 + init: function () { 805 + this.appendValueInput('CONVEYOR_SWITCH') 806 + .setCheck('niryo_one_conveyor_models') 807 + .appendField('Use conveyor:'); 808 + 809 + this.setColour(conveyor_color); 810 + this.setHelpUrl(''); 811 + this.setTooltip('Allow the conveyor to be controlled via Niryo One.'); 812 + this.setPreviousStatement(true, null); 813 + this.setNextStatement(true, null); 814 + } 815 + }; 816 + 817 + Blockly.Blocks['niryo_one_conveyor_control'] = { 818 + init: function () { 819 + this.appendValueInput('CONVEYOR_SWITCH') 820 + .setCheck('niryo_one_conveyor_models') 821 + .appendField('Control conveyor:'); 822 + 823 + this.appendValueInput('SPEED_PERCENT') 824 + .setCheck('Number') 825 + .appendField('with speed (%):'); 826 + 827 + this.appendDummyInput() 828 + .appendField('in direction:') 829 + .appendField( 830 + new Blockly.FieldDropdown([ 831 + ['FORWARD', '1'], 832 + ['BACKWARD', '-1'] 833 + ]), 834 + 'DIRECTION_SELECT' 835 + ); 836 + 837 + this.setColour(conveyor_color); 838 + this.setHelpUrl(''); 839 + this.setTooltip('Control the conveyor given.'); 840 + this.setPreviousStatement(true, null); 841 + this.setNextStatement(true, null); 842 + this.setInputsInline(false); 843 + } 844 + }; 845 + 846 + Blockly.Blocks['niryo_one_conveyor_stop'] = { 847 + init: function () { 848 + this.appendValueInput('CONVEYOR_SWITCH') 849 + .setCheck('niryo_one_conveyor_models') 850 + .appendField('Stop conveyor'); 851 + 852 + this.setColour(conveyor_color); 853 + this.setHelpUrl(''); 854 + this.setTooltip('Stop the conveyor given.'); 855 + this.setPreviousStatement(true, null); 856 + this.setNextStatement(true, null); 857 + } 858 + }; 859 + 860 + /* 861 + * Generators 862 + */ 863 + 864 + // Movement 865 + 866 + Blockly.Python['niryo_one_move_joints'] = function (block) { 867 + var number_joints_1 = block.getFieldValue('JOINTS_1'); 868 + var number_joints_2 = block.getFieldValue('JOINTS_2'); 869 + var number_joints_3 = block.getFieldValue('JOINTS_3'); 870 + var number_joints_4 = block.getFieldValue('JOINTS_4'); 871 + var number_joints_5 = block.getFieldValue('JOINTS_5'); 872 + var number_joints_6 = block.getFieldValue('JOINTS_6'); 873 + 874 + var code = 875 + 'n.move_joints([' + 876 + number_joints_1 + 877 + ', ' + 878 + number_joints_2 + 879 + ', ' + 880 + number_joints_3 + 881 + ', ' + 882 + number_joints_4 + 883 + ', ' + 884 + number_joints_5 + 885 + ', ' + 886 + number_joints_6 + 887 + '])\n'; 888 + return code; 889 + }; 890 + 891 + Blockly.Python['niryo_one_move_pose'] = function (block) { 892 + var number_pose_x = block.getFieldValue('POSE_X'); 893 + var number_pose_y = block.getFieldValue('POSE_Y'); 894 + var number_pose_z = block.getFieldValue('POSE_Z'); 895 + var number_pose_roll = block.getFieldValue('POSE_ROLL'); 896 + var number_pose_pitch = block.getFieldValue('POSE_PITCH'); 897 + var number_pose_yaw = block.getFieldValue('POSE_YAW'); 898 + 899 + var code = 900 + 'n.move_pose(' + 901 + number_pose_x + 902 + ', ' + 903 + number_pose_y + 904 + ', ' + 905 + number_pose_z + 906 + ', ' + 907 + number_pose_roll + 908 + ', ' + 909 + number_pose_pitch + 910 + ', ' + 911 + number_pose_yaw + 912 + ')\n'; 913 + return code; 914 + }; 915 + 916 + Blockly.Python['niryo_one_shift_pose'] = function (block) { 917 + var dropdown_shift_pose_axis = block.getFieldValue('SHIFT_POSE_AXIS'); 918 + var number_shift_pose_value = block.getFieldValue('SHIFT_POSE_VALUE'); 919 + 920 + var code = 921 + 'n.shift_pose(' + 922 + dropdown_shift_pose_axis + 923 + ', ' + 924 + number_shift_pose_value + 925 + ')\n'; 926 + return code; 927 + }; 928 + 929 + Blockly.Python['niryo_one_set_arm_max_speed'] = function (block) { 930 + var value_set_arm_max_speed = 931 + Blockly.Python.valueToCode( 932 + block, 933 + 'SET_ARM_MAX_SPEED', 934 + Blockly.Python.ORDER_ATOMIC 935 + ) || '0'; 936 + value_set_arm_max_speed = value_set_arm_max_speed 937 + .replace('(', '') 938 + .replace(')', ''); 939 + var code = 'n.set_arm_max_velocity(' + value_set_arm_max_speed + ')\n'; 940 + return code; 941 + }; 942 + 943 + Blockly.Python['niryo_one_calibrate_auto'] = function (block) { 944 + var code = 'n.calibrate_auto()\n'; 945 + return code; 946 + }; 947 + 948 + Blockly.Python['niryo_one_calibrate_manual'] = function (block) { 949 + var code = 'n.calibrate_manual()\n'; 950 + return code; 951 + }; 952 + 953 + Blockly.Python['niryo_one_activate_learning_mode'] = function (block) { 954 + var dropdown_learning_mode_value = block.getFieldValue('LEARNING_MODE_VALUE'); 955 + var code = 'n.activate_learning_mode(' + dropdown_learning_mode_value + ')\n'; 956 + return code; 957 + }; 958 + 959 + Blockly.Python['niryo_one_joint'] = function (block) { 960 + var value_j1 = Blockly.Python.valueToCode( 961 + block, 962 + 'j1', 963 + Blockly.Python.ORDER_ATOMIC 964 + ) 965 + .replace('(', '') 966 + .replace(')', ''); 967 + var value_j2 = Blockly.Python.valueToCode( 968 + block, 969 + 'j2', 970 + Blockly.Python.ORDER_ATOMIC 971 + ) 972 + .replace('(', '') 973 + .replace(')', ''); 974 + var value_j3 = Blockly.Python.valueToCode( 975 + block, 976 + 'j3', 977 + Blockly.Python.ORDER_ATOMIC 978 + ) 979 + .replace('(', '') 980 + .replace(')', ''); 981 + var value_j4 = Blockly.Python.valueToCode( 982 + block, 983 + 'j4', 984 + Blockly.Python.ORDER_ATOMIC 985 + ) 986 + .replace('(', '') 987 + .replace(')', ''); 988 + var value_j5 = Blockly.Python.valueToCode( 989 + block, 990 + 'j5', 991 + Blockly.Python.ORDER_ATOMIC 992 + ) 993 + .replace('(', '') 994 + .replace(')', ''); 995 + var value_j6 = Blockly.Python.valueToCode( 996 + block, 997 + 'j6', 998 + Blockly.Python.ORDER_ATOMIC 999 + ) 1000 + .replace('(', '') 1001 + .replace(')', ''); 1002 + 1003 + var code = 1004 + '[' + 1005 + value_j1 + 1006 + ', ' + 1007 + value_j2 + 1008 + ', ' + 1009 + value_j3 + 1010 + ', ' + 1011 + value_j4 + 1012 + ', ' + 1013 + value_j5 + 1014 + ', ' + 1015 + value_j6 + 1016 + ']'; 1017 + return [code, Blockly.Python.ORDER_NONE]; 1018 + }; 1019 + 1020 + Blockly.Python['niryo_one_move_joint_from_joint'] = function (block) { 1021 + // Position object 1022 + var value_joint = Blockly.Python.valueToCode( 1023 + block, 1024 + 'JOINT', 1025 + Blockly.Python.ORDER_ATOMIC 1026 + ); 1027 + value_joint = value_joint.replace('(', '').replace(')', ''); 1028 + 1029 + var code = 'n.move_joints(' + value_joint + ')\n'; 1030 + return code; 1031 + }; 1032 + 1033 + Blockly.Python['niryo_one_pose'] = function (block) { 1034 + var value_x = Blockly.Python.valueToCode( 1035 + block, 1036 + 'x', 1037 + Blockly.Python.ORDER_ATOMIC 1038 + ) 1039 + .replace('(', '') 1040 + .replace(')', ''); 1041 + var value_y = Blockly.Python.valueToCode( 1042 + block, 1043 + 'y', 1044 + Blockly.Python.ORDER_ATOMIC 1045 + ) 1046 + .replace('(', '') 1047 + .replace(')', ''); 1048 + var value_z = Blockly.Python.valueToCode( 1049 + block, 1050 + 'z', 1051 + Blockly.Python.ORDER_ATOMIC 1052 + ) 1053 + .replace('(', '') 1054 + .replace(')', ''); 1055 + var value_roll = Blockly.Python.valueToCode( 1056 + block, 1057 + 'roll', 1058 + Blockly.Python.ORDER_ATOMIC 1059 + ) 1060 + .replace('(', '') 1061 + .replace(')', ''); 1062 + var value_pitch = Blockly.Python.valueToCode( 1063 + block, 1064 + 'pitch', 1065 + Blockly.Python.ORDER_ATOMIC 1066 + ) 1067 + .replace('(', '') 1068 + .replace(')', ''); 1069 + var value_yaw = Blockly.Python.valueToCode( 1070 + block, 1071 + 'yaw', 1072 + Blockly.Python.ORDER_ATOMIC 1073 + ) 1074 + .replace('(', '') 1075 + .replace(')', ''); 1076 + 1077 + var code = 1078 + '[' + 1079 + value_x + 1080 + ', ' + 1081 + value_y + 1082 + ', ' + 1083 + value_z + 1084 + ', ' + 1085 + value_roll + 1086 + ', ' + 1087 + value_pitch + 1088 + ', ' + 1089 + value_yaw + 1090 + ']'; 1091 + return [code, Blockly.Python.ORDER_NONE]; 1092 + }; 1093 + 1094 + Blockly.Python['niryo_one_move_pose_from_pose'] = function (block) { 1095 + // Position object 1096 + var value_pose = Blockly.Python.valueToCode( 1097 + block, 1098 + 'POSE', 1099 + Blockly.Python.ORDER_ATOMIC 1100 + ); 1101 + value_pose = value_pose.replace('(', '').replace(')', ''); 1102 + 1103 + var code = 'n.move_pose(*' + value_pose + ')\n'; 1104 + return code; 1105 + }; 1106 + 1107 + Blockly.Python['niryo_one_pick_from_pose'] = function (block) { 1108 + // Position object 1109 + var value_pose = Blockly.Python.valueToCode( 1110 + block, 1111 + 'POSE', 1112 + Blockly.Python.ORDER_ATOMIC 1113 + ); 1114 + value_pose = value_pose.replace('(', '').replace(')', ''); 1115 + 1116 + var code = 'n.pick_from_pose(*' + value_pose + ')\n'; 1117 + return code; 1118 + }; 1119 + 1120 + Blockly.Python['niryo_one_place_from_pose'] = function (block) { 1121 + // Position object 1122 + var value_pose = Blockly.Python.valueToCode( 1123 + block, 1124 + 'POSE', 1125 + Blockly.Python.ORDER_ATOMIC 1126 + ); 1127 + value_pose = value_pose.replace('(', '').replace(')', ''); 1128 + 1129 + var code = 'n.place_from_pose(*' + value_pose + ')\n'; 1130 + return code; 1131 + }; 1132 + 1133 + // I/O 1134 + 1135 + Blockly.Python['niryo_one_gpio_state'] = function (block) { 1136 + var dropdown_gpio_state_select = block.getFieldValue('GPIO_STATE_SELECT'); 1137 + var code = dropdown_gpio_state_select; 1138 + return [code, Blockly.Python.ORDER_NONE]; 1139 + }; 1140 + 1141 + Blockly.Python['niryo_one_set_pin_mode'] = function (block) { 1142 + var value_pin = 1143 + Blockly.Python.valueToCode( 1144 + block, 1145 + 'SET_PIN_MODE_PIN', 1146 + Blockly.Python.ORDER_ATOMIC 1147 + ) || '(0)'; 1148 + value_pin = value_pin.replace('(', '').replace(')', ''); 1149 + var dropdown_pin_mode_select = block.getFieldValue('PIN_MODE_SELECT'); 1150 + var code = 1151 + 'n.pin_mode(' + value_pin + ', ' + dropdown_pin_mode_select + ')\n'; 1152 + return code; 1153 + }; 1154 + 1155 + Blockly.Python['niryo_one_digital_write'] = function (block) { 1156 + var value_pin = 1157 + Blockly.Python.valueToCode( 1158 + block, 1159 + 'DIGITAL_WRITE_PIN', 1160 + Blockly.Python.ORDER_ATOMIC 1161 + ) || '(0)'; 1162 + value_pin = value_pin.replace('(', '').replace(')', ''); 1163 + var dropdown_pin_write_select = block.getFieldValue('PIN_WRITE_SELECT'); 1164 + var code = 1165 + 'n.digital_write(' + value_pin + ', ' + dropdown_pin_write_select + ')\n'; 1166 + return code; 1167 + }; 1168 + 1169 + Blockly.Python['niryo_one_digital_read'] = function (block) { 1170 + var value_pin = 1171 + Blockly.Python.valueToCode( 1172 + block, 1173 + 'DIGITAL_READ_PIN', 1174 + Blockly.Python.ORDER_ATOMIC 1175 + ) || '(0)'; 1176 + value_pin = value_pin.replace('(', '').replace(')', ''); 1177 + var code = 'n.digital_read(' + value_pin + ')'; 1178 + return [code, Blockly.Python.ORDER_NONE]; 1179 + }; 1180 + 1181 + Blockly.Python['niryo_one_gpio_select'] = function (block) { 1182 + var dropdown_gpio_select = block.getFieldValue('GPIO_SELECT'); 1183 + var code = dropdown_gpio_select; 1184 + return [code, Blockly.Python.ORDER_NONE]; 1185 + }; 1186 + 1187 + Blockly.Python['niryo_one_sw_select'] = function (block) { 1188 + var dropdown_sw_select = block.getFieldValue('SW_SELECT'); 1189 + var code = dropdown_sw_select; 1190 + return [code, Blockly.Python.ORDER_NONE]; 1191 + }; 1192 + 1193 + Blockly.Python['niryo_one_set_12v_switch'] = function (block) { 1194 + var value_pin = 1195 + Blockly.Python.valueToCode( 1196 + block, 1197 + 'SET_12V_SWITCH', 1198 + Blockly.Python.ORDER_ATOMIC 1199 + ) || '(0)'; 1200 + value_pin = value_pin.replace('(', '').replace(')', ''); 1201 + var dropdown_set_12v_switch_select = block.getFieldValue( 1202 + 'SET_12V_SWITCH_SELECT' 1203 + ); 1204 + var code = 1205 + 'n.digital_write(' + 1206 + value_pin + 1207 + ', ' + 1208 + dropdown_set_12v_switch_select + 1209 + ')\n'; 1210 + return code; 1211 + }; 1212 + 1213 + // Tool 1214 + 1215 + Blockly.Python['niryo_one_tool_select'] = function (block) { 1216 + var dropdown_tool_select = block.getFieldValue('TOOL_SELECT'); 1217 + var code = dropdown_tool_select; 1218 + return [code, Blockly.Python.ORDER_NONE]; 1219 + }; 1220 + 1221 + Blockly.Python['niryo_one_change_tool'] = function (block) { 1222 + var value_tool_name = 1223 + Blockly.Python.valueToCode( 1224 + block, 1225 + 'NEW_TOOL_ID', 1226 + Blockly.Python.ORDER_ATOMIC 1227 + ) || '(TOOL_NONE)'; 1228 + value_tool_name = value_tool_name.replace('(', '').replace(')', ''); 1229 + var code = 'n.change_tool(' + value_tool_name + ')\n'; 1230 + return code; 1231 + }; 1232 + 1233 + Blockly.Python['niryo_one_detach_tool'] = function (block) { 1234 + var code = 'n.change_tool(0)\n'; 1235 + return code; 1236 + }; 1237 + 1238 + Blockly.Python['niryo_one_open_gripper'] = function (block) { 1239 + var value_gripper_id = 1240 + Blockly.Python.valueToCode( 1241 + block, 1242 + 'OPEN_GRIPPER_ID', 1243 + Blockly.Python.ORDER_ATOMIC 1244 + ) || '(TOOL_NONE)'; 1245 + value_gripper_id = value_gripper_id.replace('(', '').replace(')', ''); 1246 + var number_open_speed = block.getFieldValue('OPEN_SPEED'); 1247 + var code = 1248 + 'n.open_gripper(' + value_gripper_id + ', ' + number_open_speed + ')\n'; 1249 + return code; 1250 + }; 1251 + 1252 + Blockly.Python['niryo_one_close_gripper'] = function (block) { 1253 + var value_gripper_id = 1254 + Blockly.Python.valueToCode( 1255 + block, 1256 + 'CLOSE_GRIPPER_ID', 1257 + Blockly.Python.ORDER_ATOMIC 1258 + ) || '(TOOL_NONE)'; 1259 + value_gripper_id = value_gripper_id.replace('(', '').replace(')', ''); 1260 + var number_close_speed = block.getFieldValue('CLOSE_SPEED'); 1261 + var code = 1262 + 'n.close_gripper(' + value_gripper_id + ', ' + number_close_speed + ')\n'; 1263 + return code; 1264 + }; 1265 + 1266 + Blockly.Python['niryo_one_pull_air_vacuum_pump'] = function (block) { 1267 + var value_vacuum_pump_id = 1268 + Blockly.Python.valueToCode( 1269 + block, 1270 + 'PULL_AIR_VACUUM_PUMP_ID', 1271 + Blockly.Python.ORDER_ATOMIC 1272 + ) || '(TOOL_NONE)'; 1273 + value_vacuum_pump_id = value_vacuum_pump_id.replace('(', '').replace(')', ''); 1274 + var code = 'n.pull_air_vacuum_pump(' + value_vacuum_pump_id + ')\n'; 1275 + return code; 1276 + }; 1277 + 1278 + Blockly.Python['niryo_one_push_air_vacuum_pump'] = function (block) { 1279 + var value_vacuum_pump_id = 1280 + Blockly.Python.valueToCode( 1281 + block, 1282 + 'PUSH_AIR_VACUUM_PUMP_ID', 1283 + Blockly.Python.ORDER_ATOMIC 1284 + ) || '(TOOL_NONE)'; 1285 + value_vacuum_pump_id = value_vacuum_pump_id.replace('(', '').replace(')', ''); 1286 + var code = 'n.push_air_vacuum_pump(' + value_vacuum_pump_id + ')\n'; 1287 + return code; 1288 + }; 1289 + 1290 + Blockly.Python['niryo_one_setup_electromagnet'] = function (block) { 1291 + var value_electromagnet_id = 1292 + Blockly.Python.valueToCode( 1293 + block, 1294 + 'SETUP_ELECTROMAGNET_ID', 1295 + Blockly.Python.ORDER_ATOMIC 1296 + ) || '(TOOL_NONE)'; 1297 + value_electromagnet_id = value_electromagnet_id 1298 + .replace('(', '') 1299 + .replace(')', ''); 1300 + var value_electromagnet_pin = 1301 + Blockly.Python.valueToCode( 1302 + block, 1303 + 'SETUP_ELECTROMAGNET_PIN', 1304 + Blockly.Python.ORDER_ATOMIC 1305 + ) || '(0)'; 1306 + value_electromagnet_pin = value_electromagnet_pin 1307 + .replace('(', '') 1308 + .replace(')', ''); 1309 + var code = 1310 + 'n.setup_electromagnet(' + 1311 + value_electromagnet_id + 1312 + ', ' + 1313 + value_electromagnet_pin + 1314 + ')\n'; 1315 + return code; 1316 + }; 1317 + 1318 + Blockly.Python['niryo_one_activate_electromagnet'] = function (block) { 1319 + var value_electromagnet_id = 1320 + Blockly.Python.valueToCode( 1321 + block, 1322 + 'ACTIVATE_ELECTROMAGNET_ID', 1323 + Blockly.Python.ORDER_ATOMIC 1324 + ) || '(TOOL_NONE)'; 1325 + value_electromagnet_id = value_electromagnet_id 1326 + .replace('(', '') 1327 + .replace(')', ''); 1328 + var value_electromagnet_pin = 1329 + Blockly.Python.valueToCode( 1330 + block, 1331 + 'ACTIVATE_ELECTROMAGNET_PIN', 1332 + Blockly.Python.ORDER_ATOMIC 1333 + ) || '(0)'; 1334 + value_electromagnet_pin = value_electromagnet_pin 1335 + .replace('(', '') 1336 + .replace(')', ''); 1337 + var code = 1338 + 'n.activate_electromagnet(' + 1339 + value_electromagnet_id + 1340 + ', ' + 1341 + value_electromagnet_pin + 1342 + ')\n'; 1343 + return code; 1344 + }; 1345 + 1346 + Blockly.Python['niryo_one_deactivate_electromagnet'] = function (block) { 1347 + var value_electromagnet_id = 1348 + Blockly.Python.valueToCode( 1349 + block, 1350 + 'DEACTIVATE_ELECTROMAGNET_ID', 1351 + Blockly.Python.ORDER_ATOMIC 1352 + ) || '(TOOL_NONE)'; 1353 + value_electromagnet_id = value_electromagnet_id 1354 + .replace('(', '') 1355 + .replace(')', ''); 1356 + var value_electromagnet_pin = 1357 + Blockly.Python.valueToCode( 1358 + block, 1359 + 'DEACTIVATE_ELECTROMAGNET_PIN', 1360 + Blockly.Python.ORDER_ATOMIC 1361 + ) || '(0)'; 1362 + value_electromagnet_pin = value_electromagnet_pin 1363 + .replace('(', '') 1364 + .replace(')', ''); 1365 + var code = 1366 + 'n.deactivate_electromagnet(' + 1367 + value_electromagnet_id + 1368 + ', ' + 1369 + value_electromagnet_pin + 1370 + ')\n'; 1371 + return code; 1372 + }; 1373 + 1374 + // Utility 1375 + 1376 + Blockly.Python['niryo_one_sleep'] = function (block) { 1377 + var value_sleep_time = 1378 + Blockly.Python.valueToCode( 1379 + block, 1380 + 'SLEEP_TIME', 1381 + Blockly.Python.ORDER_ATOMIC 1382 + ) || '0'; 1383 + value_sleep_time = value_sleep_time.replace('(', '').replace(')', ''); 1384 + var code = 'n.wait(' + value_sleep_time + ')\n'; 1385 + return code; 1386 + }; 1387 + 1388 + Blockly.Python['niryo_one_comment'] = function (block) { 1389 + var text_comment_text = block.getFieldValue('COMMENT_TEXT'); 1390 + var code = ' #' + text_comment_text + '\n'; 1391 + return code; 1392 + }; 1393 + 1394 + Blockly.Python['niryo_one_break_point'] = function (block) { 1395 + var code = 'n.break_point()\n'; 1396 + return code; 1397 + }; 1398 + 1399 + // Vision 1400 + 1401 + Blockly.Python['niryo_one_vision_color'] = function (block) { 1402 + var dropdown_color_select = block.getFieldValue('COLOR_SELECT'); 1403 + var code = dropdown_color_select; 1404 + code = '"' + g_color_values[code] + '"'; 1405 + return [code, Blockly.Python.ORDER_NONE]; 1406 + }; 1407 + 1408 + Blockly.Python['niryo_one_vision_shape'] = function (block) { 1409 + var dropdown_shape_select = block.getFieldValue('SHAPE_SELECT'); 1410 + var code = dropdown_shape_select; 1411 + code = '"' + g_shape_values[code] + '"'; 1412 + return [code, Blockly.Python.ORDER_NONE]; 1413 + }; 1414 + 1415 + Blockly.Python['niryo_one_vision_pick'] = function (block) { 1416 + // Color (int) value (see g_shape_values at top of this file) 1417 + var value_color = 1418 + Blockly.Python.valueToCode( 1419 + block, 1420 + 'COLOR_SWITCH', 1421 + Blockly.Python.ORDER_ATOMIC 1422 + ) || '(0)'; 1423 + value_color = value_color.replace('(', '').replace(')', ''); 1424 + 1425 + // Shape (int) value (see g_shape_values at top of this file) 1426 + var value_shape = 1427 + Blockly.Python.valueToCode( 1428 + block, 1429 + 'SHAPE_SWITCH', 1430 + Blockly.Python.ORDER_ATOMIC 1431 + ) || '(0)'; 1432 + value_shape = value_shape.replace('(', '').replace(')', ''); 1433 + 1434 + // Name of workspace 1435 + var workspace_name = 1436 + Blockly.Python.valueToCode( 1437 + block, 1438 + 'WORKSPACE_NAME', 1439 + Blockly.Python.ORDER_ATOMIC 1440 + ) || '(0)'; 1441 + workspace_name = workspace_name.replace('(', '').replace(')', ''); 1442 + 1443 + // Height in centimeter 1444 + var height_offset = 1445 + Blockly.Python.valueToCode( 1446 + block, 1447 + 'HEIGHT_OFFSET', 1448 + Blockly.Python.ORDER_ATOMIC 1449 + ) || '(0)'; 1450 + height_offset = height_offset.replace('(', '').replace(')', ''); 1451 + 1452 + var code = 1453 + 'n.vision_pick(' + 1454 + workspace_name + 1455 + ', float(' + 1456 + height_offset + 1457 + ')/1000, ' + 1458 + value_shape + 1459 + ', ' + 1460 + value_color + 1461 + ')[0]'; 1462 + return [code, Blockly.Python.ORDER_NONE]; 1463 + }; 1464 + 1465 + Blockly.Python['niryo_one_vision_is_object_detected'] = function (block) { 1466 + // Color (int) value (see g_shape_values at top of this file) 1467 + var value_color = 1468 + Blockly.Python.valueToCode( 1469 + block, 1470 + 'COLOR_SWITCH', 1471 + Blockly.Python.ORDER_ATOMIC 1472 + ) || '(0)'; 1473 + value_color = value_color.replace('(', '').replace(')', ''); 1474 + 1475 + // Shape (int) value (see g_shape_values at top of this file) 1476 + var value_shape = 1477 + Blockly.Python.valueToCode( 1478 + block, 1479 + 'SHAPE_SWITCH', 1480 + Blockly.Python.ORDER_ATOMIC 1481 + ) || '(0)'; 1482 + value_shape = value_shape.replace('(', '').replace(')', ''); 1483 + 1484 + // Name of workspace 1485 + var workspace_name = 1486 + Blockly.Python.valueToCode( 1487 + block, 1488 + 'WORKSPACE_NAME', 1489 + Blockly.Python.ORDER_ATOMIC 1490 + ) || '(0)'; 1491 + workspace_name = workspace_name.replace('(', '').replace(')', ''); 1492 + 1493 + var code = 1494 + 'n.detect_object(' + 1495 + workspace_name + 1496 + ', ' + 1497 + value_shape + 1498 + ', ' + 1499 + value_color + 1500 + ')[0]'; 1501 + return [code, Blockly.Python.ORDER_NONE]; 1502 + }; 1503 + 1504 + // Conveyor 1505 + 1506 + Blockly.Python['niryo_one_conveyor_models'] = function (block) { 1507 + const conveyor_id_map = { 1508 + CONVEYOR_1: 6, 1509 + CONVEYOR_2: 7 1510 + }; 1511 + var conveyor_model_id = block.getFieldValue('CONVEYOR_SELECT'); 1512 + var code = conveyor_id_map[conveyor_model_id]; 1513 + return [code, Blockly.Python.ORDER_NONE]; 1514 + }; 1515 + 1516 + Blockly.Python['niryo_one_conveyor_use'] = function (block) { 1517 + var conveyor_id = 1518 + Blockly.Python.valueToCode( 1519 + block, 1520 + 'CONVEYOR_SWITCH', 1521 + Blockly.Python.ORDER_ATOMIC 1522 + ) || '(0)'; 1523 + conveyor_id = conveyor_id.replace('(', '').replace(')', ''); 1524 + var code = 'n.set_conveyor(' + conveyor_id + ', True)\n'; 1525 + return code; 1526 + }; 1527 + 1528 + Blockly.Python['niryo_one_conveyor_control'] = function (block) { 1529 + var conveyor_id = 1530 + Blockly.Python.valueToCode( 1531 + block, 1532 + 'CONVEYOR_SWITCH', 1533 + Blockly.Python.ORDER_ATOMIC 1534 + ) || '(0)'; 1535 + conveyor_id = conveyor_id.replace('(', '').replace(')', ''); 1536 + var speed_percent = 1537 + Blockly.Python.valueToCode( 1538 + block, 1539 + 'SPEED_PERCENT', 1540 + Blockly.Python.ORDER_ATOMIC 1541 + ) || '(0)'; 1542 + speed_percent = speed_percent.replace('(', '').replace(')', ''); 1543 + var direction = block.getFieldValue('DIRECTION_SELECT'); 1544 + var code = 1545 + 'n.control_conveyor(' + 1546 + conveyor_id + 1547 + ', True, ' + 1548 + speed_percent + 1549 + ', ' + 1550 + direction + 1551 + ')\n'; 1552 + return code; 1553 + }; 1554 + 1555 + Blockly.Python['niryo_one_conveyor_stop'] = function (block) { 1556 + var conveyor_id = 1557 + Blockly.Python.valueToCode( 1558 + block, 1559 + 'CONVEYOR_SWITCH', 1560 + Blockly.Python.ORDER_ATOMIC 1561 + ) || '(0)'; 1562 + conveyor_id = conveyor_id.replace('(', '').replace(')', ''); 1563 + var code = 'n.control_conveyor(' + conveyor_id + ', False, 0, 1)\n'; 1564 + return code; 1565 + }; 1566 + 1567 + // Creating a toolbox containing all the main (default) blocks. 1568 + const TOOLBOX = { 1569 + kind: 'categoryToolbox', 1570 + contents: [ 1571 + { 1572 + kind: 'category', 1573 + name: 'Logic', 1574 + colour: '210', 1575 + contents: [ 1576 + { 1577 + kind: 'block', 1578 + type: 'controls_if' 1579 + }, 1580 + { 1581 + kind: 'BLOCK', 1582 + type: 'logic_compare' 1583 + }, 1584 + { 1585 + kind: 'BLOCK', 1586 + blockxml: '<block type="logic_operation"></block>', 1587 + type: 'logic_operation' 1588 + }, 1589 + { 1590 + kind: 'BLOCK', 1591 + blockxml: '<block type="logic_negate"></block>', 1592 + type: 'logic_negate' 1593 + }, 1594 + { 1595 + kind: 'BLOCK', 1596 + blockxml: '<block type="logic_boolean"></block>', 1597 + type: 'logic_boolean' 1598 + }, 1599 + { 1600 + kind: 'BLOCK', 1601 + blockxml: '<block type="logic_null"></block>', 1602 + type: 'logic_null' 1603 + }, 1604 + { 1605 + kind: 'BLOCK', 1606 + blockxml: '<block type="logic_ternary"></block>', 1607 + type: 'logic_ternary' 1608 + } 1609 + ] 1610 + }, 1611 + { 1612 + kind: 'category', 1613 + name: 'Loops', 1614 + colour: '120', 1615 + contents: [ 1616 + { 1617 + kind: 'BLOCK', 1618 + blockxml: 1619 + '<block type="controls_repeat_ext">\n <value name="TIMES">\n <shadow type="math_number">\n <field name="NUM">10</field>\n </shadow>\n </value>\n </block>', 1620 + type: 'controls_repeat_ext' 1621 + }, 1622 + { 1623 + kind: 'BLOCK', 1624 + blockxml: '<block type="controls_whileUntil"></block>', 1625 + type: 'controls_whileUntil' 1626 + }, 1627 + { 1628 + kind: 'BLOCK', 1629 + blockxml: 1630 + '<block type="controls_for">\n <value name="FROM">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n <value name="TO">\n <shadow type="math_number">\n <field name="NUM">10</field>\n </shadow>\n </value>\n <value name="BY">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n </block>', 1631 + type: 'controls_for' 1632 + }, 1633 + { 1634 + kind: 'BLOCK', 1635 + blockxml: '<block type="controls_forEach"></block>', 1636 + type: 'controls_forEach' 1637 + }, 1638 + { 1639 + kind: 'BLOCK', 1640 + blockxml: '<block type="controls_flow_statements"></block>', 1641 + type: 'controls_flow_statements' 1642 + } 1643 + ] 1644 + }, 1645 + { 1646 + kind: 'CATEGORY', 1647 + name: 'Math', 1648 + colour: '230', 1649 + contents: [ 1650 + { 1651 + kind: 'BLOCK', 1652 + blockxml: '<block type="math_number"></block>', 1653 + type: 'math_number' 1654 + }, 1655 + { 1656 + kind: 'BLOCK', 1657 + blockxml: 1658 + '<block type="math_arithmetic">\n <value name="A">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n <value name="B">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n </block>', 1659 + type: 'math_arithmetic' 1660 + }, 1661 + { 1662 + kind: 'BLOCK', 1663 + blockxml: 1664 + '<block type="math_single">\n <value name="NUM">\n <shadow type="math_number">\n <field name="NUM">9</field>\n </shadow>\n </value>\n </block>', 1665 + type: 'math_single' 1666 + }, 1667 + { 1668 + kind: 'BLOCK', 1669 + blockxml: 1670 + '<block type="math_trig">\n <value name="NUM">\n <shadow type="math_number">\n <field name="NUM">45</field>\n </shadow>\n </value>\n </block>', 1671 + type: 'math_trig' 1672 + }, 1673 + { 1674 + kind: 'BLOCK', 1675 + blockxml: '<block type="math_constant"></block>', 1676 + type: 'math_constant' 1677 + }, 1678 + { 1679 + kind: 'BLOCK', 1680 + blockxml: 1681 + '<block type="math_number_property">\n <value name="NUMBER_TO_CHECK">\n <shadow type="math_number">\n <field name="NUM">0</field>\n </shadow>\n </value>\n </block>', 1682 + type: 'math_number_property' 1683 + }, 1684 + { 1685 + kind: 'BLOCK', 1686 + blockxml: 1687 + '<block type="math_change">\n <value name="DELTA">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n </block>', 1688 + type: 'math_change' 1689 + }, 1690 + { 1691 + kind: 'BLOCK', 1692 + blockxml: 1693 + '<block type="math_round">\n <value name="NUM">\n <shadow type="math_number">\n <field name="NUM">3.1</field>\n </shadow>\n </value>\n </block>', 1694 + type: 'math_round' 1695 + }, 1696 + { 1697 + kind: 'BLOCK', 1698 + blockxml: '<block type="math_on_list"></block>', 1699 + type: 'math_on_list' 1700 + }, 1701 + { 1702 + kind: 'BLOCK', 1703 + blockxml: 1704 + '<block type="math_modulo">\n <value name="DIVIDEND">\n <shadow type="math_number">\n <field name="NUM">64</field>\n </shadow>\n </value>\n <value name="DIVISOR">\n <shadow type="math_number">\n <field name="NUM">10</field>\n </shadow>\n </value>\n </block>', 1705 + type: 'math_modulo' 1706 + }, 1707 + { 1708 + kind: 'BLOCK', 1709 + blockxml: 1710 + '<block type="math_constrain">\n <value name="VALUE">\n <shadow type="math_number">\n <field name="NUM">50</field>\n </shadow>\n </value>\n <value name="LOW">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n <value name="HIGH">\n <shadow type="math_number">\n <field name="NUM">100</field>\n </shadow>\n </value>\n </block>', 1711 + type: 'math_constrain' 1712 + }, 1713 + { 1714 + kind: 'BLOCK', 1715 + blockxml: 1716 + '<block type="math_random_int">\n <value name="FROM">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n <value name="TO">\n <shadow type="math_number">\n <field name="NUM">100</field>\n </shadow>\n </value>\n </block>', 1717 + type: 'math_random_int' 1718 + }, 1719 + { 1720 + kind: 'BLOCK', 1721 + blockxml: '<block type="math_random_float"></block>', 1722 + type: 'math_random_float' 1723 + } 1724 + ] 1725 + }, 1726 + { 1727 + kind: 'CATEGORY', 1728 + name: 'Text', 1729 + colour: '160', 1730 + contents: [ 1731 + { 1732 + kind: 'BLOCK', 1733 + blockxml: '<block type="text"></block>', 1734 + type: 'text' 1735 + }, 1736 + { 1737 + kind: 'BLOCK', 1738 + blockxml: '<block type="text_join"></block>', 1739 + type: 'text_join' 1740 + }, 1741 + { 1742 + kind: 'BLOCK', 1743 + blockxml: 1744 + '<block type="text_append">\n <value name="TEXT">\n <shadow type="text"></shadow>\n </value>\n </block>', 1745 + type: 'text_append' 1746 + }, 1747 + { 1748 + kind: 'BLOCK', 1749 + blockxml: 1750 + '<block type="text_length">\n <value name="VALUE">\n <shadow type="text">\n <field name="TEXT">abc</field>\n </shadow>\n </value>\n </block>', 1751 + type: 'text_length' 1752 + }, 1753 + { 1754 + kind: 'BLOCK', 1755 + blockxml: 1756 + '<block type="text_isEmpty">\n <value name="VALUE">\n <shadow type="text">\n <field name="TEXT"></field>\n </shadow>\n </value>\n </block>', 1757 + type: 'text_isEmpty' 1758 + }, 1759 + { 1760 + kind: 'BLOCK', 1761 + blockxml: 1762 + '<block type="text_indexOf">\n <value name="VALUE">\n <block type="variables_get">\n <field name="VAR">text</field>\n </block>\n </value>\n <value name="FIND">\n <shadow type="text">\n <field name="TEXT">abc</field>\n </shadow>\n </value>\n </block>', 1763 + type: 'text_indexOf' 1764 + }, 1765 + { 1766 + kind: 'BLOCK', 1767 + blockxml: 1768 + '<block type="text_charAt">\n <value name="VALUE">\n <block type="variables_get">\n <field name="VAR">text</field>\n </block>\n </value>\n </block>', 1769 + type: 'text_charAt' 1770 + }, 1771 + { 1772 + kind: 'BLOCK', 1773 + blockxml: 1774 + '<block type="text_getSubstring">\n <value name="STRING">\n <block type="variables_get">\n <field name="VAR">text</field>\n </block>\n </value>\n </block>', 1775 + type: 'text_getSubstring' 1776 + }, 1777 + { 1778 + kind: 'BLOCK', 1779 + blockxml: 1780 + '<block type="text_changeCase">\n <value name="TEXT">\n <shadow type="text">\n <field name="TEXT">abc</field>\n </shadow>\n </value>\n </block>', 1781 + type: 'text_changeCase' 1782 + }, 1783 + { 1784 + kind: 'BLOCK', 1785 + blockxml: 1786 + '<block type="text_trim">\n <value name="TEXT">\n <shadow type="text">\n <field name="TEXT">abc</field>\n </shadow>\n </value>\n </block>', 1787 + type: 'text_trim' 1788 + }, 1789 + { 1790 + kind: 'BLOCK', 1791 + blockxml: 1792 + '<block type="text_print">\n <value name="TEXT">\n <shadow type="text">\n <field name="TEXT">abc</field>\n </shadow>\n </value>\n </block>', 1793 + type: 'text_print' 1794 + }, 1795 + { 1796 + kind: 'BLOCK', 1797 + blockxml: 1798 + '<block type="text_prompt_ext">\n <value name="TEXT">\n <shadow type="text">\n <field name="TEXT">abc</field>\n </shadow>\n </value>\n </block>', 1799 + type: 'text_prompt_ext' 1800 + } 1801 + ] 1802 + }, 1803 + { 1804 + kind: 'CATEGORY', 1805 + name: 'Lists', 1806 + colour: '260', 1807 + contents: [ 1808 + { 1809 + kind: 'BLOCK', 1810 + blockxml: 1811 + '<block type="lists_create_with">\n <mutation items="0"></mutation>\n </block>', 1812 + type: 'lists_create_with' 1813 + }, 1814 + { 1815 + kind: 'BLOCK', 1816 + blockxml: '<block type="lists_create_with"></block>', 1817 + type: 'lists_create_with' 1818 + }, 1819 + { 1820 + kind: 'BLOCK', 1821 + blockxml: 1822 + '<block type="lists_repeat">\n <value name="NUM">\n <shadow type="math_number">\n <field name="NUM">5</field>\n </shadow>\n </value>\n </block>', 1823 + type: 'lists_repeat' 1824 + }, 1825 + { 1826 + kind: 'BLOCK', 1827 + blockxml: '<block type="lists_length"></block>', 1828 + type: 'lists_length' 1829 + }, 1830 + { 1831 + kind: 'BLOCK', 1832 + blockxml: '<block type="lists_isEmpty"></block>', 1833 + type: 'lists_isEmpty' 1834 + }, 1835 + { 1836 + kind: 'BLOCK', 1837 + blockxml: 1838 + '<block type="lists_indexOf">\n <value name="VALUE">\n <block type="variables_get">\n <field name="VAR">list</field>\n </block>\n </value>\n </block>', 1839 + type: 'lists_indexOf' 1840 + }, 1841 + { 1842 + kind: 'BLOCK', 1843 + blockxml: 1844 + '<block type="lists_getIndex">\n <value name="VALUE">\n <block type="variables_get">\n <field name="VAR">list</field>\n </block>\n </value>\n </block>', 1845 + type: 'lists_getIndex' 1846 + }, 1847 + { 1848 + kind: 'BLOCK', 1849 + blockxml: 1850 + '<block type="lists_setIndex">\n <value name="LIST">\n <block type="variables_get">\n <field name="VAR">list</field>\n </block>\n </value>\n </block>', 1851 + type: 'lists_setIndex' 1852 + }, 1853 + { 1854 + kind: 'BLOCK', 1855 + blockxml: 1856 + '<block type="lists_getSublist">\n <value name="LIST">\n <block type="variables_get">\n <field name="VAR">list</field>\n </block>\n </value>\n </block>', 1857 + type: 'lists_getSublist' 1858 + }, 1859 + { 1860 + kind: 'BLOCK', 1861 + blockxml: 1862 + '<block type="lists_split">\n <value name="DELIM">\n <shadow type="text">\n <field name="TEXT">,</field>\n </shadow>\n </value>\n </block>', 1863 + type: 'lists_split' 1864 + }, 1865 + { 1866 + kind: 'BLOCK', 1867 + blockxml: '<block type="lists_sort"></block>', 1868 + type: 'lists_sort' 1869 + } 1870 + ] 1871 + }, 1872 + { 1873 + kind: 'CATEGORY', 1874 + name: 'Color', 1875 + colour: '20', 1876 + contents: [ 1877 + { 1878 + kind: 'BLOCK', 1879 + blockxml: '<block type="colour_picker"></block>', 1880 + type: 'colour_picker' 1881 + }, 1882 + { 1883 + kind: 'BLOCK', 1884 + blockxml: '<block type="colour_random"></block>', 1885 + type: 'colour_random' 1886 + }, 1887 + { 1888 + kind: 'BLOCK', 1889 + blockxml: 1890 + '<block type="colour_rgb">\n <value name="RED">\n <shadow type="math_number">\n <field name="NUM">100</field>\n </shadow>\n </value>\n <value name="GREEN">\n <shadow type="math_number">\n <field name="NUM">50</field>\n </shadow>\n </value>\n <value name="BLUE">\n <shadow type="math_number">\n <field name="NUM">0</field>\n </shadow>\n </value>\n </block>', 1891 + type: 'colour_rgb' 1892 + }, 1893 + { 1894 + kind: 'BLOCK', 1895 + blockxml: 1896 + '<block type="colour_blend">\n <value name="COLOUR1">\n <shadow type="colour_picker">\n <field name="COLOUR">#ff0000</field>\n </shadow>\n </value>\n <value name="COLOUR2">\n <shadow type="colour_picker">\n <field name="COLOUR">#3333ff</field>\n </shadow>\n </value>\n <value name="RATIO">\n <shadow type="math_number">\n <field name="NUM">0.5</field>\n </shadow>\n </value>\n </block>', 1897 + type: 'colour_blend' 1898 + } 1899 + ] 1900 + }, 1901 + { 1902 + kind: 'SEP' 1903 + }, 1904 + { 1905 + kind: 'CATEGORY', 1906 + colour: '330', 1907 + custom: 'VARIABLE', 1908 + name: 'Variables' 1909 + }, 1910 + { 1911 + kind: 'CATEGORY', 1912 + colour: '290', 1913 + custom: 'PROCEDURE', 1914 + name: 'Functions' 1915 + }, 1916 + { 1917 + kind: 'SEP' 1918 + }, 1919 + { 1920 + kind: 'CATEGORY', 1921 + colour: '210', 1922 + name: 'Niryo', 1923 + contents: [ 1924 + { 1925 + kind: 'BLOCK', 1926 + type: 'niryo_one_move_joints' 1927 + } 1928 + ] 1929 + } 1930 + ] 1931 + }; 1932 + 1933 + const BlocklyNiryo = { 1934 + Blocks: Blockly.Blocks, 1935 + Generator: Blockly.Python, 1936 + Toolbox: TOOLBOX 1937 + }; 1938 + 1939 + export default BlocklyNiryo;
+2 -1
src/toolbar/index.ts
··· 1 - export * from './selector'; 1 + export * from './toolbox'; 2 + export * from './generator'; 2 3 export * from './utils';
src/toolbar/selector.tsx src/toolbar/generator.tsx
+45
src/toolbar/toolbox.tsx
··· 1 + import { ToolbarButtonComponent } from '@jupyterlab/apputils'; 2 + import { HTMLSelect } from '@jupyterlab/ui-components'; 3 + 4 + import React from 'react'; 5 + 6 + import { BlocklyManager } from './../manager'; 7 + import { BlocklyButton } from './utils'; 8 + 9 + export namespace SelectToolbox { 10 + export interface IOptions extends ToolbarButtonComponent.IProps { 11 + manager: BlocklyManager; 12 + } 13 + } 14 + 15 + export class SelectToolbox extends BlocklyButton { 16 + private _manager: BlocklyManager; 17 + 18 + constructor(props: SelectToolbox.IOptions) { 19 + super(props); 20 + this._manager = props.manager; 21 + this._manager.changed.connect(this.update, this); 22 + } 23 + 24 + dispose(): void { 25 + super.dispose(); 26 + this._manager.changed.disconnect(this.update, this); 27 + } 28 + 29 + private handleChange = ( 30 + event: React.ChangeEvent<HTMLSelectElement> 31 + ): void => { 32 + this._manager.setToolbox(event.target.value); 33 + this.update(); 34 + }; 35 + 36 + render(): JSX.Element { 37 + return ( 38 + <HTMLSelect 39 + onChange={this.handleChange} 40 + value={this._manager.getToolbox()} 41 + options={this._manager.listToolboxes()} 42 + /> 43 + ); 44 + } 45 + }
+16 -3
src/widget.ts
··· 11 11 12 12 import { BlocklyLayout } from './layout'; 13 13 import { BlocklyManager } from './manager'; 14 - import { BlocklyButton, SelectGenerator, Spacer } from './toolbar'; 14 + import { 15 + BlocklyButton, 16 + SelectGenerator, 17 + SelectToolbox, 18 + Spacer 19 + } from './toolbar'; 15 20 16 21 /** 17 22 * DocumentWidget: widget that represents the view or editor for a file type. ··· 35 40 this.toolbar.addItem('run', button); 36 41 this.toolbar.addItem('spacer', new Spacer()); 37 42 this.toolbar.addItem( 38 - 'select', 43 + 'toolbox', 44 + new SelectToolbox({ 45 + label: 'Toolbox', 46 + tooltip: 'Select tollbox', 47 + manager: options.manager 48 + }) 49 + ); 50 + this.toolbar.addItem( 51 + 'generator', 39 52 new SelectGenerator({ 40 - label: 'Select', 53 + label: 'Kernel', 41 54 tooltip: 'Select kernel', 42 55 manager: options.manager 43 56 })
+2 -1
tsconfig.json
··· 2 2 "compilerOptions": { 3 3 "allowSyntheticDefaultImports": true, 4 4 "composite": true, 5 + "allowJs": true, 5 6 "declaration": true, 6 7 "esModuleInterop": true, 7 8 "incremental": true, ··· 17 18 "target": "es2017", 18 19 "types": [] 19 20 }, 20 - "include": ["src/**/*.ts", "src/**/*.tsx", "style/icons"], 21 + "include": ["src/**/*.ts", "src/**/*.js", "src/**/*.tsx", "style/icons"], 21 22 "exclude": ["node_modules"] 22 23 }