}
-class BrickColor(Textfiled, Lookupable):
+class BrickColor(Textfiled, Lookupable, WithDb):
'Color incl. solidness/transparency field.'
_id_indent = 3
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 = {}
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
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
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 {}
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)
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(