chmutils.base_chess_tk_app¶
BaseChessTkApp
Classes
Base class for a chess app |
- class chmutils.base_chess_tk_app.BaseChessTkApp¶
Bases:
object
Base class for a chess app
- add_options(menu_bar: Menu) None ¶
Adds options menu to menu bar.
- Parameters:
- menu_bartkinter.Menu
- after(ms: int, function: Optional[Callable] = None, *args) None ¶
Placeholder for Tk.after(self, ms, function=None, *args) method.
Notes
- ask_depth() Optional[int] ¶
Prompt the user to set a new recursion depth for heatmap calculations.
This method displays a dialog box warning the user about the exponential complexity of increasing depth values. It recommends using odd values for unbiased heatmaps, as even depths favor the current player.
- Returns:
- Union[int, None]
The user-provided depth value if valid, otherwise None.
- canvas: Canvas¶
- change_board_colors() None ¶
Invoke both light and dark square color option prompts.
This method opens color pickers for both the light and dark squares, allowing the user to select custom colors for the chessboard squares.
- change_font(new_font: str) None ¶
Handle font option updates.
This method updates the font used for displaying chess pieces on the board. After updating, the board is re-rendered with the new font.
- choose_square_color(title: str, index: int) None ¶
Allow the user to change a specific square color.
This method opens a tkinter color chooser dialog, allowing the user to select a new color for either the light or dark squares on the chessboard.
- Parameters:
- titlestr
The title of the color picker dialog (e.g., “Pick Light Square Color”).
- indexint
The index (0 for light squares, 1 for dark squares) of the square color to be changed.
- abstract clear_board()¶
Clears the canvas of any drawn board objects
- colors: List[str]¶
Constructs the app menu during initialization.
This method creates a menu bar with options to load a PGN file, change the board colors, and modify the font. It also allows navigation through the moves in the game (next/previous move).
- current_move_index: int¶
- depth: int¶
- font: str¶
- static get_xys(col: int, flipped_row: int, square_size: int) Tuple[int, int, int, int] ¶
Get x_0, x_1, y_0, y_1 of a square.
- Parameters:
- colint
- flipped_rowint
- square_sizeint
- Returns:
- Tuple[int, int, int, int]
- highlight_squares: Set[int]¶
- abstract on_closing()¶
Clean up resources before closing the application.
- on_resize(event: Event) None ¶
Handle window resize events.
This method is called whenever the user resizes the window, adjusting the canvas and square size to fit the new dimensions of the window. It triggers a board update after resizing.
- abstract set_depth()¶
Prompt the user to set a new recursion depth for heatmap calculations.
The user is asked to input an integer value. If a valid value is provided, the depth is updated and the window title is refreshed to reflect the change.
- abstract set_title()¶
Sets the App window title
- square_size: int¶
- abstract update_board()¶
Update the chessboard display based on the current position.
This method redraws the entire chessboard based on the current state of the Board object, including updating the colors of the squares and displaying the chess pieces. It uses the precomputed heatmap colors if available, or calculates them if necessary.
- updating: bool¶