Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.
1 to 6 of 6
Is it possible to access the functionality of File | Save via script? Namely, I'd like to implement an auto-save feature, prior to running a simulation based on the layout. The desired operation is that if the user hasn't saved the file, it would prompt for a path / filename. If it has already previously been saved, it would re-save. So exactly what the File | Save does. I found in the manual you have functionality to save the layout to a file, but that requires the path to be specified. But how to get the built-in dialog which prompts for filename, GDS details, etc, to pop up?
p.s. reference: https://github.com/lukasc-ubc/SiEPIC_EBeam_PDK/issues/141
The "File/Save" function can simply be triggered with
(the cm_... functions are the ones that are tied to the menus, so by calling them you do exactly when the corresponding menu entry does).
This cm_save function will save the layout from the active tab. If the layout wasn't saved before, it will prompt for a file name. If however, multiple layouts are loaded into the same tab, it will ask for confirmation what layouts to save. cm_save_all will emulate File/Save All, if you want all files to be saved.
One thing missing is that if the user presses escape, this function doesn't return if the file was saved. But that can be checked by:
layout_filename = pya.Application.instance().main_window().current_view().active_cellview().filename()
if len(layout_filename) == 0:
raise Exception("Please save your layout before running the simulation")
Ah .. right. The "cm_..." functions are stupid and don't report status or similar. They are slots too, so return values are not feasible. Errors will also not become visible to the code by the way. Only a message box will be shown.
You can basically emulate the "cm_save_all" function with low-level calls, but that's more than a single line of code. You code is a valid and simple workaround.
Is there any way to check if a layout hasn't been saved? i.e., when you exit KLayout, it knows if it has been modified or not. I couldn't find such a flag. The closest I could find was checking the undo transactions. If there are none, I assume the file hasn't been modified. But I don't think this is what you use...
Reason I ask is because I don't want to save a file unnecessarily, since it changes the file's date stamp even though no edits were done.
you're right. This feature is basically missing. Internally that's the "is_dirty" flag. It should be straightforward to implement. I have filed an issue here: https://github.com/klayoutmatthias/klayout/issues/7.