Source code for bot_api.internal.graphics_state
# graphics_state.py
from typing import Optional, List, Dict, Any
[docs]
class GraphicsState:
def __init__(self):
# Simple internal state, e.g., a list of SVG elements or drawing commands
self._svg_elements: List[Dict[str, Any]] = []
[docs]
def get_svg_output(self) -> Optional[str]:
"""
Returns the current graphics state as an SVG string.
Returns None if there is nothing to render.
"""
if not self._svg_elements:
return None
# This is a placeholder for actual SVG generation.
# In a real implementation, this method would iterate through _svg_elements
# and construct a valid SVG string.
# For the purpose of this test, we'll just indicate that output would be generated.
return f"<svg>{len(self._svg_elements)} elements</svg>"
[docs]
def clear(self) -> None:
"""
Clears all graphics elements.
"""
self._svg_elements = []
# Placeholder for methods that would add graphics elements.
# These would be called by the bot through the IGraphics interface.
# e.g., draw_line, draw_rectangle, draw_text, etc.
# For now, these are not strictly necessary for the import test to pass,
# as long as the methods called by BaseBotInternals (get_svg_output, clear) exist.
[docs]
def add_element(self, element: Dict[str, Any]): # Example method to make it non-empty for testing get_svg_output
"""Adds a generic graphics element."""
self._svg_elements.append(element)