kumiki.frame_decorators¶
Flat import path
kumiki/__init__.py re-exports everything on this page via from kumiki import *, so every name below is also available directly as kumiki.FRAME -- you do not need to import from the submodule path shown in the heading above.
kumiki.frame_decorators
¶
Marking the frames and tools in a file for kigumi to find.
A file may declare any number of frames and tools. Each frame declares its own parameters, resolves the values it is handed onto them, and returns them on the Frame::
STOOL = kiwari(legs=kiwari.count(4, minimum=3))
@frame
def stool(k: Optional[Kiwari] = None) -> Frame:
k = STOOL.resolve(k)
...
return Frame.from_joints(joints, kiwari=k)
@frame
def bench(k: Optional[Kiwari] = None) -> Frame:
k = STOOL.resolve(k) # the same kiwari object: one set of parameters for both
...
@tool
def leg_report(frame: Frame) -> str:
return f"{frame.kiwari.count('legs')} legs"
Kigumi builds every @frame and shows them together. Frames whose kiwari were resolved from
the same kiwari object share one set of parameters (see Kiwari.origin); each different one
gets its own section in the parameters panel. A frame is handed back the values for its own
kiwari, or None on the first build. A @tool runs on demand against the shown frame and its
text is displayed. The decorators only mark a function; it is still an ordinary function to
call from a script or a test.
A marked function is admitted only if its annotations say exactly that: (k: Kiwari) -> Frame
for a frame, (frame: Frame) -> str for a tool. Optional[Kiwari] is accepted for the
parameters.
A pattern book marks each of its patterns instead, with a path and, if it takes parameters, its own kiwari::
@pattern("basic_joints/basic_mortise_and_tenon", tags=["main"], kiwari=MORTISE_AND_TENON_OPTIONS)
def basic_mortise_and_tenon(k: Optional[Kiwari] = None) -> Joint:
...
A pattern takes (k: Kiwari) if it declares a kiwari and nothing otherwise, and returns a
Frame, a Joint or a CutCSG. Further parameters are allowed if they have defaults.
PatternDeclaration
dataclass
¶
PatternDeclaration(path: str, tags: Tuple[str, ...], kiwari: Optional[Kiwari])
Entry
dataclass
¶
Rejected
dataclass
¶
ModuleEntries
dataclass
¶
frame
¶
Marks a function (k: Kiwari) -> Frame as one of the file's frames.
It returns its parameters on the Frame: Frame(..., kiwari=k).
tool
¶
pattern
¶
pattern(path: str, *, tags: Sequence[str] = (), kiwari: Optional[Kiwari] = None) -> Callable[[F], F]
Marks a function as one of a pattern book's patterns, at path, with its own kiwari if it takes one.
path is hierarchical ("corner_joints/plain_miter_joint"); each segment is also a tag. Of the
tags, 'main' shows the pattern when the file is opened and 'poop' hides it from the sidebar.
Source code in kumiki/frame_decorators.py
module_entries
¶
module_entries(module: Any) -> ModuleEntries
The frames and tools module marked, in source order, each admitted or rejected.
Source code in kumiki/frame_decorators.py
module_patterns
¶
module_patterns(module: Any) -> Tuple[List[Any], Tuple[Rejected, ...]]
The patterns module marked with @pattern, in source order, and those rejected for their signature.
Source code in kumiki/frame_decorators.py
overlay_frames
¶
Several frames shown together, each where it was built.
The overlay carries a kiwari only when every frame was built from the same one; otherwise each frame's parameters are its own, and stay on it.