From 05392ef5e9868c1591fd2982c45a4ef1a57aeedc Mon Sep 17 00:00:00 2001 From: mistangl Date: Thu, 7 Mar 2024 23:56:33 +0100 Subject: [PATCH] Fix des Baumviews. ChildIds wurden nicht aus dem Pool genommen --- lib/CreoMigrateGui.py | 2 +- lib/gui.py | 51 ++++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/lib/CreoMigrateGui.py b/lib/CreoMigrateGui.py index 99d85de..b805815 100644 --- a/lib/CreoMigrateGui.py +++ b/lib/CreoMigrateGui.py @@ -121,7 +121,7 @@ if __name__ == '__main__': model = CadItem() if args.demo: model.from_json(json.loads(demo_data)) - build_gui(model, configs) + build_gui(model, configs, "400102196", True) elif args.sivasid: sivasid = args.sivasid.strip() diff --git a/lib/gui.py b/lib/gui.py index 7844000..95a14ca 100644 --- a/lib/gui.py +++ b/lib/gui.py @@ -87,43 +87,40 @@ class TreeView(): return False def create(self, parent_children_mapping, red_ids): - # adding data of first column after root pool = dict() for parent, children in parent_children_mapping.items(): - parent_text = parent - # parent erzeugen, falls es diese nicht schon gibt - if parent_text not in pool: - parent_id = self.tree.insert('', tk.END, text=parent_text, open=True) - pool[parent_text] = parent_id + # parent erzeugen, falls es diese nicht schon gibt (check der pool ids) + if parent not in pool: + if parent not in red_ids: rowtags = ('good') + else: rowtags = ('missing') + + parent_id = self.tree.insert('', tk.END, text=parent, tags=rowtags, open=True) + pool[parent] = parent_id else: - parent_id = pool[parent_text] - + parent_id = pool[parent] + for child in children: - child_text = child - if child_text not in red_ids: rowtags = ('good') - else: rowtags = ('missing') - if self._has_childs(child_text, parent_children_mapping) == True: + if child not in red_ids: rowtags = ('good') + else: rowtags = ('missing') + + if self._has_childs(child, parent_children_mapping) == True: # wenn das Objekt ein Kind hat, könnte es bereits erzeugt worden sein - if child_text not in pool: - child_id = self.tree.insert('', tk.END, text=child_text, tags=rowtags, open=True) - pool[child_text] = child_id - self.tree.move(child_id, parent_id, 0) + if child not in pool: + child_id = self.tree.insert('', tk.END, text=child, tags=rowtags, open=True) + pool[child] = child_id + else: + child_id = pool[child] else: - # die Blätter des Baumes kann man bedenkenlos bauen - child_id = self.tree.insert('', tk.END, text=child_text, tags=rowtags, open=True) - self.tree.move(child_id, parent_id, 0) - pool[child_text] = child_id - - - - # # einmal über alles gehen und alle keys an die richtige Stelle schieben - # for parent,children in parent_children_mapping.items(): - # for child_id in children: - # self.tree.move(child_id, parent, 0) + # die Blätter des Baumes kann man bedenkenlos immer bauen. Diese können redundante Texte haben. + child_id = self.tree.insert('', tk.END, text=child, tags=rowtags, open=True) + pool[child] = child_id + self.tree.move(child_id, parent_id, 'end') # https://www.askpython.com/python-modules/tkinter/tkinter-colors #self.tree.tag_configure('good', background='LawnGreen') self.tree.tag_configure('good', background='white') + self.tree.tag_configure('yellow', background='yellow') + self.tree.tag_configure('orange', background='orange') self.tree.tag_configure('missing', background='red') def data_from_model(self):