setupEM 0.18.3__tar.gz → 0.18.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. {setupem-0.18.3/src/setupEM.egg-info → setupem-0.18.4}/PKG-INFO +7 -16
  2. {setupem-0.18.3 → setupem-0.18.4}/README_pypi.md +6 -15
  3. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/__init__.py +1 -1
  4. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/setup_common.py +131 -20
  5. {setupem-0.18.3 → setupem-0.18.4/src/setupEM.egg-info}/PKG-INFO +7 -16
  6. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM.egg-info/SOURCES.txt +1 -0
  7. {setupem-0.18.3 → setupem-0.18.4}/tests/test_cli_startup.py +1 -0
  8. {setupem-0.18.3 → setupem-0.18.4}/tests/test_config_update_gui.py +3 -0
  9. {setupem-0.18.3 → setupem-0.18.4}/tests/test_deembedded_view.py +2 -0
  10. {setupem-0.18.3 → setupem-0.18.4}/tests/test_export_no_gui.py +1 -0
  11. {setupem-0.18.3 → setupem-0.18.4}/tests/test_margin_per_side.py +1 -0
  12. {setupem-0.18.3 → setupem-0.18.4}/tests/test_piece_set.py +5 -0
  13. {setupem-0.18.3 → setupem-0.18.4}/tests/test_port_walls.py +1 -0
  14. {setupem-0.18.3 → setupem-0.18.4}/tests/test_return_applies.py +1 -0
  15. setupem-0.18.4/tests/test_save_current_file.py +119 -0
  16. {setupem-0.18.3 → setupem-0.18.4}/tests/test_script_writer.py +1 -0
  17. {setupem-0.18.3 → setupem-0.18.4}/tests/test_table_rows.py +1 -0
  18. {setupem-0.18.3 → setupem-0.18.4}/tests/test_thermal_powers.py +6 -0
  19. {setupem-0.18.3 → setupem-0.18.4}/tests/test_thermal_results.py +1 -0
  20. {setupem-0.18.3 → setupem-0.18.4}/LICENSE +0 -0
  21. {setupem-0.18.3 → setupem-0.18.4}/README.md +0 -0
  22. {setupem-0.18.3 → setupem-0.18.4}/pyproject.toml +0 -0
  23. {setupem-0.18.3 → setupem-0.18.4}/setup.cfg +0 -0
  24. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/__main__.py +0 -0
  25. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/cli_common.py +0 -0
  26. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/config_update.py +0 -0
  27. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/data/SG13CMOS5L_200um.xml +0 -0
  28. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/data/SG13G2_100um.xml +0 -0
  29. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/data/SG13G2_200um.xml +0 -0
  30. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/data/SG13G2_FEM_200um.xml +0 -0
  31. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/data/SG13G2_FEM_200um_passi3D.xml +0 -0
  32. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/data/SG13G2_nosub.xml +0 -0
  33. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/field_viewer.py +0 -0
  34. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/gds_hierarchy_scan.py +0 -0
  35. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/join_pieces.py +0 -0
  36. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/layout_preview.py +0 -0
  37. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/momentum_import.py +0 -0
  38. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/palace_results.py +0 -0
  39. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/piece_set.py +0 -0
  40. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/result_viewer.py +0 -0
  41. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/run_with_overrides.py +0 -0
  42. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/script_model.py +0 -0
  43. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/script_probe.py +0 -0
  44. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/script_writer.py +0 -0
  45. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/setupEM.py +0 -0
  46. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/setupThermal.py +0 -0
  47. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/simplify_gds.py +0 -0
  48. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/stackupEditor.py +0 -0
  49. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/stackup_writer.py +0 -0
  50. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM/thermal_results.py +0 -0
  51. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM.egg-info/dependency_links.txt +0 -0
  52. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM.egg-info/entry_points.txt +0 -0
  53. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM.egg-info/requires.txt +0 -0
  54. {setupem-0.18.3 → setupem-0.18.4}/src/setupEM.egg-info/top_level.txt +0 -0
  55. {setupem-0.18.3 → setupem-0.18.4}/tests/test_config_update.py +0 -0
  56. {setupem-0.18.3 → setupem-0.18.4}/tests/test_join_pieces.py +0 -0
  57. {setupem-0.18.3 → setupem-0.18.4}/tests/test_qt_platform_noise.py +0 -0
  58. {setupem-0.18.3 → setupem-0.18.4}/tests/test_run_with_overrides.py +0 -0
  59. {setupem-0.18.3 → setupem-0.18.4}/tests/test_script_model.py +0 -0
  60. {setupem-0.18.3 → setupem-0.18.4}/tests/test_script_probe.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: setupEM
3
- Version: 0.18.3
3
+ Version: 0.18.4
4
4
  Summary: Python tool for configuration of gds2palace workflow with GUI.
5
5
  Author-email: Volker Muehlhaus <volker@muehlhaus.com>
6
6
  License-Expression: GPL-3.0-or-later
@@ -40,6 +40,12 @@ https://github.com/VolkerMuehlhaus/setupEM
40
40
 
41
41
  ## Recent changes
42
42
 
