diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2025-01-29 12:04:07 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-29 12:04:07 -0500 |
| commit | 913c2700d1486284dba0583ae1b280b1aa237570 (patch) | |
| tree | c165b29d0794981b5e44ab46f9838baab16b06a4 /lib/utils/dotdict.py | |
| parent | efe3b27f17686094f74462bd81763a8197b54c6e (diff) | |
Sew Stack first steps (#3133)
* handle more recursive cases
* scaffolding for stitch layers
* scaffolding for SewStack
* always use DotDict when parsing json params
* add DefaultDotDict + DotDict fixes
* first working SewStack (no UI yet)
* ignore inkstitch_debug.log and .svg
* refactor
* early WIP: property grid display temporarily in stitch plan preview
* start of sew stack editor extension
* add layer properties panel and splitter
* spacing and better icon
* handle checkbox
* add layer action buttons
* show selected property help text in an HtmlWindow
* rename
* rephrase help text for tolerance
* refactor into separate file
* simplify structure
* better property type handling
* add randomization button
* add random seed re-roll button
* simulator preview
* update preview in a few more cases
* always DotDict
* avoid ridiculously slow simulations
* preview selected layer or all layers
* edit multiple objects and save only modified properties into the SVG
* better preview handling
* add reverse and jitter
* add stitch path jitter
* fix types
* fix random shuffle button
* fixes
* fix repeats
* type hinting to please pycharm
* show layer description
* avoid exception in properties with multiple values
* fix typing
* fix new layer
* draw a box around property grid and help box
* confirm before closing
* rename properties and fix seed
* fix close/cancel logic
* add buttons to undo changes and reset to default value
* set not modified if default is original setting
* fix invisible icon
* more space for properties
* fix random properties
* better regulation of simulator rendering speed
* Fixed timer being passed a float
* fix get_json_param() default handling
* fix tests
* add checkbox for sew stack only
* fix property help
* adjustable stitch layer editor help box size, with persistence
* repeat exact stitches
* "fix" style
* adjust for new next_element stuff
---------
Co-authored-by: CapellanCitizen <thecapellancitizen@gmail.com>
Diffstat (limited to 'lib/utils/dotdict.py')
| -rw-r--r-- | lib/utils/dotdict.py | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/utils/dotdict.py b/lib/utils/dotdict.py index 12cf6e79..47f56623 100644 --- a/lib/utils/dotdict.py +++ b/lib/utils/dotdict.py @@ -3,6 +3,7 @@ # Copyright (c) 2010 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + class DotDict(dict): """A dict subclass that allows accessing methods using dot notation. @@ -10,24 +11,33 @@ class DotDict(dict): """ def __init__(self, *args, **kwargs): - super(DotDict, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self._dotdictify() def update(self, *args, **kwargs): - super(DotDict, self).update(*args, **kwargs) + super().update(*args, **kwargs) self._dotdictify() def _dotdictify(self): for k, v in self.items(): - if isinstance(v, dict): + if isinstance(v, dict) and not isinstance(v, DotDict): self[k] = DotDict(v) - __setattr__ = dict.__setitem__ __delattr__ = dict.__delitem__ + def __setattr__(self, name, value): + if name.startswith('_'): + super().__setattr__(name, value) + else: + if isinstance(value, dict) and not isinstance(value, DotDict): + value = DotDict(value) + + super().__setitem__(name, value) + def __getattr__(self, name): if name.startswith('_'): - raise AttributeError("'DotDict' object has no attribute '%s'" % name) + raise AttributeError( + f"'{self.__class__.__name__}' object has no attribute '{name}'") if name in self: return self.__getitem__(name) @@ -37,5 +47,5 @@ class DotDict(dict): return new_dict def __repr__(self): - super_repr = super(DotDict, self).__repr__() - return "DotDict(%s)" % super_repr + super_repr = super().__repr__() + return f"{self.__class__.__name__}({super_repr})" |
