From 715ec8dacf7045d2e31ee94209f824bc92bc9439 Mon Sep 17 00:00:00 2001 From: mitaa Date: Fri, 13 Sep 2024 07:04:27 +0200 Subject: [PATCH] Slight renamings for better clarity --- .gitignore | 1 + src/production_planner/core.py | 27 ++++++++++++++++----------- src/production_planner/datatable.py | 6 +++--- tests | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index d6fafde..e13d82f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ auxiliary/ *.html +*.stackdump # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/src/production_planner/core.py b/src/production_planner/core.py index e35a3d1..41094b3 100644 --- a/src/production_planner/core.py +++ b/src/production_planner/core.py @@ -628,12 +628,12 @@ def ingredient_constructor(loader, data): class SummaryNode(Node): def __init__(self, nodes): self.row_idx = 0 - super().__init__(SUMMARY_PRODUCER, self.update_recipe(nodes), is_dummy=True) + super().__init__(SUMMARY_PRODUCER, self.update_summary(nodes), is_dummy=True) def producer_reset(self): ... - def update_recipe(self, nodes: [Node]) -> Recipe: + def update_summary(self, nodes: [Node]) -> Recipe: # TODO: also handle power consumption power = 0 sums = {} @@ -665,12 +665,15 @@ def summary_constructor(loader, data): class NodeInstance: + # FIXME: this is shared between all instances but this must not be true for unrelated NodeTrees row_to_node_index = [] - session_modules = set() - def __init__(self, node:Node, children:[Self]=None, parent:[Self]=None, shown=True, expanded=True, row_idx=None, level=0): + def __init__(self, node: Node, children: [Self] = None, parent: [Self] = None, shown=True, expanded=True, row_idx=None, level=0): + self.tree_modules = set() + self.parent = parent self.node_main = node + if children is None: children = [] @@ -764,7 +767,7 @@ def get_nodes(self, level=0) -> [Self]: if isinstance(self.node_main, SummaryNode): # Note: the innermost nodes get their recipe updated before the outer nodes # because of the `get_nodes` calls above - self.node_main.update_recipe([cinstance.node_main for cinstance in self.node_children]) + self.node_main.update_summary([cinstance.node_main for cinstance in self.node_children]) if level < 2: NodeInstance.row_to_node_index += [self] * len(nodes) @@ -778,7 +781,7 @@ def update_summaries(self): if not isinstance(self.node_main, SummaryNode): return - self.node_main.update_recipe([cinstance.node_main for cinstance in self.node_children]) + self.node_main.update_summary([cinstance.node_main for cinstance in self.node_children]) def update_parents(self): for child in self.node_children: @@ -789,6 +792,7 @@ def set_module(self, module_file: ModuleFile): if not self.node_main.is_module: return + # FIXME: guard against recursive modules here.. if module_file: self.node_children.clear() tree = MODULE_PRODUCER.update_module(module_file) @@ -797,15 +801,16 @@ def set_module(self, module_file: ModuleFile): self.add_children([tree]) - if self.node_children: - self.node_main.energy_module = self.node_children[0].node_main.energy + if self.node_children: + # FIXME: sum with nested modules isn't always correct + self.node_main.energy_module = self.node_children[0].node_main.energy def collect_modules(self, level=0): if level == 0: - self.session_modules.clear() + self.tree_modules.clear() if self.node_main.is_module: - self.session_modules.add(self.node_main.recipe.name) + self.tree_modules.add(self.node_main.recipe.name) for child in self.node_children: child.collect_modules(level + 1) @@ -860,7 +865,7 @@ def reload_module(instance) -> str | bool | None: if instance.node_main.is_module: module = instance.node_main.recipe.name log(f"reloading module: {module}") - self.session_modules.add(module) + self.tree_modules.add(module) if module in module_stack: log("Error: Recursive Modules!") APP.notify(f"Error; Resursive Modules: ({'>'.join(module_stack)})", diff --git a/src/production_planner/datatable.py b/src/production_planner/datatable.py index 8f2249f..2b524d7 100644 --- a/src/production_planner/datatable.py +++ b/src/production_planner/datatable.py @@ -141,11 +141,11 @@ def save_file(subpath: Path) -> None: return self.nodetree.collect_modules() # TODO: create a test - if ModuleFile(subpath).id in self.nodetree.session_modules: + if ModuleFile(subpath).id in self.nodetree.tree_modules: self.notify(f"Saving to `{subpath}` would create recursive modules", severity="error", timeout=10) - self.notify(f"Modules included: {repr(self.nodetree.session_modules)}", + self.notify(f"Modules included: {repr(self.nodetree.tree_modules)}", severity="warning", timeout=10) return @@ -418,7 +418,7 @@ def update(self, selected: SelectionContext = None): node.update() is_summary = isinstance(node, SummaryNode) if is_summary: - node.update_recipe(inst.node_main for inst in node_instance.node_children) + node.update_summary(inst.node_main for inst in node_instance.node_children) row = [Column(node_instance) for Column in self.edit_columns] for ingredient in ingredients: diff --git a/tests b/tests index a94cfaf..90519f6 160000 --- a/tests +++ b/tests @@ -1 +1 @@ -Subproject commit a94cfaf22919779d0d52c5b21efa5e609d6d0ec3 +Subproject commit 90519f647a07ad3dcd28e6d7737051dce501c7a1