Components
Internal classes to generate gif components, included in the documentation for information purposes.
- class gifpgn.components._AssetImage(name: str, size: int)[source]
Bases:
objectLoads an image from the assets directory or the cache
- Parameters:
name (str) – filename
size (int) – size in pixels to resize the image to
- _images: Dict[str, Image] = {}
- class gifpgn.components._Board(size: int, board: Board, reverse: bool = False, square_colors: BoardTheme | None = None, piece_theme: PieceTheme = PieceTheme.ALPHA)[source]
Bases:
_ComponentGenerate an image of a given board position
- Parameters:
size (int) – Size of the board image in pixels
board (chess.Board) – A board state
reverse (bool) – Draws the board from the perspective of black if True, defaults to False
square_colors (BoardTheme) – Colors of the white and black squares, instance of gifpgn.BoardTheme
piece_theme (PieceTheme) – The piece theme to use, instance of gifpgn.PieceTheme
- property board: Board
- property board_size: int
Size of the board in pixels
- draw_arrow(from_sqare: int, to_square: int, color: Literal['red', 'green', 'blue'] = 'green') None[source]
Draws an arrow from one square to another square
- Parameters:
from_sqare (chess.Square)
to_square (chess.Square)
color (str) – Arrow color. Options are “red”, “green”, or “blue”. Defaults to “green”
- draw_nag(nag: Literal['blunder', 'mistake', 'inaccuracy'], square: int) None[source]
Draws a blunder, mistake or inaccuracy NAG at the specified square
- Parameters:
nag (str) – NAG to draw. Options are “blunder”, “mistake”, or “inaccuracy”
square (chess.Square) – The square to draw the NAG
- get_square_color(square: int) bool[source]
Returns the color of the given square
- Parameters:
square (chess.Square)
- Return chess.Color:
- get_square_image(square: int) Image[source]
Retrieves or creates a square image of the given color
- Parameters:
square (chess.Square)
- Return Image.Image:
PIL Image object containing an image of the given square color
- get_square_position(square: int, center: bool = False) Coord[source]
Calculates the position of either the top left of center of the specified square taking into account whether the board is reversed
- Parameters:
square (chess.Square)
center (bool) – If true the center of the square will be calculated, otherwise top left, defaults to False
- Return Coord:
Coordinates of the given square
- property square_colors: BoardTheme
- class gifpgn.components._Canvas(board: int, analysis_bar: int | None, analysis_graph: int | None, headers: int | None, reverse: bool)[source]
Bases:
_ComponentStitches the components together into a final frame
- Parameters:
board (int) – Board size in pixels
analysis_bar (Optional[int]) – Analysis bar width in pixels
analysis_graph (Optional[int]) – Graph height in pixels
headers (Optional[int]) – Header heights in pixels
reverse (bool) – White at the top if True, at the bottom if False
- class gifpgn.components._EvalBar(size: Tuple[int, int], evalu: Score, max_eval: int, reverse: bool)[source]
Bases:
_Component
- class gifpgn.components._Graph(game: Game, size: Tuple[int, int], max_eval: int, line_width: int = 1)[source]
Bases:
objectDraws the evaluation graph. The full graph is drawn when initialized and stored.
Calls to
at_move()return a copy of the graph with a red dot drawn at the specified move.- Parameters:
game (chess.pgn.Game) – Game object containing an
[%eval ...]annotated PGNsize (Tuple[int, int]) – x,y size of the graph
max_eval (int) – Limits the y axis to +/- the given number of centipawns
line_width (int) – Width of graph line (and x axis line) in pixels, defaults to 1
- _draw_graph_background() Image[source]
Iterates through the game in self._game_root and draws a the analysis graph
- Return Image.Image:
PIL Image object containing the graph
- _get_graph_position(evalu: Score, move: int) Coord[source]
Returns the position of a given evluation and move number on the evaluation graph
- Parameters:
evalu (chess.engine.Score)
move (int)
- Return Coord:
Coordinates on the evaluation graph
- at_move(move_num: int) Image[source]
Returns a copy of the analysis graph with a red dot drawn at the given move number
- Parameters:
move_num (int)
- Raises:
MoveOutOfRangeError – Requested move is not valid
- Return Image.Image:
- class gifpgn.components._Headers(game: Game, captures: List[Piece], size: Tuple[int, int])[source]
Bases:
object
- class gifpgn.components._Piece(piece: Piece, size: int, theme: PieceTheme = PieceTheme.ALPHA)[source]
Bases:
_AssetImageExtends
_AssetImageto convert achess.Pieceto the corresponding filename in the assets directory- Parameters:
piece (chess.Piece)
size (int) – size in pixels to resize the image to
theme (Piecetheme) – Instance of gifpgn.PieceTheme