Skip to content

Commit fa16a17

Browse files
committed
Adding parameters to distinguish different ways of executing "run_blockly-app"
1 parent 517f764 commit fa16a17

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

xarm/tools/blockly/_blockly_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __init__(self, xml_path):
2424
self._main_run_code_list = []
2525
self._is_main_run_code = True
2626
self._is_exec = False
27+
self._is_ide = False
2728

2829
self._listen_tgpio_digital = False
2930
self._listen_tgpio_analog = False
@@ -1116,7 +1117,7 @@ def _handle_python_code(self, block, indent=0, arg_map=None, **kwargs):
11161117
prev_is_empty = True
11171118
else:
11181119
prev_is_empty = False
1119-
if self._is_exec and code.strip():
1120+
if (self._is_exec or (not self._is_exec and not self._is_ide)) and code.strip():
11201121
code_indent = re.match('(\s*).*', code).group(1)
11211122
self._append_main_code(code_indent + 'if not self.is_alive:', indent + 2)
11221123
self._append_main_code(code_indent + 'return', indent + 3)

xarm/tools/blockly/_blockly_tool.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def codes(self):
2323
def to_python(self, path=None, arm=None, init=True, wait_seconds=1, mode=0, state=0, error_exit=True, stop_exit=True, **kwargs):
2424
if not self._is_converted:
2525
self._is_exec = kwargs.get('is_exec', False)
26+
self._is_ide = kwargs.get('is_ide', False)
2627
# highlight_callback: only use pack to run blockly in studio
2728
self._highlight_callback = kwargs.get('highlight_callback', None)
2829
# axis_type: Obtain the type of mechanical arm axis for end leveling use
@@ -451,9 +452,9 @@ def __define_check_code_func(self):
451452
self._append_main_init_code(' return self.is_alive\n')
452453

453454
def _init_main_codes(self, arm=None):
454-
# exec can not run main function, if run in exec(), the parameter is_exec must set True
455+
# exec can not run main function, if run in exec(), the parameter is_ide must set False
455456
self._append_main_code('\n', indent=-1)
456-
if not self._is_exec:
457+
if self._is_ide:
457458
self._append_main_code('if __name__ == \'__main__\':', indent=-1)
458459
indent = 0
459460
else:

xarm/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.14.2'
1+
__version__ = '1.14.3'

xarm/x3/xarm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ def run_blockly_app(self, path, **kwargs):
14611461
if not os.path.exists(path):
14621462
raise FileNotFoundError('{} is not found'.format(path))
14631463
blockly_tool = BlocklyTool(path)
1464-
succeed = blockly_tool.to_python(arm=self._api_instance, is_exec=True, **kwargs)
1464+
succeed = blockly_tool.to_python(arm=self._api_instance, **kwargs)
14651465
if succeed:
14661466
times = kwargs.get('times', 1)
14671467
highlight_callback = kwargs.get('highlight_callback', None)

0 commit comments

Comments
 (0)