def walk_module(module, parent, ancestry): modules = netlist['modules'] cell_parent = QTreeWidgetItem(parent, ['cells']) cell_parent.full_name = ancestry for k, cell in module['cells'].items(): cell_type = cell['type'] cell['name'] = k disp_name = k + ' : ' + cell_type cell_item = QTreeWidgetItem(cell_parent, [disp_name]) cell_item.model = cell cell_item.full_name = ancestry + '/' + k if cell_type in modules: walk_module(modules[cell_type], cell_item, cell_item.full_name) nets_parent = QTreeWidgetItem(parent, ['nets']) nets_parent.full_name = ancestry for k, net in module['netnames'].items(): net_item = QTreeWidgetItem(nets_parent, [k]) net_item.model = net net_item.full_name = ancestry + '/' + k net['name'] = k
def update_hierarchy_tree(fname): global netlist with open(fname) as f: netlist = json.load(f) modules = netlist['modules'] top_module = list(modules.items())[0][0] for k, v in modules.items(): attrs = v.get('attributes', {}) if 'top' in attrs: top_module = k window.treeWidget.clear() root_item = QTreeWidgetItem(window.treeWidget) root_item.setText(0, top_module) root_item.full_name = top_module root_item.model = modules[top_module] walk_module(modules[top_module], root_item, top_module) window.treeWidget.expandAll()