Skip to content

Commit 4d5f7e1

Browse files
authored
Merge pull request #1 from DenisaCG/blocks_metadata
added top level initialization
2 parents 2392702 + 8206f3f commit 4d5f7e1

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/niryo_one_python_generators.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -880,18 +880,6 @@ Blockly.Blocks['niryo_one_conveyor_stop'] = {
880880
* Generators
881881
*/
882882

883-
const connexion = `
884-
from pyniryo import *
885-
886-
class niryo_connect():
887-
def __init__(self, ip):
888-
self.n = NiryoRobot(ip)
889-
def __enter__(self):
890-
return self.n
891-
def __exit__(self):
892-
self.n.close_connection()
893-
`;
894-
895883
Blockly.Python['niryo_one_connect'] = function (block) {
896884
var ip_0 = block.getFieldValue('ip_0');
897885
var ip_1 = block.getFieldValue('ip_1');
@@ -901,10 +889,22 @@ Blockly.Python['niryo_one_connect'] = function (block) {
901889
let branch = Blockly.Python.statementToCode(block, 'DO');
902890
var ip = ip_0 + '.' + ip_1 + '.' + ip_2 + '.' + ip_3;
903891

904-
var code = connexion + '\nwith niryo_connect("' + ip + '") as n:\n' + branch;
892+
var code = '\nwith niryo_connect("' + ip + '") as n:\n' + branch;
905893
return code;
906894
};
907895

896+
Blockly.Blocks['niryo_one_connect'].toplevel_init = `
897+
from pyniryo import *
898+
899+
class niryo_connect():
900+
def __init__(self, ip):
901+
self.n = NiryoRobot(ip)
902+
def __enter__(self):
903+
return self.n
904+
def __exit__(self):
905+
self.n.close_connection()
906+
`;
907+
908908
Blockly.Python['niryo_one_move_joints'] = function (block) {
909909
var number_joints_1 = block.getFieldValue('JOINTS_1');
910910
var number_joints_2 = block.getFieldValue('JOINTS_2');

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
resolved "https://registry.yarnpkg.com/@juggle/resize-observer/-/resize-observer-3.3.1.tgz#b50a781709c81e10701004214340f25475a171a0"
180180
integrity sha512-zMM9Ds+SawiUkakS7y94Ymqx+S0ORzpG3frZirN3l+UlXUmSUR7hF4wxCVqW+ei94JzV5kt0uXBcoOEAuiydrw==
181181

182-
"@jupyterlab/application@^3.3", "@jupyterlab/application@^3.4":
182+
"@jupyterlab/application@^3.4":
183183
version "3.4.3"
184184
resolved "https://registry.yarnpkg.com/@jupyterlab/application/-/application-3.4.3.tgz#acaecafbce1be71776ceee11203b9fb0a02e27d8"
185185
integrity sha512-JZy/4yB23N9o0gJFL8L219N7cWhUgulBECa+esN8K/i3TVoG0m/obacLBJrmwdgmQKAgyJ2Vfo1tyhW3UHvlFw==

0 commit comments

Comments
 (0)