home · contact · privacy
To default colors view add hint on where to find in colors examples set. master
authorPlom Heller <plom@plomlompom.com>
Wed, 16 Sep 2026 17:07:29 +0000 (19:07 +0200)
committerPlom Heller <plom@plomlompom.com>
Wed, 16 Sep 2026 17:07:29 +0000 (19:07 +0200)
src/bricksplom/misc.py
src/run.py

index 9229916b41e36df6b094c04f64512d639e11d48e..0bbe80ea371f9f1416f7237b2394550c8ab84199 100644 (file)
@@ -228,7 +228,7 @@ class Lookupable:
             }
 
 
             }
 
 
-class BrickColor(Textfiled, Lookupable):
+class BrickColor(Textfiled, Lookupable, WithDb):
     'Color incl. solidness/transparency field.'
     _id_indent = 3
 
     'Color incl. solidness/transparency field.'
     _id_indent = 3
 
@@ -236,16 +236,19 @@ class BrickColor(Textfiled, Lookupable):
             self,
             id_: str,
             solid: bool,
             self,
             id_: str,
             solid: bool,
-            wavelength: str
+            wavelength: str,
+            **kwargs
             ) -> None:
         self.id_ = id_
         self.solid = solid
         self.wavelength = wavelength
             ) -> None:
         self.id_ = id_
         self.solid = solid
         self.wavelength = wavelength
+        super().__init__(**kwargs)
 
     @classmethod
     def from_textfile(
             cls,
             path: tuple[str, str],
 
     @classmethod
     def from_textfile(
             cls,
             path: tuple[str, str],
+            db: Optional['BricksDb'] = None,
             **_
             ) -> dict[str, Self]:
         collected = {}
             **_
             ) -> 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}
             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
         return collected
 
     @classmethod
@@ -267,7 +271,18 @@ class BrickColor(Textfiled, Lookupable):
     def show(
             self
             ) -> str:
     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()} '
         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
         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,
             self,
             path_tables: str,
             path_ldraw: str,
-            ldraw_modes: str
+            ldraw_modes: str,
+            name_set_colors: str
             ) -> None:
             ) -> 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 {}
         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])
                 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)
index ffcc22ec63cddbe81d46be8beba158d64489d8cc..2296afe7ca3cbc57bc0dc7a685a7e1e99178b3d1 100755 (executable)
@@ -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 {})
         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(
     if not args.table == ARG_CHECK:
         print(
             db.lookup(