From 8fd7431692923ddc75eaff376e8f6bb9e24e79a3 Mon Sep 17 00:00:00 2001 From: Plom Heller Date: Wed, 16 Sep 2026 19:07:29 +0200 Subject: [PATCH] To default colors view add hint on where to find in colors examples set. --- src/bricksplom/misc.py | 31 +++++++++++++++++++++++++++---- src/run.py | 9 ++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/bricksplom/misc.py b/src/bricksplom/misc.py index 9229916..0bbe80e 100644 --- a/src/bricksplom/misc.py +++ b/src/bricksplom/misc.py @@ -228,7 +228,7 @@ class Lookupable: } -class BrickColor(Textfiled, Lookupable): +class BrickColor(Textfiled, Lookupable, WithDb): 'Color incl. solidness/transparency field.' _id_indent = 3 @@ -236,16 +236,19 @@ class BrickColor(Textfiled, Lookupable): self, id_: str, solid: bool, - wavelength: str + wavelength: str, + **kwargs ) -> None: self.id_ = id_ self.solid = solid self.wavelength = wavelength + super().__init__(**kwargs) @classmethod def from_textfile( cls, path: tuple[str, str], + db: Optional['BricksDb'] = None, **_ ) -> dict[str, Self]: collected = {} @@ -253,7 +256,8 @@ class BrickColor(Textfiled, Lookupable): assert id_ not in collected assert len(desc) > 1 assert desc[0] in {CHAR_COL_SOLID, CHAR_COL_TRANSPARENT} - collected[id_] = cls(id_, desc[0] == CHAR_COL_SOLID, desc[1:]) + collected[id_] = cls(id_, desc[0] == CHAR_COL_SOLID, desc[1:], + db=db) return collected @classmethod @@ -267,7 +271,18 @@ class BrickColor(Textfiled, Lookupable): def show( self ) -> str: + def idx_in_sample_set( + pages: tuple[Page, ...] + ) -> str: + for idx, page in enumerate(pages): + for jdx, column in enumerate(page): + for kdx, listing in enumerate(column): + if self.id_ == listing[2].strip(): + return f'({idx}:{jdx}:{kdx})' + return '(-) ' text = f'{self.id_indented()} ' + if (set_colors := self.db.set_colors()): + text += f'{idx_in_sample_set(set_colors.brick_listings)} ' text += 'solid' if self.solid else 'trans' text += f' {self.wavelength}' return text @@ -821,8 +836,10 @@ class BricksDb: self, path_tables: str, path_ldraw: str, - ldraw_modes: str + ldraw_modes: str, + name_set_colors: str ) -> None: + self._name_set_colors = name_set_colors for name, cls in [(name, cls) for name, cls in self.lookupables.items() if issubclass(cls, Textfiled)]: kwargs = {'db': self} if issubclass(cls, WithDb) else {} @@ -976,3 +993,9 @@ class BricksDb: items = cls.sorters()[sorter][1](self, items) return CHAR_NEWLINE.join([cls.formatters()[formatter][1](item) for item in items]) + + def set_colors( + self + ) -> Optional[BrickSet]: + 'Set with color examples, if found under ._name_set_colors.' + return self.sets.get(self._name_set_colors) diff --git a/src/run.py b/src/run.py index ffcc22e..2296afe 100755 --- a/src/run.py +++ b/src/run.py @@ -87,9 +87,12 @@ def main( or str(Path.home().joinpath('.config', 'bricksplom', 'config.json'))) config = (json_loads(path_conffile.read_text(encoding='utf8')) if path_conffile.is_file() else {}) - path_tables = environ.get(NAME_ENV_DIRNAME, config.get('path_tables', '')) - path_ldraw = environ.get(NAME_ENV_LDRAW, config.get('path_ldraw', '')) - db = BricksDb(path_tables, path_ldraw, args.ldraw) + db = BricksDb( + environ.get(NAME_ENV_DIRNAME, config.get('path_tables', '')), + environ.get(NAME_ENV_LDRAW, config.get('path_ldraw', '')), + args.ldraw, + config.get('set_colors', ''), + ) if not args.table == ARG_CHECK: print( db.lookup( -- 2.30.2