Fix macro not executing correctly on first run after save
The commands list was stored as a shallow copy, meaning the individual command dicts were shared references with the CommandBuilder widget. When the dialog closed, these shared objects could be affected. Fix: Use copy.deepcopy() when storing commands in add_macro() and update_macro() to ensure the macro manager has its own independent copy of all command data. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# Macro management and execution with command sequence support
|
||||
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
import uuid
|
||||
@@ -163,11 +164,11 @@ class MacroManager:
|
||||
# Process image if provided
|
||||
image_path_reference = self._process_image(image_path) if image_path else ""
|
||||
|
||||
# Create macro data
|
||||
# Create macro data (deep copy commands to avoid reference issues)
|
||||
macro_data = {
|
||||
"name": name,
|
||||
"type": "sequence",
|
||||
"commands": commands,
|
||||
"commands": copy.deepcopy(commands),
|
||||
"category": category,
|
||||
"image_path": image_path_reference,
|
||||
"last_used": 0
|
||||
@@ -197,11 +198,11 @@ class MacroManager:
|
||||
else:
|
||||
image_path_reference = macro.get("image_path", "")
|
||||
|
||||
# Update macro data
|
||||
# Update macro data (deep copy commands to avoid reference issues)
|
||||
self.macros[macro_id] = {
|
||||
"name": name,
|
||||
"type": "sequence",
|
||||
"commands": commands,
|
||||
"commands": copy.deepcopy(commands),
|
||||
"category": category,
|
||||
"image_path": image_path_reference,
|
||||
"last_used": macro.get("last_used", 0)
|
||||
|
||||
Reference in New Issue
Block a user