43
+ # What's New - November 16, 2026 (setupEM 0.18.4)
44
+
45
+ **File > Save (Ctrl+S) saves the settings file you opened.** Opened from a `.simcfg` (e.g. the KLayout plug-in's export, with Open in setupEM), Ctrl+S did nothing: the action existed only for a script edited in place, and changes such as a port wall extension were lost without a question when setupEM was closed. Now:
46
+ - Ctrl+S saves into the `.simcfg` / `.tsimcfg` the model was opened from (the menu names it). Its other entries, e.g. the plug-in's link to the model script, are kept. A script edited in place and a piece of a split region are saved as before; a new model asks for a file name.
47
+ - Closing setupEM, opening another file or File > New asks "Save the changes to ...?" when the settings changed since the file was opened or saved.
48
+
43
49
  # What's New - November 15, 2026 (setupEM 0.18.3)
44
50
 
45
51
  Needs gds2palace 0.10.7 or newer (`pip install` updates it).
@@ -66,21 +72,6 @@ Needs gds2palace 0.10.7 or newer (`pip install` updates it).
66
72
  - A model script edited in place whose GDS file was taken from its folder on opening (the script had the other machine's path, e.g. `/mnt/pub/...` for `P:/...`) now gets that path when it is saved or the model is created; the Code tab shows it. Before, the GUI showed the new path and the script kept the old one, and the model was made from the old one.
67
73
  - On Linux, a path with a drive letter from Windows (`D:/...`) in a script or settings file is no longer taken as relative to the script's folder (`/mnt/.../D:/...`, "Load a GDSII file and XML stackup first"). A stackup that is not found, also not next to the script, is taken from the stackups that ship with gds2palace if one has that name; the log says so.
68
74
 
69
- # What's New - November 11, 2026 (setupEM 0.18.1)
70
-
71
- **Command line fixes** (from issue #52, use without a display):
72
- - `--help`, `--version` and a wrong argument of `setupEM`, `setupThermal`, `stackupEditor`, `resultViewer` and `fieldViewer` no longer need a display: the arguments are read before Qt starts. All five have `--version` now.
73
- - `setupEM -simcfg <file>` opens a settings file of an Elmer model in Elmer mode. It opened in Palace mode unless `--elmer` was given, also when started from the KLayout plug-in.
74
- - A `-simcfg`, `-gdsfile` or `-xmlfile` that does not exist, or a settings file of the other application, ends `setupEM` / `setupThermal` with a message on stderr and exit code 2 instead of an empty window. In the GUI, a settings file that is gone is reported as "File not found", not as "Unknown data format".
75
- - Loading a settings file no longer shows a "Loaded" box: the log says "Config loaded from ...", with a GDS or stackup file that was not found at its saved path and was taken from the settings file's folder instead.
76
- - Opening a `.simcfg` continues with the model script only when the file is linked to it, and asks only when the two have other settings (the question lists them). Create Model links: besides `<model>.simcfg` it writes the script's name (`"model_script"`) into the `.simcfg` the model was opened from, e.g. the KLayout plug-in's export, which keeps it on the next export. A script that only reads the same GDSII file is no longer taken for the model; the log names it. New options `--continue-with-script` and `--start-from-config` answer the question on the command line.
77
- - `fieldViewer --screenshot` needs no display and no `QT_QPA_PLATFORM=offscreen`.
78
- - `python -m setupEM.join_pieces` and `python -m setupEM.thermal_results` have `--help` and `--version`, write their errors to stderr, and a missing file is a message, not a traceback.
79
- - The modules without a GUI (`join_pieces`, `thermal_results`, `script_model`, ...) can be imported without loading Qt.
80
- - User guide: Model Fit starts snp2le with the result file loaded (the text said it has to be loaded by hand).
81
-
82
- **Split regions, fix:**a side of the region made a port wall in setupEM after the export (e.g. with via ports of the layout on the region's edge) was a plain PEC wall in every piece and in the full check model: the wall shorted those ports, and the joined result and the full model were both wrong, in the same way. The pieces' port walls on the region's edge are now found from the ports on the edge of each piece's layout; the full model has all of the region's port walls. Where the region has a port wall but a piece none of its ports, that stretch stays PEC and now moves outward with the region's port wall extension (a length; written as `settings['wall_extension']`, needs gds2palace 0.10.1), so that all pieces and the full model have the same box.
83
-
84
75
  Full history: [CHANGES.md](https://github.com/VolkerMuehlhaus/setupEM/blob/main/doc/CHANGES.md)
85
76
 
86
77
  ---
@@ -11,6 +11,12 @@ https://github.com/VolkerMuehlhaus/setupEM
11
11
 
12
12
  ## Recent changes
13
13
 
14
+ # What's New - November 16, 2026 (setupEM 0.18.4)
15
+
16
+ **File > Save (Ctrl+S) saves the settings file you opened.** Opened from a `.simcfg` (e.g. the KLayout plug-in's export, with Open in setupEM), Ctrl+S did nothing: the action existed only for a script edited in place, and changes such as a port wall extension were lost without a question when setupEM was closed. Now:
17
+ - Ctrl+S saves into the `.simcfg` / `.tsimcfg` the model was opened from (the menu names it). Its other entries, e.g. the plug-in's link to the model script, are kept. A script edited in place and a piece of a split region are saved as before; a new model asks for a file name.
18
+ - Closing setupEM, opening another file or File > New asks "Save the changes to ...?" when the settings changed since the file was opened or saved.
19
+
14
20
  # What's New - November 15, 2026 (setupEM 0.18.3)
15
21
 
16
22
  Needs gds2palace 0.10.7 or newer (`pip install` updates it).
@@ -37,21 +43,6 @@ Needs gds2palace 0.10.7 or newer (`pip install` updates it).
37
43
  - A model script edited in place whose GDS file was taken from its folder on opening (the script had the other machine's path, e.g. `/mnt/pub/...` for `P:/...`) now gets that path when it is saved or the model is created; the Code tab shows it. Before, the GUI showed the new path and the script kept the old one, and the model was made from the old one.
38
44
  - On Linux, a path with a drive letter from Windows (`D:/...`) in a script or settings file is no longer taken as relative to the script's folder (`/mnt/.../D:/...`, "Load a GDSII file and XML stackup first"). A stackup that is not found, also not next to the script, is taken from the stackups that ship with gds2palace if one has that name; the log says so.
39
45
 
40
- # What's New - November 11, 2026 (setupEM 0.18.1)
41
-
42
- **Command line fixes** (from issue #52, use without a display):
43
- - `--help`, `--version` and a wrong argument of `setupEM`, `setupThermal`, `stackupEditor`, `resultViewer` and `fieldViewer` no longer need a display: the arguments are read before Qt starts. All five have `--version` now.
44
- - `setupEM -simcfg <file>` opens a settings file of an Elmer model in Elmer mode. It opened in Palace mode unless `--elmer` was given, also when started from the KLayout plug-in.
45
- - A `-simcfg`, `-gdsfile` or `-xmlfile` that does not exist, or a settings file of the other application, ends `setupEM` / `setupThermal` with a message on stderr and exit code 2 instead of an empty window. In the GUI, a settings file that is gone is reported as "File not found", not as "Unknown data format".
46
- - Loading a settings file no longer shows a "Loaded" box: the log says "Config loaded from ...", with a GDS or stackup file that was not found at its saved path and was taken from the settings file's folder instead.
47
- - Opening a `.simcfg` continues with the model script only when the file is linked to it, and asks only when the two have other settings (the question lists them). Create Model links: besides `<model>.simcfg` it writes the script's name (`"model_script"`) into the `.simcfg` the model was opened from, e.g. the KLayout plug-in's export, which keeps it on the next export. A script that only reads the same GDSII file is no longer taken for the model; the log names it. New options `--continue-with-script` and `--start-from-config` answer the question on the command line.
48
- - `fieldViewer --screenshot` needs no display and no `QT_QPA_PLATFORM=offscreen`.
49
- - `python -m setupEM.join_pieces` and `python -m setupEM.thermal_results` have `--help` and `--version`, write their errors to stderr, and a missing file is a message, not a traceback.
50
- - The modules without a GUI (`join_pieces`, `thermal_results`, `script_model`, ...) can be imported without loading Qt.
51
- - User guide: Model Fit starts snp2le with the result file loaded (the text said it has to be loaded by hand).
52
-
53
- **Split regions, fix:**a side of the region made a port wall in setupEM after the export (e.g. with via ports of the layout on the region's edge) was a plain PEC wall in every piece and in the full check model: the wall shorted those ports, and the joined result and the full model were both wrong, in the same way. The pieces' port walls on the region's edge are now found from the ports on the edge of each piece's layout; the full model has all of the region's port walls. Where the region has a port wall but a piece none of its ports, that stretch stays PEC and now moves outward with the region's port wall extension (a length; written as `settings['wall_extension']`, needs gds2palace 0.10.1), so that all pieces and the full model have the same box.
54
-
55
46
  Full history: [CHANGES.md](https://github.com/VolkerMuehlhaus/setupEM/blob/main/doc/CHANGES.md)
56
47
 
57
48
  ---
@@ -31,4 +31,4 @@ def main():
31
31
 
32
32
 
33
33
  __all__ = ["main"]
34
- __version__ = "0.18.3"
34
+ __version__ = "0.18.4"
@@ -4822,7 +4822,7 @@ class MainWindowBase(QMainWindow):
4822
4822
 
4823
4823
  self.import_model_action.triggered.connect(lambda: self.import_py_model())
4824
4824
  self.edit_model_action.triggered.connect(lambda: self.edit_py_model())
4825
- self.save_script_action.triggered.connect(lambda: self.save_script_in_place())
4825
+ self.save_script_action.triggered.connect(lambda: self.save_current_file())
4826
4826
  self.revert_script_action.triggered.connect(lambda: self.revert_script_in_place())
4827
4827
  self.export_model_action.triggered.connect(lambda: self.export_to_python())
4828
4828
  self.preferences_action.triggered.connect(lambda: self.open_preferences_dialog())
@@ -5051,6 +5051,8 @@ class MainWindowBase(QMainWindow):
5051
5051
  self._stop_preserve_mode()
5052
5052
  self.protected_source_model_path = None
5053
5053
  self.backup_before_overwrite = None
5054
+ self.config_file = None # a new model: no settings file yet (Ctrl+S asks for one)
5055
+ self._config_baseline = None
5054
5056
  self.saved_values.clear()
5055
5057
  self.materials_list = None
5056
5058
  self.dielectrics_list = None
@@ -5060,6 +5062,7 @@ class MainWindowBase(QMainWindow):
5060
5062
  self.load_all_tabs()
5061
5063
  self.create_model_tab.log_area.clear()
5062
5064
  self.create_model_tab._reset_live_status()
5065
+ self._update_in_place_menu()
5063
5066
 
5064
5067
  def load_user_inputs(self, filename):
5065
5068
  # load of native configuration file
@@ -5207,6 +5210,8 @@ class MainWindowBase(QMainWindow):
5207
5210
  self.apply_native_config_data(data)
5208
5211
  self.load_all_tabs()
5209
5212
  self._add_recent_file(RECENT_SETTINGS_KEY, file_path)
5213
+ self.config_file = file_path # Ctrl+S saves to this file
5214
+ self._mark_config_saved() # the baseline for unsaved changes
5210
5215
  if not quiet:
5211
5216
  # in the log, not a message box: nothing to decide, and a box blocks a start with no display
5212
5217
  log_area = self.create_model_tab.log_area
@@ -5241,6 +5246,9 @@ class MainWindowBase(QMainWindow):
5241
5246
  if answer != QMessageBox.Yes:
5242
5247
  return
5243
5248
  leave_current_script()
5249
+ self.config_file = None # a model from a script: no settings file for Ctrl+S to write
5250
+ self._config_baseline = None
5251
+ self._update_in_place_menu()
5244
5252
  if not quiet and self.piece_set is not None:
5245
5253
  self.piece_set = None # another model: the split region is closed
5246
5254
  self.current_piece = None
@@ -6076,16 +6084,21 @@ class MainWindowBase(QMainWindow):
6076
6084
  action()
6077
6085
 
6078
6086
  def _update_in_place_menu(self):
6079
- # Save script / Revert only in edit-in-place mode; Save Config (*.simcfg)
6080
- # is hidden there, a config file next to the script would be a second,
6081
- # diverging copy of its settings
6087
+ # Save (Ctrl+S) always: the script edited in place, the piece of a split region or the settings file the
6088
+ # model was opened from (save_current_file), named after it. Revert only in edit-in-place mode; Save Config
6089
+ # (*.simcfg) is hidden there, a config file next to the script would be a second, diverging copy of its
6090
+ # settings
6082
6091
  in_place = getattr(self, "script_model", None) is not None
6083
- self.save_script_action.setVisible(in_place)
6084
6092
  self.revert_script_action.setVisible(in_place)
6085
6093
  if in_place:
6086
6094
  name = os.path.basename(self.script_model.path)
6087
6095
  self.save_script_action.setText(f"Save {name}")
6088
6096
  self.revert_script_action.setText(f"Revert {name}")
6097
+ elif getattr(self, "piece_set", None) is not None and getattr(self, "current_piece", None) is not None:
6098
+ self.save_script_action.setText(f"Save {self.current_piece['piece']}")
6099
+ else:
6100
+ config = self._current_config_file()
6101
+ self.save_script_action.setText(f"Save {os.path.basename(config)}" if config else "Save ...")
6089
6102
  self.save_action.setVisible(not in_place)
6090
6103
 
6091
6104
  # saved_values key -> (tab attribute, [widget attributes]) of the fields that
@@ -6293,7 +6306,7 @@ class MainWindowBase(QMainWindow):
6293
6306
 
6294
6307
  def _set_script_dirty(self, dirty):
6295
6308
  self._script_dirty = dirty
6296
- self.save_script_action.setEnabled(self.script_model is not None)
6309
+ self._update_in_place_menu() # Save is always there (save_current_file), named after the file
6297
6310
  self._refresh_title()
6298
6311
 
6299
6312
  def script_has_unsaved_changes(self):
@@ -6385,11 +6398,115 @@ class MainWindowBase(QMainWindow):
6385
6398
  return
6386
6399
  self.load_configuration_from_file(self.script_model.path, in_place=True, ask_unsaved=False)
6387
6400
 
6401
+ # ---------- the settings file opened: Save (Ctrl+S) and its unsaved changes ----------
6402
+
6403
+ def _current_config_file(self):
6404
+ """The settings file (*.simcfg / *.tsimcfg) the tabs were loaded from or last saved to, if it still exists;
6405
+ None for a script edited in place, a split region (its pieces save themselves), or a model from a script or
6406
+ File > New. (Not user_inputs_file: that stays set while a script is edited in place, for Create Model's link
6407
+ from a layout tool's settings file to the script.)"""
6408
+ if getattr(self, "script_model", None) is not None or getattr(self, "piece_set", None) is not None:
6409
+ return None
6410
+ path = getattr(self, "config_file", None)
6411
+ if path and path.lower().endswith("." + self.CONFIG_SUFFIX.lower()) and os.path.isfile(path):
6412
+ return path
6413
+ return None
6414
+
6415
+ def _config_struct(self):
6416
+ """The settings as a settings file holds them (Save Config)."""
6417
+ struct = {"application": self.APP_NAME, "data_format": "1.0"}
6418
+ struct["saved_values"] = self.saved_values
6419
+ struct.update(self.native_config_extra_struct())
6420
+ return struct
6421
+
6422
+ def _config_fingerprint(self):
6423
+ """The tabs' settings as text, for comparing: saved from the tabs without the tabs' warnings (an invalid field
6424
+ is the user's to find when saving, not when opening or closing)."""
6425
+ shown = {kind: getattr(QMessageBox, kind) for kind in ("warning", "critical", "information")}
6426
+ try:
6427
+ for kind in shown:
6428
+ setattr(QMessageBox, kind, staticmethod(lambda *args, **kwargs: QMessageBox.Ok))
6429
+ self.save_all_tabs()
6430
+ finally:
6431
+ for kind, function in shown.items():
6432
+ setattr(QMessageBox, kind, function)
6433
+ return json.dumps(self._config_struct(), sort_keys=True, default=str)
6434
+
6435
+ def _mark_config_saved(self):
6436
+ """The tabs hold what the settings file holds (just loaded or saved): the baseline for unsaved changes."""
6437
+ self._config_baseline = self._config_fingerprint() if self._current_config_file() else None
6438
+ self._update_in_place_menu()
6439
+
6440
+ def config_has_unsaved_changes(self):
6441
+ if self._current_config_file() is None or getattr(self, "_config_baseline", None) is None:
6442
+ return False
6443
+ return self._config_fingerprint() != self._config_baseline
6444
+
6445
+ def _write_config(self, filename, keep_other_keys):
6446
+ """Write the settings file; keep_other_keys: keep the file's other top-level keys (e.g. a layout tool's
6447
+ model_script link or pieces). Returns True when written. A tab with invalid input says so (its warning) and
6448
+ keeps its last valid values, as Save Config always did."""
6449
+ self.save_all_tabs()
6450
+ data = {}
6451
+ if keep_other_keys and os.path.isfile(filename):
6452
+ try:
6453
+ with open(filename, encoding="utf-8") as f:
6454
+ data = json.load(f)
6455
+ except (OSError, ValueError):
6456
+ data = {}
6457
+ if not isinstance(data, dict):
6458
+ data = {}
6459
+ data.update(self._config_struct())
6460
+ try:
6461
+ with open(filename, "w", encoding="utf-8") as f:
6462
+ json.dump(data, f, indent=4)
6463
+ except OSError as e:
6464
+ QMessageBox.warning(self, "Error", f"Failed to save config to {filename}: {e}")
6465
+ return False
6466
+ self._add_recent_file(RECENT_SETTINGS_KEY, filename)
6467
+ self.config_file = filename
6468
+ self._mark_config_saved()
6469
+ return True
6470
+
6471
+ def save_current_file(self):
6472
+ """File > Save (Ctrl+S): the script edited in place, the current piece of a split region, or the settings
6473
+ file the model was opened from (an export of a layout tool too); with none of them, Save Config's dialog.
6474
+ Returns True when saved."""
6475
+ if self.script_model is not None:
6476
+ return self.save_script_in_place()
6477
+ if getattr(self, "piece_set", None) is not None and getattr(self, "current_piece", None) is not None:
6478
+ self.leave_piece(self.current_piece)
6479
+ self.create_model_tab.log_area.appendPlainText(f"Saved {self.current_piece['piece']}.\n")
6480
+ return True
6481
+ path = self._current_config_file()
6482
+ if path is None:
6483
+ self.save_ask_filenamefile()
6484
+ return self._current_config_file() is not None
6485
+ if self._write_config(path, keep_other_keys=True):
6486
+ self.create_model_tab.log_area.appendPlainText(f"Config saved to {shorten_path_for_display(path)}\n")
6487
+ return True
6488
+ return False
6489
+
6490
+ def confirm_unsaved_config(self):
6491
+ """Before New, Load, Import, Open or Exit: offer to save changes to the settings file the model was opened
6492
+ from. Returns False to stay."""
6493
+ if not self.config_has_unsaved_changes():
6494
+ return True
6495
+ path = self._current_config_file()
6496
+ answer = QMessageBox.question(
6497
+ self, "Unsaved changes",
6498
+ f"Save the changes to {os.path.basename(path)}?",
6499
+ QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel, QMessageBox.Save)
6500
+ if answer == QMessageBox.Save:
6501
+ return self._write_config(path, keep_other_keys=True)
6502
+ return answer == QMessageBox.Discard
6503
+
6388
6504
  def confirm_unsaved_script(self):
6389
6505
  """Before leaving edit-in-place mode (New, Load, Import, Open, Exit): offer
6390
- to save unsaved changes. Returns False to stay."""
6506
+ to save unsaved changes. Returns False to stay. Without a script edited in place: the same for the settings
6507
+ file the model was opened from (confirm_unsaved_config)."""
6391
6508
  if not self.script_has_unsaved_changes():
6392
- return True
6509
+ return self.confirm_unsaved_config()
6393
6510
  answer = QMessageBox.question(
6394
6511
  self, "Unsaved changes",
6395
6512
  f"Save the changes to {os.path.basename(self.script_model.path)}?",
@@ -6531,19 +6648,13 @@ class MainWindowBase(QMainWindow):
6531
6648
  raise NotImplementedError
6532
6649
 
6533
6650
  def save_user_inputs_to_file(self, filename):
6534
- # make sure all tabs save their values
6535
- self.save_all_tabs()
6536
-
6651
+ # Save Config: the file becomes the one File > Save (Ctrl+S) writes; saved over the file the model was
6652
+ # opened from, that file's other keys (e.g. a layout tool's) are kept
6653
+ current = self._current_config_file()
6654
+ keep = bool(current) and same_path(filename, current)
6537
6655
  try:
6538
- struct = {"application": self.APP_NAME,
6539
- "data_format": "1.0"}
6540
- struct["saved_values"] = self.saved_values
6541
- struct.update(self.native_config_extra_struct())
6542
-
6543
- with open(filename, "w") as f:
6544
- json.dump(struct, f, indent=4)
6545
- self._add_recent_file(RECENT_SETTINGS_KEY, filename)
6546
- QMessageBox.information(self, "Saved", f"Config saved to {filename}")
6656
+ if self._write_config(filename, keep_other_keys=keep):
6657
+ QMessageBox.information(self, "Saved", f"Config saved to {filename}")
6547
6658
  except Exception as e:
6548
6659
  QMessageBox.warning(self, "Error", f"Failed to save config to {filename}: {e}")
6549
6660
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: setupEM
3
- Version: 0.18.3
3
+ Version: 0.18.4
4
4
  Summary: Python tool for configuration of gds2palace workflow with GUI.
5
5
  Author-email: Volker Muehlhaus <volker@muehlhaus.com>
6
6
  License-Expression: GPL-3.0-or-later
@@ -40,6 +40,12 @@ https://github.com/VolkerMuehlhaus/setupEM
40
40
 
41
41
  ## Recent changes
42
42
 
43
+ # What's New - November 16, 2026 (setupEM 0.18.4)
44
+
45
+ **File > Save (Ctrl+S) saves the settings file you opened.** Opened from a `.simcfg` (e.g. the KLayout plug-in's export, with Open in setupEM), Ctrl+S did nothing: the action existed only for a script edited in place, and changes such as a port wall extension were lost without a question when setupEM was closed. Now:
46
+ - Ctrl+S saves into the `.simcfg` / `.tsimcfg` the model was opened from (the menu names it). Its other entries, e.g. the plug-in's link to the model script, are kept. A script edited in place and a piece of a split region are saved as before; a new model asks for a file name.
47
+ - Closing setupEM, opening another file or File > New asks "Save the changes to ...?" when the settings changed since the file was opened or saved.
48
+
43
49
  # What's New - November 15, 2026 (setupEM 0.18.3)
44
50
 
45
51
  Needs gds2palace 0.10.7 or newer (`pip install` updates it).
@@ -66,21 +72,6 @@ Needs gds2palace 0.10.7 or newer (`pip install` updates it).
66
72
  - A model script edited in place whose GDS file was taken from its folder on opening (the script had the other machine's path, e.g. `/mnt/pub/...` for `P:/...`) now gets that path when it is saved or the model is created; the Code tab shows it. Before, the GUI showed the new path and the script kept the old one, and the model was made from the old one.
67
73
  - On Linux, a path with a drive letter from Windows (`D:/...`) in a script or settings file is no longer taken as relative to the script's folder (`/mnt/.../D:/...`, "Load a GDSII file and XML stackup first"). A stackup that is not found, also not next to the script, is taken from the stackups that ship with gds2palace if one has that name; the log says so.
68
74
 
69
- # What's New - November 11, 2026 (setupEM 0.18.1)
70
-
71
- **Command line fixes** (from issue #52, use without a display):
72
- - `--help`, `--version` and a wrong argument of `setupEM`, `setupThermal`, `stackupEditor`, `resultViewer` and `fieldViewer` no longer need a display: the arguments are read before Qt starts. All five have `--version` now.
73
- - `setupEM -simcfg <file>` opens a settings file of an Elmer model in Elmer mode. It opened in Palace mode unless `--elmer` was given, also when started from the KLayout plug-in.
74
- - A `-simcfg`, `-gdsfile` or `-xmlfile` that does not exist, or a settings file of the other application, ends `setupEM` / `setupThermal` with a message on stderr and exit code 2 instead of an empty window. In the GUI, a settings file that is gone is reported as "File not found", not as "Unknown data format".
75
- - Loading a settings file no longer shows a "Loaded" box: the log says "Config loaded from ...", with a GDS or stackup file that was not found at its saved path and was taken from the settings file's folder instead.
76
- - Opening a `.simcfg` continues with the model script only when the file is linked to it, and asks only when the two have other settings (the question lists them). Create Model links: besides `<model>.simcfg` it writes the script's name (`"model_script"`) into the `.simcfg` the model was opened from, e.g. the KLayout plug-in's export, which keeps it on the next export. A script that only reads the same GDSII file is no longer taken for the model; the log names it. New options `--continue-with-script` and `--start-from-config` answer the question on the command line.
77
- - `fieldViewer --screenshot` needs no display and no `QT_QPA_PLATFORM=offscreen`.
78
- - `python -m setupEM.join_pieces` and `python -m setupEM.thermal_results` have `--help` and `--version`, write their errors to stderr, and a missing file is a message, not a traceback.
79
- - The modules without a GUI (`join_pieces`, `thermal_results`, `script_model`, ...) can be imported without loading Qt.
80
- - User guide: Model Fit starts snp2le with the result file loaded (the text said it has to be loaded by hand).
81
-
82
- **Split regions, fix:**a side of the region made a port wall in setupEM after the export (e.g. with via ports of the layout on the region's edge) was a plain PEC wall in every piece and in the full check model: the wall shorted those ports, and the joined result and the full model were both wrong, in the same way. The pieces' port walls on the region's edge are now found from the ports on the edge of each piece's layout; the full model has all of the region's port walls. Where the region has a port wall but a piece none of its ports, that stretch stays PEC and now moves outward with the region's port wall extension (a length; written as `settings['wall_extension']`, needs gds2palace 0.10.1), so that all pieces and the full model have the same box.
83
-
84
75
  Full history: [CHANGES.md](https://github.com/VolkerMuehlhaus/setupEM/blob/main/doc/CHANGES.md)
85
76
 
86
77
  ---
@@ -49,6 +49,7 @@ tests/test_port_walls.py
49
49
  tests/test_qt_platform_noise.py
50
50
  tests/test_return_applies.py
51
51
  tests/test_run_with_overrides.py
52
+ tests/test_save_current_file.py
52
53
  tests/test_script_model.py
53
54
  tests/test_script_probe.py
54
55
  tests/test_script_writer.py
@@ -147,6 +147,7 @@ def em(monkeypatch):
147
147
  yield start
148
148
  for window in windows:
149
149
  window._script_dirty = False
150
+ window._config_baseline = None
150
151
  window.close()
151
152
  app.processEvents()
152
153
 
@@ -48,6 +48,7 @@ def win(monkeypatch):
48
48
  window = MainWindow()
49
49
  yield window
50
50
  window._script_dirty = False
51
+ window._config_baseline = None
51
52
  window.close()
52
53
  app.processEvents()
53
54
 
@@ -245,6 +246,7 @@ def test_command_line_choice(win, layout, monkeypatch):
245
246
  finally:
246
247
  for window in windows:
247
248
  window._script_dirty = False
249
+ window._config_baseline = None
248
250
  window.close()
249
251
  with pytest.raises(SystemExit):
250
252
  module.parse_arguments(["--continue-with-script"])
@@ -311,6 +313,7 @@ def test_load_config_while_editing_in_place(win, layout, monkeypatch):
311
313
 
312
314
  monkeypatch.setattr(win, "_ask_update_script_from_config", lambda p, d: "new")
313
315
  win._script_dirty = False
316
+ win._config_baseline = None
314
317
  monkeypatch.setattr(win, "confirm_unsaved_script", lambda: True)
315
318
  win.load_configuration_from_file(config)
316
319
  assert win.script_model is None and win.user_inputs_file == config
@@ -51,6 +51,7 @@ def test_viewer_shows_raw_and_deembedded(monkeypatch, app, tmp_path):
51
51
  assert viewer.include_deembedded_cb.isChecked() and not viewer.include_dc_cb.isChecked()
52
52
  viewer.close()
53
53
  win._script_dirty = False
54
+ win._config_baseline = None
54
55
  win.close()
55
56
 
56
57
 
@@ -68,4 +69,5 @@ def test_model_fit_takes_the_calibrated_result_with_port_walls(monkeypatch, app,
68
69
  tab.open_model_fit()
69
70
  assert started and os.path.basename(started[0][-1]) == expected, started
70
71
  win._script_dirty = False
72
+ win._config_baseline = None
71
73
  win.close()
@@ -40,4 +40,5 @@ def test_export_has_no_gui_comment(monkeypatch, app, tmp_path, module_name):
40
40
  assert "no_gui" not in editor.model_edit.toPlainText()
41
41
  finally:
42
42
  window._script_dirty = False
43
+ window._config_baseline = None
43
44
  window.close()
@@ -39,6 +39,7 @@ def open_window(monkeypatch, module_name):
39
39
 
40
40
  def close_window(window):
41
41
  window._script_dirty = False
42
+ window._config_baseline = None
42
43
  window.close()
43
44
 
44
45
 
@@ -315,6 +315,7 @@ def test_window_opens_the_set_and_switches_pieces(monkeypatch, app, messages, tm
315
315
  window.load_configuration_from_file(other)
316
316
  assert window.piece_set is None and tab.runs_group.isHidden()
317
317
  window._script_dirty = False
318
+ window._config_baseline = None
318
319
  window.close()
319
320
 
320
321
 
@@ -355,6 +356,7 @@ def test_start_with_every_piece_unchanged_only_joins(monkeypatch, app, messages,
355
356
  preferred = PieceSet(path).joined_results()[0]
356
357
  assert started and started[0][-1] == preferred and os.path.basename(preferred).startswith("whole_"), started
357
358
  window._script_dirty = False
359
+ window._config_baseline = None
358
360
  window.close()
359
361
 
360
362
 
@@ -380,6 +382,7 @@ def test_a_changed_piece_runs_again(monkeypatch, app, messages, tmp_path):
380
382
  assert started == ["p2"] # p1 reused, p2 meshed (the process is not started here)
381
383
  assert "reused: p1" in tab.log_area.toPlainText()
382
384
  window._script_dirty = False
385
+ window._config_baseline = None
383
386
  window.close()
384
387
 
385
388
 
@@ -406,6 +409,7 @@ def test_a_piece_with_a_script_keeps_its_changes_and_full_stays_unticked(monkeyp
406
409
  assert float(window.saved_values["refined_cellsize"]) == 2.5
407
410
  assert [t for _, t, _ in table_rows(tab)] == [True, True, False] # full check model still unticked
408
411
  window._script_dirty = False
412
+ window._config_baseline = None
409
413
  window.close()
410
414
 
411
415
 
@@ -435,6 +439,7 @@ def test_start_simulation_runs_unattended_and_keeps_a_current_mesh(monkeypatch,
435
439
  tab._piece_runner = None
436
440
  assert "no_gui=True" not in tab.model_launch_args("p1.py"), "Create Mesh by hand shows the mesh as before"
437
441
  window._script_dirty = False
442
+ window._config_baseline = None
438
443
  window.close()
439
444
 
440
445
 
@@ -86,6 +86,7 @@ def open_window(monkeypatch, gds=None, ports=(1, 2)):
86
86
 
87
87
  def close_window(window):
88
88
  window._script_dirty = False
89
+ window._config_baseline = None
89
90
  window.close()
90
91
 
91
92
 
@@ -27,6 +27,7 @@ def open_window(monkeypatch, module_name):
27
27
 
28
28
  def close_window(window):
29
29
  window._script_dirty = False
30
+ window._config_baseline = None
30
31
  window.close()
31
32
 
32
33
 
@@ -0,0 +1,119 @@
1
+ # File > Save (Ctrl+S) without a script edited in place: it saves to the settings file the model was opened from (e.g.
2
+ # a layout tool's export), keeping that file's other keys; closing, opening another file or New ask about unsaved
3
+ # changes to it. Before, Ctrl+S did nothing there (the action only existed for a script edited in place), and changes
4
+ # such as a port wall extension were lost without a question.
5
+ #
6
+ # Run from the repo root: python -m pytest tests
7
+
8
+ import json
9
+ import os
10
+
11
+ import pytest
12
+ from PySide6.QtWidgets import QFileDialog, QLineEdit, QMessageBox
13
+
14
+ from test_port_walls import app, close_window, gssg_gds, messages, open_window # noqa: F401 (fixtures)
15
+
16
+
17
+ @pytest.fixture
18
+ def export(monkeypatch, app, messages, tmp_path):
19
+ """A settings file as a layout tool writes it: GSSG lines with a port wall at xmin, plus a key of its own."""
20
+ window, module = open_window(monkeypatch, gssg_gds(tmp_path / "line.gds"))
21
+ window.mesh_tab.set_port_wall("xmin")
22
+ window.save_all_tabs()
23
+ data = {"application": "setupEM", "data_format": "1.0", "saved_values": dict(module.saved_values),
24
+ "model_script": "line_em.py"}
25
+ data.update(window.native_config_extra_struct())
26
+ close_window(window)
27
+ path = tmp_path / "line_em.simcfg"
28
+ path.write_text(json.dumps(data))
29
+ return str(path)
30
+
31
+
32
+ def extension_edit(window, side):
33
+ window.ports_tab.refresh_port_wall_rows()
34
+ table = window.ports_tab.portwall_table
35
+ row = next(r for r in range(table.rowCount()) if table.item(r, 0).text() == side)
36
+ return table.cellWidget(row, 7).findChild(QLineEdit)
37
+
38
+
39
+ def asked(monkeypatch, answer):
40
+ """QMessageBox.question answered with answer; returns the list of questions asked"""
41
+ questions = []
42
+
43
+ def question(parent, title, text, *args):
44
+ questions.append(text)
45
+ return answer
46
+ monkeypatch.setattr(QMessageBox, "question", staticmethod(question))
47
+ return questions
48
+
49
+
50
+ def test_ctrl_s_saves_the_port_wall_extension_into_the_export(monkeypatch, export, messages):
51
+ window, module = open_window(monkeypatch)
52
+ window.load_configuration_from_file(export)
53
+ assert window.save_script_action.isVisible() and window.save_script_action.text() == "Save line_em.simcfg"
54
+ edit = extension_edit(window, "xmin")
55
+ edit.setText("20")
56
+ edit.editingFinished.emit()
57
+ assert window.config_has_unsaved_changes()
58
+ window.save_script_action.trigger() # Ctrl+S
59
+ assert not window.config_has_unsaved_changes()
60
+ assert not [m for m in messages if m[0] != "information"], messages
61
+ data = json.load(open(export))
62
+ assert data["saved_values"]["port_wall_extension"] == {"xmin": 20.0}
63
+ assert data["model_script"] == "line_em.py", "the layout tool's key is kept"
64
+ assert "Config saved to" in window.create_model_tab.log_area.toPlainText()
65
+ close_window(window)
66
+
67
+ window, module = open_window(monkeypatch) # opened again: the extension is there
68
+ window.load_configuration_from_file(export)
69
+ assert window.ports_tab._port_wall_extension == {"xmin": 20.0} and extension_edit(window, "xmin").text() == "20.0"
70
+ close_window(window)
71
+
72
+
73
+ def test_closing_asks_only_after_a_change(monkeypatch, export):
74
+ window, module = open_window(monkeypatch)
75
+ window.load_configuration_from_file(export)
76
+ questions = asked(monkeypatch, QMessageBox.Discard)
77
+ assert window.close() and questions == [], "nothing changed: no question"
78
+
79
+ for answer, closes, saved in ((QMessageBox.Cancel, False, False), (QMessageBox.Discard, True, False),
80
+ (QMessageBox.Save, True, True)):
81
+ window, module = open_window(monkeypatch)
82
+ window.load_configuration_from_file(export)
83
+ window.frequencies_tab.stop_edit.setText("123")
84
+ questions = asked(monkeypatch, answer)
85
+ before = open(export).read()
86
+ assert window.close() is closes
87
+ assert questions == ["Save the changes to line_em.simcfg?"]
88
+ after = json.load(open(export))
89
+ assert (after != json.loads(before)) is saved
90
+ if saved:
91
+ assert after["model_script"] == "line_em.py"
92
+ close_window(window)
93
+
94
+
95
+ def test_opening_another_file_asks_first(monkeypatch, export, tmp_path):
96
+ window, module = open_window(monkeypatch)
97
+ window.load_configuration_from_file(export)
98
+ window.frequencies_tab.stop_edit.setText("123")
99
+ questions = asked(monkeypatch, QMessageBox.Cancel)
100
+ other = tmp_path / "other.simcfg"
101
+ other.write_text(open(export).read())
102
+ window.load_configuration_from_file(str(other))
103
+ assert questions == ["Save the changes to line_em.simcfg?"] and window.config_file == export, "Cancel: stays"
104
+ close_window(window)
105
+
106
+
107
+ def test_new_model_ctrl_s_asks_for_a_file(monkeypatch, export, tmp_path):
108
+ window, module = open_window(monkeypatch)
109
+ window.load_configuration_from_file(export)
110
+ asked(monkeypatch, QMessageBox.Discard)
111
+ window.new_configuration()
112
+ assert window.config_file is None and window.save_script_action.text() == "Save ..."
113
+ target = tmp_path / "new_model.simcfg"
114
+ module.saved_values["GdsFile"] = str(tmp_path / "line.gds")
115
+ monkeypatch.setattr(QFileDialog, "getSaveFileName", staticmethod(lambda *a, **k: (str(target), "")))
116
+ window.save_script_action.trigger()
117
+ assert os.path.isfile(target) and window.config_file == str(target)
118
+ assert window.save_script_action.text() == "Save new_model.simcfg"
119
+ close_window(window)
@@ -87,6 +87,7 @@ def gui_script(monkeypatch, name, export):
87
87
  return inputs, text
88
88
  finally:
89
89
  window._script_dirty = False
90
+ window._config_baseline = None
90
91
  window.close()
91
92
 
92
93
 
@@ -41,6 +41,7 @@ def open_window(module, monkeypatch):
41
41
 
42
42
  def close(window, app):
43
43
  window._script_dirty = False
44
+ window._config_baseline = None
44
45
  window.close()
45
46
  app.processEvents()
46
47
 
@@ -98,6 +98,7 @@ def test_load_powers(app, monkeypatch, export):
98
98
  powers = {o.source_layernum: o.power for o in setupthermal.thermal_objects.objects if o.type == "source"}
99
99
  assert powers == {202: 0.00012, 203: 0.0, 204: 0.0, 205: 0.0025, 301: 0.003}
100
100
  win._script_dirty = False
101
+ win._config_baseline = None
101
102
  win.close()
102
103
 
103
104
 
@@ -107,6 +108,7 @@ def test_device_names_and_layers_past_299(app, monkeypatch, export):
107
108
  assert column(win, 5) == ["R1 (rhigh)", "R2 (rhigh)", "R3 (rhigh)", "XCORE.Q1 (npn13G2)", "XCORE.Q2 (npn13G2)",
108
109
  "region outline"]
109
110
  win._script_dirty = False
111
+ win._config_baseline = None
110
112
  win.close()
111
113
 
112
114
 
@@ -129,6 +131,7 @@ def test_placeholder_boundary(app, monkeypatch, export):
129
131
  tab.apply_port_values_to_table()
130
132
  assert column(win, 1)[boundary] == "Activ" and column(win, 5)[boundary] == "region outline"
131
133
  win._script_dirty = False
134
+ win._config_baseline = None
132
135
  win.close()
133
136
 
134
137
  def test_elmer_environment(monkeypatch):
@@ -168,6 +171,7 @@ def test_create_model_writes_config(app, monkeypatch, export, tmp_path):
168
171
  tab.create_model()
169
172
  assert json.loads(config.read_text()) == {"application": "something else"}, "a foreign file stays"
170
173
  win._script_dirty = False
174
+ win._config_baseline = None
171
175
  win.close()
172
176
 
173
177
 
@@ -211,6 +215,7 @@ def test_refined_cellsize_override(app, monkeypatch, export):
211
215
  win.modeleditor_tab.create_model_text()
212
216
  assert "settings['refined_cellsize_override']" not in win.modeleditor_tab.model_edit.toPlainText()
213
217
  win._script_dirty = False
218
+ win._config_baseline = None
214
219
  win.close()
215
220
 
216
221
 
@@ -230,4 +235,5 @@ def test_default_purpose(app, monkeypatch):
230
235
  win.file_tab.save_values()
231
236
  assert win.saved_values["purpose"] == expected, module.__name__
232
237
  win._script_dirty = False
238
+ win._config_baseline = None
233
239
  win.close()
@@ -159,4 +159,5 @@ def test_setupthermal_writes_temperatures(tmp_path, monkeypatch):
159
159
  csv_path = sim / "cascode_thermal_temperatures.csv"
160
160
  assert csv_path.is_file() and 'Q1,"npn13G2@-7230,590"' in csv_path.read_text()
161
161
  win._script_dirty = False
162
+ win._config_baseline = None
162
163
  win.close()
File without changes
File without changes
File without changes
File without changes