Skip to content

Commit 0d39249

Browse files
committed
Fix blockly to python: print with color in blockly
1 parent 561ef0a commit 0d39249

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

xarm/tools/blockly/_blockly_handler.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,23 +271,38 @@ def _handle_app_studio_traj(self, block, indent=0, arg_map=None):
271271

272272
def _handle_tool_message(self, block, indent=0, arg_map=None):
273273
fields = self._get_nodes('field', block)
274+
color = json.dumps(fields[0].text, ensure_ascii=False) if len(fields) > 1 else 'white'
274275
msg = json.dumps(fields[1].text if fields[-1].text is not None else '', ensure_ascii=False)
275-
self._append_main_code('print({})'.format(msg), indent + 2)
276+
if self._highlight_callback is not None:
277+
self._append_main_code('print({}, {})'.format(msg, color), indent + 2)
278+
else:
279+
self._append_main_code('print({})'.format(msg), indent + 2)
276280

277281
def _handle_tool_console(self, block, indent=0, arg_map=None):
278282
fields = self._get_nodes('field', block)
283+
color = json.dumps(fields[0].text, ensure_ascii=False) if len(fields) > 1 else 'white'
279284
msg = json.dumps(fields[1].text if fields[-1].text is not None else '', ensure_ascii=False)
280-
self._append_main_code('print({})'.format(msg), indent + 2)
285+
if self._highlight_callback is not None:
286+
self._append_main_code('print({}, {})'.format(msg, color), indent + 2)
287+
else:
288+
self._append_main_code('print({})'.format(msg), indent + 2)
281289

282290
def _handle_tool_console_with_variable(self, block, indent=0, arg_map=None):
283291
fields = self._get_nodes('field', block)
292+
color = json.dumps(fields[0].text, ensure_ascii=False)
284293
msg = fields[1].text
285294
value = self._get_node('value', block)
286295
expression = self._get_condition_expression(value, arg_map=arg_map)
287296
if msg:
288-
self._append_main_code('print({}.format({}))'.format(json.dumps(msg+'{}', ensure_ascii=False), expression), indent + 2)
297+
if self._highlight_callback is not None:
298+
self._append_main_code('print({}.format({}), {})'.format(json.dumps(msg+'{}', ensure_ascii=False), expression, color), indent + 2)
299+
else:
300+
self._append_main_code('print({}.format({}))'.format(json.dumps(msg+'{}', ensure_ascii=False), expression), indent + 2)
289301
else:
290-
self._append_main_code('print(\'{{}}\'.format({}))'.format(expression), indent + 2)
302+
if self._highlight_callback is not None:
303+
self._append_main_code('print(\'{{}}\'.format({}), {})'.format(expression, color), indent + 2)
304+
else:
305+
self._append_main_code('print(\'{{}}\'.format({}))'.format(expression), indent + 2)
291306

292307
def _handle_wait(self, block, indent=0, arg_map=None):
293308
value = self._get_node('value', root=block)

xarm/x3/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,7 @@ def getset_tgpio_modbus_data(self, datas, min_res_len=0, ignore_log=False, host_
23352335
if not self.connected:
23362336
return APIState.NOT_CONNECTED, []
23372337
ret = self.arm_cmd.tgpio_set_modbus(datas, len(datas), host_id=host_id)
2338-
ret[0] = self._check_modbus_code(ret, min_res_len + 2)
2338+
ret[0] = self._check_modbus_code(ret, min_res_len + 2, host_id=host_id)
23392339
if not ignore_log:
23402340
self.log_api_info('API -> getset_tgpio_modbus_data -> code={}, response={}'.format(ret[0], ret[2:]), code=ret[0])
23412341
return ret[0], ret[2:]

0 commit comments

Comments
 (0)