-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquote_table.py
More file actions
77 lines (59 loc) · 2.33 KB
/
quote_table.py
File metadata and controls
77 lines (59 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""A data table widget to display and manipulate financial quotes."""
from __future__ import annotations
from typing import TYPE_CHECKING, TypeAlias, TypedDict
from calahan import YQuote
from .enhanced_data_table import EnhancedColumn, EnhancedDataTable, EnhancedTableCell
if TYPE_CHECKING:
from collections.abc import Callable
from .enums import Justify
QuoteColumn: TypeAlias = EnhancedColumn[YQuote]
QuoteTable: TypeAlias = EnhancedDataTable[YQuote]
def quote_table() -> QuoteTable:
"""Create a QuoteTable.
Returns:
QuoteTable: An EnhancedDataTable specialized for YQuote.
"""
table = EnhancedDataTable[YQuote]()
table.id = "quote-table"
return table
def quote_column( # noqa: PLR0913
label: str,
*,
full_name: str | None = None,
key: str | None = None,
width: int | None = None,
justification: Justify | None = None,
cell_factory: Callable[[YQuote], EnhancedTableCell] | None = None,
) -> QuoteColumn:
"""Create a QuoteColumn.
Args:
label (str): The display label for the column.
full_name (str | None): The full display name of the column. Defaults to
the label when omitted.
key (str | None): The key to access the attribute in YQuote.
Defaults to None, which uses the label as the key.
width (int | None): The width of the column.
justification (Justify | None): The text justification for the column.
cell_factory (Callable[[YQuote], EnhancedTableCell] | None): Factory used
to produce the cell object for each row.
Returns:
QuoteColumn: An EnhancedColumn specialized for YQuote.
"""
class _QuoteColumnParams(TypedDict, total=False):
"""Typing helper for optional QuoteColumn parameters."""
full_name: str
key: str
width: int
justification: Justify
cell_factory: Callable[[YQuote], EnhancedTableCell]
params: _QuoteColumnParams = {}
params["full_name"] = full_name if full_name is not None else label
if key is not None:
params["key"] = key
if width is not None:
params["width"] = width
if justification is not None:
params["justification"] = justification
if cell_factory is not None:
params["cell_factory"] = cell_factory
return EnhancedColumn[YQuote](label, **params)