fix: keep print and re-apply selected template on preview switch
Switching the preview garment cleared the scene (print lost), and re-loading a print used the canvas's hard-coded centred default instead of the selected template. - template_panel: add apply_current() to re-emit the selected template for the current garment/print sizes and sync _current_state. - main_window: remember the current print path, restore it after a garment switch, and call apply_current() after garment/print changes so the selected template stays sticky. Fine-tuned items are unaffected. - Also feed template_applied into export_panel.set_transform to keep the single-export transform in sync. Docs: record the sticky-template rule (PRD 6.6). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+24
-10
@@ -50,6 +50,7 @@ class MainWindow(QMainWindow):
|
||||
# Fine-tune state: track which queue item is currently being edited
|
||||
self._active_queue_item = None
|
||||
self._loading_queue_item = False # suppress fine-tune marking during item load
|
||||
self._current_print_path = None # keep the print across garment switches
|
||||
|
||||
root = QWidget()
|
||||
root.setObjectName("root")
|
||||
@@ -277,11 +278,23 @@ class MainWindow(QMainWindow):
|
||||
self.template_panel.template_applied.connect(self.image_canvas.set_transform)
|
||||
self.template_panel.template_applied.connect(self.transform_panel.set_transform)
|
||||
self.template_panel.template_applied.connect(self.queue_panel.set_transform)
|
||||
self.template_panel.template_applied.connect(self.export_panel.set_transform)
|
||||
|
||||
# ── Export panel secondary buttons → template panel ────────────────
|
||||
self.export_panel.apply_as_template.connect(self.template_panel._save_as_template)
|
||||
self.export_panel.reset_to_template.connect(self.template_panel._reset_to_template)
|
||||
|
||||
def _load_print_preview(self, path):
|
||||
"""Load a print into the canvas and sync its native size to the template panel."""
|
||||
self.image_canvas.load_print(path)
|
||||
self.export_panel.set_print(path)
|
||||
try:
|
||||
from PIL import Image as _PilImage
|
||||
with _PilImage.open(path) as img:
|
||||
self.template_panel.set_print_size(img.width, img.height)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _on_garment_preview(self, asset):
|
||||
"""Load a garment from the asset list into the canvas for direct preview."""
|
||||
self._active_queue_item = None # leave queue mode
|
||||
@@ -298,23 +311,24 @@ class MainWindow(QMainWindow):
|
||||
self.template_panel.set_garment_size(img.width, img.height)
|
||||
except Exception:
|
||||
pass
|
||||
# load_garment clears the scene; restore the current print and re-lay it
|
||||
# out with the selected template (instead of the canvas default).
|
||||
if self._current_print_path:
|
||||
self._load_print_preview(self._current_print_path)
|
||||
self.template_panel.apply_current()
|
||||
|
||||
def _on_print_preview(self, asset):
|
||||
"""Load a print from the asset list into the canvas for direct preview."""
|
||||
self._active_queue_item = None
|
||||
if not asset:
|
||||
self._current_print_path = None
|
||||
self.export_panel.set_print(None)
|
||||
return
|
||||
path = str(asset.path)
|
||||
self.image_canvas.load_print(path)
|
||||
self.export_panel.set_print(path)
|
||||
# Tell template panel the print dimensions for aspect-aware fitting
|
||||
try:
|
||||
from PIL import Image as _PilImage
|
||||
with _PilImage.open(path) as img:
|
||||
self.template_panel.set_print_size(img.width, img.height)
|
||||
except Exception:
|
||||
pass
|
||||
self._current_print_path = str(asset.path)
|
||||
self._load_print_preview(self._current_print_path)
|
||||
# Apply the selected template so the print lands per the chosen layout,
|
||||
# not the canvas's hard-coded centred default.
|
||||
self.template_panel.apply_current()
|
||||
|
||||
def _on_queue_item_activated(self, item):
|
||||
"""Load a queue item into the canvas and arm fine-tune tracking."""
|
||||
|
||||
Reference in New Issue
Block a user