From 403fe1be4c2d0a48bb6b70ec853da0d736b8b931 Mon Sep 17 00:00:00 2001 From: MrTeferi Date: Sun, 1 Oct 2023 18:03:49 -0500 Subject: [PATCH] refactor(main): Group render queue by template PSD to prevent unnecessary document cycling and improve batch render time --- main.py | 16 +++++++--------- src/core.py | 2 +- src/templates/_core.py | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 2705983c..1e20bc31 100644 --- a/main.py +++ b/main.py @@ -388,7 +388,7 @@ def render_all(self, files: Optional[list[str]] = None) -> None: layouts: dict = {} for c in cards: layouts.setdefault( - 'failed' if isinstance(c, str) else c.card_class, [] + 'failed' if isinstance(c, str) else temps[c.card_class]['template_path'], [] ).append(c) # Did any cards fail to find? @@ -408,13 +408,11 @@ def render_all(self, files: Optional[list[str]] = None) -> None: console.update() # Render each card type as a different batch - for card_type, cards in layouts.items(): - # The template we'll use for this type - template = temps[card_type].copy() - template['loaded_class'] = get_template_class(template) - for card in cards: - # Start render thread - if not self.start_render(template, card): + for _, cards in layouts.items(): + for c in cards: + # Initialize the template module if needed, start a render thread + temps[c.card_class].setdefault('loaded_class', get_template_class(temps[c.card_class])) + if not self.start_render(temps[c.card_class], c): return # Card complete self.reset() @@ -484,7 +482,7 @@ def test_all(self, deep: bool = False) -> None: console.update(layout) return # Grab the template class and start the render thread - layout.filename = osp.join(con.cwd, "src/img/test.png") + layout.filename = osp.join(con.path_img, "test.jpg") template['loaded_class'] = get_template_class(template) if not self.start_render(template, layout): failures.append(card[0]) diff --git a/src/core.py b/src/core.py index 84636e09..76e6f1d7 100644 --- a/src/core.py +++ b/src/core.py @@ -65,7 +65,7 @@ def get_templates() -> dict[str, list[TemplateDetails]]: "class_name": template['class'], "type": con.card_type_map_raw.get(card_type, 'Normal'), "config_path": osp.join(con.path_configs, f"{template['class']}.json"), - "preview_path": osp.join(con.path_img, f"{template['class']}.jpg"), + "preview_path": osp.join(con.path_img, f"previews/{template['class']}.jpg"), "template_path": osp.join(con.path_templates, template['file']), "plugin_name": None, "plugin_path": None, diff --git a/src/templates/_core.py b/src/templates/_core.py index cf264baa..4a552279 100644 --- a/src/templates/_core.py +++ b/src/templates/_core.py @@ -606,7 +606,7 @@ def load_artwork(self) -> None: """ # Check for fullart test image if cfg.test_mode and self.is_fullart: - self.layout.filename = osp.join(con.path_img, "test-fa.png") + self.layout.filename = osp.join(con.path_img, "test-fa.jpg") # Paste the file into the art self.active_layer = self.art_layer