return None
-class Piece(Textfiled, Lookupable):
+class Piece(Textfiled, WithDb, Lookupable):
'Individual configuration of design and color.'
def __init__(
id_: str,
design_id: str,
color_id: str,
- comment: str
+ comment: str,
+ **kwargs
) -> None:
self.id_ = id_
self.design_id = design_id
self.color_id = color_id
self.comment = comment
+ super().__init__(**kwargs)
@classmethod
def from_textfile(
cls,
path: tuple[str, str],
+ db: Optional['BricksDb'] = None,
**_
) -> dict[str, Self]:
collected = {}
assert piece_id not in collected
color_id, comment = (toks[-1].split(CHAR_SEP_TOKEN, maxsplit=1)
+ [''])[:2]
- collected[piece_id] = cls(piece_id, design_id, color_id, comment)
+ collected[piece_id] = cls(piece_id, design_id, color_id, comment,
+ db=db)
return collected
def raw(
return (f'{self.id_:>7} {self.design_id:>6} '
f'{self.color_id:>3} {self.comment}').rstrip()
+ def __str__(
+ self
+ ) -> str:
+ assert self._db
+ design = Design.possibly_by_alt(self.design_id, self._db.designs)
+ color = self._db.colors[self.color_id]
+ comment = f' # {self.comment}' if self.comment else ''
+ return f'{self.id_:>7} {self.design_id:>6} {design.description} ({str(color).strip()}){comment}'
+
class Collection(Textfiled, WithDb, Lookupable):
'Named collection of pieces in order of pages of columns of counts.'
path_tables: str
) -> None:
self.colors = Color.from_textfile((path_tables, PATH_COLORS))
- self.pieces = Piece.from_textfile((path_tables, PATH_PIECES))
+ self.pieces = Piece.from_textfile((path_tables, PATH_PIECES), db=self)
self.collections = Collection.from_textfile(
(path_tables, PATH_COLLECTIONS), db=self)
self.designs = Design.from_textfile((path_tables, PATH_DESIGNS))