clock.py

No documentation

class Clock

Description

A clock UI element that can display both analog and digital time.

Supports both 12-hour and 24-hour formats, real-time or custom time,
and various customization options.

Attributes:
   diameter (int): Diameter of the analog clock face.
   use_real_time (bool): Whether to use the system's real time.
   show_numbers (bool): Whether to show numbers on the analog clock.
   time_style (str): '12hr' or '24hr' format.
   mode (str): 'analog', 'digital', or 'both'.
   custom_time (datetime): Custom time to display (if not using real time).

Methods
def __init__(self: Any, x: int, y: int, diameter: int = 100, font_name: Optional[str] = None, font_size: int = 16, use_real_time: bool = True, show_numbers: bool = True, time_style: Literal['12hr', '24hr'] = '24hr', mode: Literal['analog', 'digital', 'both'] = 'analog', root_point: Tuple[float, float] = (0, 0), theme: ThemeType = None, element_id: Optional[str] = None) -> Any
Initialize a Clock element.

Args:
   x (int): X coordinate position.
   y (int): Y coordinate position.
   diameter (int): Diameter of the analog clock face.
   font_name (Optional[str]): Font for digital display and numbers.
   font_size (int): Font size for digital display.
   use_real_time (bool): Whether to use system time.
   show_numbers (bool): Whether to show numbers on analog clock.
   time_style (str): '12hr' or '24hr' format.
   mode (str): 'analog', 'digital', or 'both'.
   root_point (Tuple[float, float]): Anchor point for positioning.
   theme (ThemeType): Theme for styling.
   element_id (Optional[str]): Custom element ID.
def font(self: Any) -> Any
Get the main font object.
def small_font(self: Any) -> Any
Get the smaller font for analog clock numbers.
def update_theme(self: Any, theme_type: ThemeType) -> Any
Update theme colors for the clock.
def set_face_color(self: Any, color: Tuple[int, int, int]) -> Any
Set the clock face color.
def set_border_color(self: Any, color: Tuple[int, int, int]) -> Any
Set the clock border color.
def set_hand_colors(self: Any, hour: Tuple[int, int, int], minute: Tuple[int, int, int], second: Tuple[int, int, int]) -> Any
Set the colors for clock hands.
def set_number_color(self: Any, color: Tuple[int, int, int]) -> Any
Set the color for analog clock numbers.
def set_digital_text_color(self: Any, color: Tuple[int, int, int]) -> Any
Set the color for digital display text.
def set_time(self: Any, time_struct: time.struct_time) -> Any
Set a custom time for the clock.

Args:
   time_struct (time.struct_time): Time structure from time.localtime()
def set_time_from_string(self: Any, time_str: str, format_str: str = '%H:%M:%S') -> Any
Set time from a string.

Args:
   time_str (str): Time string.
   format_str (str): Format string for parsing.
def get_time_string(self: Any) -> str
Get the current time as a formatted string.
def update(self: Any, dt: float, inputState: InputState) -> Any
Update the clock time.
def render(self: Any, renderer: Renderer) -> Any
Render the clock.
def _render_analog_clock(self: Any, renderer: Renderer, x: int, y: int) -> Any
Render the analog clock face and hands.
def _draw_clock_numbers(self: Any, renderer: Renderer, center_x: int, center_y: int, radius: int) -> Any
Draw numbers around the clock face.
def _draw_tick_marks(self: Any, renderer: Renderer, center_x: int, center_y: int, radius: int) -> Any
Draw tick marks for minutes/seconds.
def _draw_hand(self: Any, renderer: Renderer, center_x: int, center_y: int, angle: float, length: float, width: int, color: Tuple[int, int, int]) -> Any
Draw a clock hand.
def _render_digital_clock(self: Any, renderer: Renderer, x: int, y: int) -> Any
Render the digital clock display.
Back to Ui Module