Repository navigation
Add dynamic preset support - #41
Gerard-Taulats wants to merge 11 commits into
Conversation
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
278f2cb to
89ea42a
Compare
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
89ea42a to
0408b60
Compare
| key=lambda kv: (kv[1]["order"], kv[0]) | ||
| )) | ||
|
|
||
| PDK_CONFIGS = load_pdk_configs() |
There was a problem hiding this comment.
Don't use a constant variable for those information.
| addon_dir = Path(__file__).parent | ||
| color_path = addon_dir / PDK_CONFIGS.get(pdk, {}).get('color_path', pdk) | ||
| schemes = [('realistic', 'Realistic', 'Realistic color scheme')] | ||
| pdf_dict = PDK_CONFIGS.get(pdk, {}) |
There was a problem hiding this comment.
Call load_pdk_configs instead of the constant.
There was a problem hiding this comment.
I'm having mixed feelings about this. This constant is being used across 7 functions. While that'd help to maintain latest folder status, I think it's a bit too much to call this every time. What's the usual way on handling these cases? Is it the way you suggest?🤔
There was a problem hiding this comment.
I think the function should be run inside "register_properties", GDSIIPreImportDialog class and Import GDSII class once, and pass around data for functions that need it. What do you think?
There was a problem hiding this comment.
Yes, loading it once and storing it internally is the right way. I think I already did this with other data.
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
4b9bab7 to
e3a86bd
Compare
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
d8f394f to
0173cc8
Compare
Signed-off-by: Gerard Taulats <gerardtaulats@gmail.com>
0173cc8 to
22fcd80
Compare
| pdk_info = PDK_CONFIGS.get(pdk_selection, {}) | ||
| addon_dir = Path(__file__).parent | ||
| yamlfile = addon_dir / pdk_info.get('config_path', 'configs/ihp-sg13g2.yaml') | ||
| yamlfile = addon_dir / pdk_info.get('config_path', f"configs/{pdk_info["file_name"]}.yaml") |
There was a problem hiding this comment.
Claude: bug: nested " inside an f-string delimited by " is a SyntaxError before Python 3.12 — this addon targets Blender 3.4+ (older Python), so the module won't even import.
| yamlfile = addon_dir / pdk_info.get('config_path', f"configs/{pdk_info["file_name"]}.yaml") | |
| yamlfile = addon_dir / pdk_info.get('config_path', f'configs/{pdk_info["file_name"]}.yaml') |
| colorfile = Path(custom_color_path) | ||
| else: | ||
| color_dir = addon_dir / pdk_info.get('color_path', 'configs/colors/ihp-sg13g2') | ||
| color_dir = addon_dir / pdk_info.get('color_path', f"configs/colors/{pdk_info["file_name"]}") |
There was a problem hiding this comment.
Claude: bug: same nested-quote SyntaxError as the yamlfile line above.
| color_dir = addon_dir / pdk_info.get('color_path', f"configs/colors/{pdk_info["file_name"]}") | |
| color_dir = addon_dir / pdk_info.get('color_path', f'configs/colors/{pdk_info["file_name"]}') |
| if k not in pdk_order | ||
| } | ||
| sorted_pdks.update(dict(sorted(remaining.items()))) | ||
| elif item in pdks.keys(): |
There was a problem hiding this comment.
Claude: bug: _config_order.yaml lists raw file stems (ihp-sg13g2), but pdks is keyed by the uppercased form (IHP_SG13G2) from line 50 — so item in pdks.keys() and k not in pdk_order (line 77) never match, and custom ordering silently falls back to alphabetical every time. Normalize item/pdk_order entries with the same .upper().replace('-', '_') transform used on line 50 before comparing.
| color_file = yaml.safe_load(file.read_text(encoding='utf-8')) | ||
| schemes.append((file.stem, color_file.get('name', file.stem), | ||
| color_file.get('description', file.stem))) | ||
| if file.stem==pdf_dict["def_color"]: |
There was a problem hiding this comment.
Claude: bug: if pdk isn't a valid key (e.g. the stale fallback below), pdf_dict is {} and this raises KeyError.
| if file.stem==pdf_dict["def_color"]: | |
| if file.stem==pdf_dict.get("def_color"): |
| items = [] | ||
| # TODO: Load only when accessing list or when opening file explorer, not every refresh. Or add a refresh button | ||
|
|
||
| pdk = getattr(context.scene, 'gdsii_pdk_selection', 'IHP_SG13G2') |
There was a problem hiding this comment.
Claude: nit: this fallback is still the old hardcoded 'IHP_SG13G2' — the rest of this PR switched to next(iter(PDK_CONFIGS)) for the same purpose (lines 625, 638, 777).
| pdk = getattr(context.scene, 'gdsii_pdk_selection', 'IHP_SG13G2') | |
| pdk = getattr(context.scene, 'gdsii_pdk_selection', next(iter(PDK_CONFIGS))) |
| addon_dir = Path(__file__).parent | ||
| color_path = addon_dir / PDK_CONFIGS.get(pdk, {}).get('color_path', pdk) | ||
| schemes = [('realistic', 'Realistic', 'Realistic color scheme')] | ||
| pdf_dict = PDK_CONFIGS.get(pdk, {}) |
There was a problem hiding this comment.
Yes, loading it once and storing it internally is the right way. I think I already did this with other data.
|
Replaced by #43 |
Removes hardcoded presets, reading the files present at "config" folder.
Allows for users to add their custom presets and be readily available from Blender UI.
A set of new properties have been added to the "config" YAML files under "pdk_config", where name, description, order and default color can be set.
"Order" are integers. Default value is 0. If same value is set, then it's ordered alphabetically.
Since I set order of existing presets greater than 0, any new custom preset added by the user will take preference in the list.
I'm thinking next step to polish stuff is to not have a pre-import popup, and instead choose pdk and color from the import window.
TODO: Update readme.md and schema.json, add "def_color" to presets and make default def_color=""