Coverage for src / ezqt_widgets / types.py: 87.10%
27 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-01 22:46 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-01 22:46 +0000
1# ///////////////////////////////////////////////////////////////
2# TYPES - Type Aliases Module
3# Project: ezqt_widgets
4# ///////////////////////////////////////////////////////////////
6"""
7Type aliases module for ezqt_widgets.
9This module centralizes common type aliases used throughout the library
10to improve code readability, maintainability, and type safety.
12Example:
13 >>> from ezqt_widgets.types import IconSource, SizeType
14 >>> from PySide6.QtGui import QIcon
15 >>>
16 >>> def create_icon(source: IconSource) -> QIcon:
17 ... # Use the type alias
18 ... pass
19"""
21from __future__ import annotations
23# ///////////////////////////////////////////////////////////////
24# IMPORTS
25# ///////////////////////////////////////////////////////////////
26# Standard library imports
27from collections.abc import Callable
28from typing import TYPE_CHECKING, Any, TypeAlias
30# Third-party imports
31from PySide6.QtCore import QSize
32from PySide6.QtGui import QColor, QIcon, QPixmap
33from PySide6.QtWidgets import QWidget
35# Type-checking-only imports (avoids circular import at runtime)
36if TYPE_CHECKING: 36 ↛ 37line 36 didn't jump to line 37 because the condition on line 36 was never true
37 from .widgets.misc.theme_icon import ThemeIcon
39# ///////////////////////////////////////////////////////////////
40# TYPE ALIASES
41# ///////////////////////////////////////////////////////////////
43# ------------------------------------------------
44# Icon Types
45# ------------------------------------------------
47IconSource: TypeAlias = QIcon | str | None
48"""Type alias for icon sources.
50Accepts:
51 - QIcon: A Qt icon object (ThemeIcon recommended)
52 - str: Path to an icon file (local path, resource path, or URL)
53 - None: No icon
55Note:
56 ThemeIcon is a QIcon subclass and is supported wherever QIcon is accepted.
58Used by: IconButton, DateButton, LoaderButton, etc.
59"""
61if TYPE_CHECKING: 61 ↛ 62line 61 didn't jump to line 62 because the condition on line 61 was never true
62 IconSourceExtended: TypeAlias = QIcon | QPixmap | str | bytes | ThemeIcon | None
63else:
64 IconSourceExtended: TypeAlias = QIcon | QPixmap | str | bytes | None
65"""Type alias for extended icon sources (includes QPixmap, ThemeIcon, and bytes).
67Accepts:
68 - QIcon: A Qt icon object (ThemeIcon recommended)
69 - QPixmap: A Qt pixmap object
70 - str: Path to an icon file (local path, resource path, or URL)
71 - bytes: Raw SVG or image data (e.g. embedded SVG constants from shared)
72 - ThemeIcon: A theme-aware icon (subclass of QIcon)
73 - None: No icon
75Used by: ToggleIcon, HoverLabel, ThemeIcon, IconButton, LoaderButton,
76 SearchInput, PasswordInput, and other widgets that support QPixmap.
77"""
79# ------------------------------------------------
80# Size Types
81# ------------------------------------------------
83SizeType: TypeAlias = QSize | tuple[int, int]
84"""Type alias for size specifications.
86Accepts:
87 - QSize: A Qt size object
88 - tuple[int, int]: (width, height) tuple
90Used by: IconButton, widget sizing, etc.
91"""
93# ------------------------------------------------
94# Color Types
95# ------------------------------------------------
97ColorType: TypeAlias = QColor | str
98"""Type alias for color specifications.
100Accepts:
101 - QColor: A Qt color object
102 - str: Color string (hex "#RRGGBB", named color "red", etc.)
104Used by: Widgets with custom painting (ToggleSwitch, CircularTimer, etc.)
105"""
107# ------------------------------------------------
108# Widget Types
109# ------------------------------------------------
111WidgetParent: TypeAlias = QWidget | None
112"""Type alias for widget parent parameter.
114Accepts:
115 - QWidget: A parent widget
116 - None: No parent (top-level widget)
118Used by: All widget constructors.
119"""
121# ------------------------------------------------
122# Animation Types
123# ------------------------------------------------
125AnimationDuration: TypeAlias = int
126"""Type alias for animation duration in milliseconds.
128Used by: Widgets with animations (ToggleSwitch, LoaderButton, etc.)
129"""
131# ------------------------------------------------
132# Callback Types
133# ------------------------------------------------
135EventCallback: TypeAlias = Callable[[], None]
136"""Type alias for event callbacks without parameters.
138Used by: Click handlers, event callbacks, etc.
139"""
141ValueCallback: TypeAlias = Callable[[Any], None]
142"""Type alias for value change callbacks.
144Used by: Signal handlers, value change callbacks, etc.
145"""
147# ///////////////////////////////////////////////////////////////
148# PUBLIC API
149# ///////////////////////////////////////////////////////////////
151__all__ = [
152 "AnimationDuration",
153 "ColorType",
154 "EventCallback",
155 "IconSource",
156 "IconSourceExtended",
157 "SizeType",
158 "ValueCallback",
159 "WidgetParent",
160]