CTkDataTable 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+
2
+ from ._utils import rows_from_cursor
3
+ from .ctk_data_table import CTkDataTable
4
+ from .table_column import BadgeStyle, Column, TableAction, TableColumn
5
+ from .table_events import TableRowEvent
6
+ from .table_style import TableStyle
7
+
8
+ __all__ = [
9
+ "BadgeStyle",
10
+ "Column",
11
+ "CTkDataTable",
12
+ "TableAction",
13
+ "TableColumn",
14
+ "TableRowEvent",
15
+ "TableStyle",
16
+ "rows_from_cursor",
17
+ ]
CTkDataTable/_utils.py ADDED
@@ -0,0 +1,58 @@
1
+ """Shared internal helpers for CTkDataTable."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Iterable, Mapping
6
+ from datetime import date, datetime
7
+ from typing import Any
8
+
9
+
10
+ def parse_datetime(value: Any) -> datetime | None:
11
+ """Parse date-like values used by table sorting and display formatting."""
12
+
13
+ if isinstance(value, datetime):
14
+ return value
15
+ if isinstance(value, date):
16
+ return datetime.combine(value, datetime.min.time())
17
+ if isinstance(value, str):
18
+ try:
19
+ return datetime.fromisoformat(value)
20
+ except ValueError:
21
+ return None
22
+ return None
23
+
24
+
25
+ def normalize_row(row: Any) -> dict[str, Any]:
26
+ """Convert common query row objects into a plain dictionary."""
27
+
28
+ if isinstance(row, Mapping):
29
+ return dict(row)
30
+
31
+ mapping = getattr(row, "_mapping", None)
32
+ if mapping is not None:
33
+ return dict(mapping)
34
+
35
+ keys = getattr(row, "keys", None)
36
+ if callable(keys):
37
+ return {key: row[key] for key in keys()}
38
+
39
+ raise TypeError(
40
+ "Rows must be mappings, sqlite3.Row objects, SQLAlchemy mapping rows, "
41
+ "or PostgreSQL rows returned as dictionaries."
42
+ )
43
+
44
+
45
+ def normalize_rows(rows: Iterable[Any]) -> list[dict[str, Any]]:
46
+ """Convert an iterable of row-like objects into plain dictionaries."""
47
+
48
+ return [normalize_row(row) for row in rows]
49
+
50
+
51
+ def rows_from_cursor(cursor: Any) -> list[dict[str, Any]]:
52
+ """Convert a DB-API cursor result into dictionaries using cursor.description."""
53
+
54
+ if cursor.description is None:
55
+ raise ValueError("Cursor has no result columns. Execute a SELECT query before converting rows.")
56
+
57
+ column_names = [column[0] for column in cursor.description]
58
+ return [dict(zip(column_names, row, strict=False)) for row in cursor.fetchall()]