Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion grain.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<name>LibraryManagerPlugin</name>
<token/>
<hidden>false</hidden>
<version>0.23</version>
<version>0.24</version>
<api-version/>
<title>Library Manager Plugin</title>
<doc>Library manager for hierarchical layouts</doc>
Expand Down
94 changes: 50 additions & 44 deletions pymacros/library_manager_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,9 @@ def on_export_hierarchical_layout_for_tapeout(self):
traceback.print_exc()
caught_exception = e
finally:
if not succeeded and caught_exception is None: # cancellation
return

mbox = pya.QMessageBox()
mbox.setTextFormat(pya.Qt.RichText)
if succeeded:
mbox = pya.QMessageBox()
mbox.setTextFormat(pya.Qt.RichText)
mbox.setIcon(pya.QMessageBox.Information)
mbox.setWindowTitle('Export For Tapeout Success')
mbox.text = "Export for tapeout succeeded."
Expand All @@ -529,7 +526,9 @@ def on_export_hierarchical_layout_for_tapeout(self):
clicked = mbox.clickedButton()
if clicked == reveal_button:
FileSystemHelpers.reveal_in_file_manager(layout_path)
else:
elif caught_exception is None:
pass # cancellation
elif caught_exception is not None:
qmessagebox_critical('Export For Tapeout Error', 'Export for tapeout failed.',
f"Caught Exception: "\
f"<pre>{str(caught_exception)}</pre>"
Expand Down Expand Up @@ -619,17 +618,6 @@ def report_issues(issues: LibraryMapIssues) -> bool:

loading_issues = LibraryMapIssues()

for new_lib_def in changes.added_libs:
try:
lib = pya.Library()
lib.layout().read(new_lib_def.lib_path)
lib.register(new_lib_def.lib_name)
except Exception as e:
loading_issues.failed_libraries.append((new_lib_def, str(e)))

if not report_issues(loading_issues):
return

for old_lib_def, new_lib_def in changes.renamed_libs:
lib = pya.Library.library_by_name(old_lib_def.lib_name)
if 'rename' in dir(lib): # added in KLayout 0.30.5 API
Expand All @@ -638,27 +626,35 @@ def report_issues(issues: LibraryMapIssues) -> bool:
for old_lib_def, new_lib_def in changes.repathed_libs:
lib = pya.Library.library_by_name(new_lib_def.lib_name)
# NOTE: due to loading errors, it could be that the library does not yet exist
if lib is None:
lib = pya.Library()
lib.layout().read(new_lib_def.lib_path)
lib.register(new_lib_def.lib_name)
else:
lib.layout().clear()
lib.layout().read(new_lib_def.lib_path)
lib.refresh()
try:
self._load_or_reload_library(new_lib_def, loading_issues.failed_libraries)
except Exception as e:
loading_issues.failed_libraries.append((new_lib_def, str(e)))

for old_lib_def in changes.removed_libs:
lib = pya.Library.library_by_name(old_lib_def.lib_name)
if lib: # NOTE: due to loading errors, it could be that the library does not yet exist
if 'unregister' in dir(pya.Library): # added in KLayout 0.30.5 API
pya.Library.unregister(lib)
self._unregister_library_by_name(old_lib_def.lib_name)

for new_lib_def in changes.added_libs:
try:
self._load_or_reload_library(new_lib_def, loading_issues.failed_libraries)
except Exception as e:
loading_issues.failed_libraries.append((new_lib_def, str(e)))

if not report_issues(loading_issues):
return

if retry_block is not None:
retry_block()

def on_reload_cell_libraries(self):
if Debugging.DEBUG:
debug("LibraryManagerPluginFactory.on_reload_cell_libraries")

if 'library_from_file' not in dir(pya.Library): # added in KLayout 0.30.8 API
qmessagebox_critical('Error', 'Reload Cell Libraries failed',
f"Reloading cell libraries is not possible prior to <pre>KLayout v0.30.8.</pre> "\
f"For now, please restart KLayout for any library cell changes to propagate.")
return

try:
mw = pya.MainWindow.instance()
Expand All @@ -683,6 +679,27 @@ def report_success():
print("LibraryManagerPluginFactory.on_reload_cell_libraries caught an exception", e)
traceback.print_exc()

def _unregister_library_by_name(self, name: str):
lib = pya.Library.library_by_name(name)
if lib:
if 'unregister' in dir(pya.Library): # added in KLayout 0.30.5 API
pya.Library.unregister(lib)
else:
lib.delete()

def _load_or_reload_library(self,
lib_def: LibraryDefinition,
failed_list: List):
"""Register a new library or safely reload an existing one by name."""

# Unregister if necessary
self._unregister_library_by_name(lib_def.lib_name)

# Register library
lib = pya.Library.library_from_file(lib_def.lib_path, lib_def.lib_name)
if Debugging.DEBUG:
debug(f"Registered library '{lib_def.lib_name}'")

def reload_cell_libraries(self,
layout_file_set: LayoutFileSet,
config: LibraryMapConfig,
Expand All @@ -707,21 +724,10 @@ def handle_issues(issues: LibraryMapIssues) -> bool:
for lib_def in new_lib_defs:
if Debugging.DEBUG:
debug(f"Reload library {lib_def.lib_name} from path {lib_def.lib_path}")
lib = pya.Library.library_by_name(lib_def.lib_name)
if lib is None:
lib = pya.Library()
try:
lib.layout().read(lib_def.lib_path)
lib.register(lib_def.lib_name)
except Exception as e:
loading_issues.failed_libraries.append((lib_def, str(e)))
else:
try:
lib.layout().clear()
lib.layout().read(lib_def.lib_path)
lib.refresh()
except Exception as e:
loading_issues.failed_libraries.append((lib_def, str(e)))
try:
self._load_or_reload_library(lib_def, loading_issues.failed_libraries)
except Exception as e:
loading_issues.failed_libraries.append((lib_def, str(e)))
return True
elif consequence == LibraryMapIssueConsequence.CLOSE_LAYOUT:
mw = pya.MainWindow.instance()
Expand Down
2 changes: 1 addition & 1 deletion pymacros/library_map_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class LibraryMapChanges:
issues: LibraryMapIssues = field(default_factory=LibraryMapIssues)

@classmethod
def compare(self,
def compare(cls,
base_folder: Path,
old_config: LibraryMapConfig,
new_config: LibraryMapConfig) -> LibraryMapChanges:
Expand Down