textualicious 0.0.1__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,7 @@
1
+ __version__ = "0.0.1"
2
+
3
+ from textualicious.dataclass_table import DataClassTable
4
+ from textualicious.dataclass_viewer import DataClassViewer
5
+ from textualicious.log_widget import LoggingWidget
6
+
7
+ __all__ = ["DataClassTable", "DataClassViewer", "LoggingWidget"]
@@ -0,0 +1,168 @@
1
+ """Generic data table implementations for dataclass-like objects."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING, Any
6
+
7
+ from fieldz import fields
8
+ from textual.message import Message
9
+ from textual.widgets import DataTable
10
+
11
+
12
+ if TYPE_CHECKING:
13
+ from textual.widgets._data_table import CursorType, RowKey
14
+
15
+
16
+ class DataClassTable[T](DataTable):
17
+ """A DataTable that displays a list of dataclass-like objects."""
18
+
19
+ class RowSelected(Message):
20
+ """Emitted when a row is selected."""
21
+
22
+ def __init__(self, item: Any) -> None:
23
+ self.item = item
24
+ super().__init__()
25
+
26
+ def __init__(
27
+ self,
28
+ item_type: type[T],
29
+ *,
30
+ show_hidden: bool = False,
31
+ show_header: bool = True,
32
+ show_row_labels: bool = True,
33
+ fixed_rows: int = 0,
34
+ fixed_columns: int = 0,
35
+ zebra_stripes: bool = False,
36
+ header_height: int = 1,
37
+ show_cursor: bool = True,
38
+ cursor_type: CursorType = "cell",
39
+ cell_padding: int = 1,
40
+ name: str | None = None,
41
+ id: str | None = None, # noqa: A002
42
+ classes: str | None = None,
43
+ disabled: bool = False,
44
+ ) -> None:
45
+ """Initialize the table.
46
+
47
+ Args:
48
+ item_type: The type of items to display
49
+ show_hidden: Whether to show fields starting with underscore
50
+ show_header: Whether the table header should be visible
51
+ show_row_labels: Whether the row labels should be shown
52
+ fixed_rows: Number of rows to fix at the top
53
+ fixed_columns: Number of columns to fix at the left
54
+ zebra_stripes: Enable alternating row colors
55
+ header_height: Height of the header row
56
+ show_cursor: Whether to show the cursor
57
+ cursor_type: Type of cursor ("cell", "row", "column", or "none")
58
+ cell_padding: Padding between cells
59
+ name: The name of the widget
60
+ id: The ID of the widget
61
+ classes: CSS classes
62
+ disabled: Whether the widget is disabled
63
+ """
64
+ super().__init__(
65
+ show_header=show_header,
66
+ show_row_labels=show_row_labels,
67
+ fixed_rows=fixed_rows,
68
+ fixed_columns=fixed_columns,
69
+ zebra_stripes=zebra_stripes,
70
+ header_height=header_height,
71
+ show_cursor=show_cursor,
72
+ cursor_type=cursor_type,
73
+ cell_padding=cell_padding,
74
+ name=name,
75
+ id=id,
76
+ classes=classes,
77
+ disabled=disabled,
78
+ )
79
+ self._item_type = item_type
80
+ self._show_hidden = show_hidden
81
+ self._items: dict[RowKey, T] = {}
82
+ self._setup_columns()
83
+
84
+ def _setup_columns(self) -> None:
85
+ """Set up columns based on the item type's fields."""
86
+ try:
87
+ obj_fields = fields(self._item_type)
88
+ except TypeError as e:
89
+ msg = f"Unable to inspect fields of {self._item_type}"
90
+ raise ValueError(msg) from e
91
+
92
+ for field in obj_fields:
93
+ if field.name.startswith("_") and not self._show_hidden:
94
+ continue
95
+
96
+ header = field.name
97
+ self.add_column(header, key=field.name)
98
+
99
+ def add_item(self, item: T) -> None:
100
+ """Add an item to the table.
101
+
102
+ Args:
103
+ item: Instance of the item type
104
+ """
105
+ if not isinstance(item, self._item_type):
106
+ msg = f"Expected {self._item_type.__name__}, got {type(item).__name__}"
107
+ raise TypeError(msg)
108
+
109
+ try:
110
+ obj_fields = fields(item)
111
+ except TypeError as e:
112
+ msg = f"Unable to inspect fields of {item}"
113
+ raise ValueError(msg) from e
114
+
115
+ row_values = []
116
+ for field in obj_fields:
117
+ if field.name.startswith("_") and not self._show_hidden:
118
+ continue
119
+ row_values.append(getattr(item, field.name))
120
+
121
+ row_key = self.add_row(*row_values)
122
+ self._items[row_key] = item
123
+
124
+ def clear_items(self) -> None:
125
+ """Remove all items from the table."""
126
+ self.clear()
127
+ self._items.clear()
128
+
129
+ def get_item(self, row: RowKey) -> T | None:
130
+ """Get the item at the specified row."""
131
+ return self._items.get(row)
132
+
133
+ def on_data_table_row_selected(self, event: DataTable.RowSelected) -> None:
134
+ """Handle row selection."""
135
+ if item := self.get_item(event.row_key):
136
+ self.post_message(self.RowSelected(item))
137
+
138
+
139
+ if __name__ == "__main__":
140
+ from dataclasses import dataclass
141
+ from datetime import datetime
142
+
143
+ from textual.app import App
144
+
145
+ @dataclass
146
+ class TaskItem:
147
+ """Example task item for demonstration."""
148
+
149
+ id: int
150
+ title: str
151
+ due_date: datetime
152
+ completed: bool
153
+
154
+ class DemoApp(App):
155
+ """Demo application showing DataClassTable usage."""
156
+
157
+ def compose(self):
158
+ table = DataClassTable(TaskItem, cursor_type="row")
159
+ # Add some sample data
160
+ table.add_item(
161
+ TaskItem(1, "Write documentation", datetime(2024, 1, 15), False)
162
+ )
163
+ table.add_item(TaskItem(2, "Fix bugs", datetime(2024, 1, 16), True))
164
+ table.add_item(TaskItem(3, "Release version", datetime(2024, 1, 17), False))
165
+ yield table
166
+
167
+ app = DemoApp()
168
+ app.run()
@@ -0,0 +1,96 @@
1
+ """Widget for displaying dataclass-like objects in a table format."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING, Any
6
+
7
+ from fieldz import fields
8
+ from rich.table import Table
9
+ from textual.widgets import Static
10
+
11
+
12
+ if TYPE_CHECKING:
13
+ from rich.style import StyleType
14
+
15
+
16
+ class DataClassViewer(Static):
17
+ """Display a dataclass-like object in a table format."""
18
+
19
+ DEFAULT_CSS = """
20
+ DataClassViewer {
21
+ padding: 1;
22
+ }
23
+ """
24
+
25
+ def __init__(
26
+ self,
27
+ obj: Any,
28
+ *,
29
+ show_types: bool = True,
30
+ show_descriptions: bool = True,
31
+ show_hidden: bool = False,
32
+ field_style: StyleType | None = None,
33
+ value_style: StyleType | None = None,
34
+ type_style: StyleType = "dim",
35
+ description_style: StyleType = "italic blue",
36
+ ):
37
+ """Initialize the model viewer.
38
+
39
+ Args:
40
+ obj: Any dataclass-like object to display
41
+ show_types: Whether to show field types
42
+ show_descriptions: Whether to show field descriptions
43
+ show_hidden: Whether to show fields starting with underscore
44
+ field_style: Style for field names
45
+ value_style: Style for field values
46
+ type_style: Style for type annotations
47
+ description_style: Style for field descriptions
48
+ """
49
+ super().__init__("")
50
+ self.obj = obj
51
+ self.show_types = show_types
52
+ self.show_descriptions = show_descriptions
53
+ self.show_hidden = show_hidden
54
+ self.field_style = field_style
55
+ self.value_style = value_style
56
+ self.type_style = type_style
57
+ self.description_style = description_style
58
+ self._update_content()
59
+
60
+ def _update_content(self) -> None:
61
+ """Update the displayed content."""
62
+ table = Table(show_header=False, pad_edge=False, show_edge=True)
63
+
64
+ # Add columns
65
+ table.add_column("Field", style=self.field_style)
66
+ table.add_column("Value", style=self.value_style)
67
+ if self.show_types:
68
+ table.add_column("Type", style=self.type_style)
69
+ if self.show_descriptions:
70
+ table.add_column("Description", style=self.description_style)
71
+
72
+ try:
73
+ obj_fields = fields(self.obj)
74
+ except TypeError as e:
75
+ msg = f"Unable to inspect fields of {type(self.obj)}"
76
+ raise ValueError(msg) from e
77
+
78
+ # Add rows for each field
79
+ for field in obj_fields:
80
+ if field.name.startswith("_") and not self.show_hidden:
81
+ continue
82
+
83
+ value = getattr(self.obj, field.name)
84
+ row: list[Any] = [field.name, str(value)]
85
+
86
+ if self.show_types:
87
+ type_name = field.type if field.type else "N/A"
88
+ row.append(type_name)
89
+
90
+ if self.show_descriptions:
91
+ description = field.description or ""
92
+ row.append(description)
93
+
94
+ table.add_row(*row)
95
+
96
+ self.update(table)
@@ -0,0 +1,6 @@
1
+ from __future__ import annotations
2
+
3
+ from textualicious.log_widget.widget_handler import WidgetHandler
4
+ from textualicious.log_widget.log_widget import LoggingWidget
5
+
6
+ __all__ = ["LoggingWidget", "WidgetHandler"]
@@ -0,0 +1,49 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ from typing import TYPE_CHECKING
5
+
6
+ from textual.message import Message
7
+ from textual.widgets import RichLog
8
+
9
+ from textualicious.log_widget.widget_handler import WidgetHandler
10
+
11
+
12
+ if TYPE_CHECKING:
13
+ from rich.text import Text
14
+
15
+
16
+ class LoggingWidget(RichLog):
17
+ """Widget that acts as both log display and handler."""
18
+
19
+ class LogMessage(Message):
20
+ """Internal message for log events."""
21
+
22
+ def __init__(self, text: Text):
23
+ self.text = text
24
+ super().__init__()
25
+
26
+ DEFAULT_CSS = """
27
+ LoggingWidget {
28
+ height: 1fr;
29
+ border: heavy $background;
30
+ padding: 1;
31
+ }
32
+ """
33
+
34
+ def __init__(
35
+ self,
36
+ *,
37
+ level: int = logging.DEBUG,
38
+ format_string: str = "%(asctime)s - %(levelname)s - %(message)s",
39
+ id: str | None = None, # noqa: A002
40
+ ):
41
+ super().__init__(id=id, wrap=True, markup=True)
42
+ self.formatter = logging.Formatter(format_string)
43
+ handler = WidgetHandler(self)
44
+ handler.setLevel(level)
45
+ self.handler = handler
46
+
47
+ def on_logging_widget_log_message(self, message: LogMessage) -> None:
48
+ """Handle log message event."""
49
+ self.write(message.text)
@@ -0,0 +1,35 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ from typing import TYPE_CHECKING
5
+
6
+ from rich.text import Text
7
+
8
+
9
+ if TYPE_CHECKING:
10
+ from textualicious.log_widget import LoggingWidget
11
+
12
+
13
+ class WidgetHandler(logging.Handler):
14
+ def __init__(self, widget: LoggingWidget):
15
+ super().__init__()
16
+ self.widget = widget
17
+
18
+ def emit(self, record: logging.LogRecord) -> None:
19
+ from textualicious.log_widget import LoggingWidget
20
+
21
+ try:
22
+ assert self.widget.formatter
23
+ msg = self.widget.formatter.format(record)
24
+ style = {
25
+ logging.DEBUG: "dim",
26
+ logging.INFO: "white",
27
+ logging.WARNING: "yellow",
28
+ logging.ERROR: "red",
29
+ logging.CRITICAL: "red bold",
30
+ }.get(record.levelno, "white")
31
+
32
+ text = Text(msg + "\n", style=style)
33
+ self.widget.post_message(LoggingWidget.LogMessage(text))
34
+ except Exception: # noqa: BLE001
35
+ self.handleError(record)
File without changes
textualicious/py.typed ADDED
File without changes
@@ -0,0 +1,82 @@
1
+ Metadata-Version: 2.4
2
+ Name: textualicious
3
+ Version: 0.0.1
4
+ Summary: Textual widgets and integrations
5
+ Project-URL: Documentation, https://phil65.github.io/textualicious/
6
+ Project-URL: Source, https://github.com/phil65/textualicious
7
+ Project-URL: Issues, https://github.com/phil65/textualicious/issues
8
+ Project-URL: Discussions, https://github.com/phil65/textualicious/discussions
9
+ Project-URL: Code coverage, https://app.codecov.io/gh/phil65/textualicious
10
+ Author-email: Philipp Temminghoff <philipptemminghoff@googlemail.com>
11
+ License: MIT License
12
+
13
+ Copyright (c) 2024, Philipp Temminghoff
14
+
15
+ Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ of this software and associated documentation files (the "Software"), to deal
17
+ in the Software without restriction, including without limitation the rights
18
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ copies of the Software, and to permit persons to whom the Software is
20
+ furnished to do so, subject to the following conditions:
21
+
22
+ The above copyright notice and this permission notice shall be included in all
23
+ copies or substantial portions of the Software.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ SOFTWARE.
32
+
33
+ License-File: LICENSE
34
+ Classifier: Development Status :: 4 - Beta
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: Operating System :: OS Independent
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3 :: Only
39
+ Classifier: Programming Language :: Python :: 3.12
40
+ Classifier: Programming Language :: Python :: 3.13
41
+ Classifier: Programming Language :: Python :: 3.14
42
+ Classifier: Topic :: Documentation
43
+ Classifier: Topic :: Software Development
44
+ Classifier: Topic :: Utilities
45
+ Classifier: Typing :: Typed
46
+ Requires-Python: >=3.12
47
+ Requires-Dist: fieldz>=0.1.0
48
+ Requires-Dist: textual>=1.0.0
49
+ Description-Content-Type: text/markdown
50
+
51
+ # Textualicious
52
+
53
+ [![PyPI License](https://img.shields.io/pypi/l/textualicious.svg)](https://pypi.org/project/textualicious/)
54
+ [![Package status](https://img.shields.io/pypi/status/textualicious.svg)](https://pypi.org/project/textualicious/)
55
+ [![Daily downloads](https://img.shields.io/pypi/dd/textualicious.svg)](https://pypi.org/project/textualicious/)
56
+ [![Weekly downloads](https://img.shields.io/pypi/dw/textualicious.svg)](https://pypi.org/project/textualicious/)
57
+ [![Monthly downloads](https://img.shields.io/pypi/dm/textualicious.svg)](https://pypi.org/project/textualicious/)
58
+ [![Distribution format](https://img.shields.io/pypi/format/textualicious.svg)](https://pypi.org/project/textualicious/)
59
+ [![Wheel availability](https://img.shields.io/pypi/wheel/textualicious.svg)](https://pypi.org/project/textualicious/)
60
+ [![Python version](https://img.shields.io/pypi/pyversions/textualicious.svg)](https://pypi.org/project/textualicious/)
61
+ [![Implementation](https://img.shields.io/pypi/implementation/textualicious.svg)](https://pypi.org/project/textualicious/)
62
+ [![Releases](https://img.shields.io/github/downloads/phil65/textualicious/total.svg)](https://github.com/phil65/textualicious/releases)
63
+ [![Github Contributors](https://img.shields.io/github/contributors/phil65/textualicious)](https://github.com/phil65/textualicious/graphs/contributors)
64
+ [![Github Discussions](https://img.shields.io/github/discussions/phil65/textualicious)](https://github.com/phil65/textualicious/discussions)
65
+ [![Github Forks](https://img.shields.io/github/forks/phil65/textualicious)](https://github.com/phil65/textualicious/forks)
66
+ [![Github Issues](https://img.shields.io/github/issues/phil65/textualicious)](https://github.com/phil65/textualicious/issues)
67
+ [![Github Issues](https://img.shields.io/github/issues-pr/phil65/textualicious)](https://github.com/phil65/textualicious/pulls)
68
+ [![Github Watchers](https://img.shields.io/github/watchers/phil65/textualicious)](https://github.com/phil65/textualicious/watchers)
69
+ [![Github Stars](https://img.shields.io/github/stars/phil65/textualicious)](https://github.com/phil65/textualicious/stars)
70
+ [![Github Repository size](https://img.shields.io/github/repo-size/phil65/textualicious)](https://github.com/phil65/textualicious)
71
+ [![Github last commit](https://img.shields.io/github/last-commit/phil65/textualicious)](https://github.com/phil65/textualicious/commits)
72
+ [![Github release date](https://img.shields.io/github/release-date/phil65/textualicious)](https://github.com/phil65/textualicious/releases)
73
+ [![Github language count](https://img.shields.io/github/languages/count/phil65/textualicious)](https://github.com/phil65/textualicious)
74
+ [![Github commits this week](https://img.shields.io/github/commit-activity/w/phil65/textualicious)](https://github.com/phil65/textualicious)
75
+ [![Github commits this month](https://img.shields.io/github/commit-activity/m/phil65/textualicious)](https://github.com/phil65/textualicious)
76
+ [![Github commits this year](https://img.shields.io/github/commit-activity/y/phil65/textualicious)](https://github.com/phil65/textualicious)
77
+ [![Package status](https://codecov.io/gh/phil65/textualicious/branch/main/graph/badge.svg)](https://codecov.io/gh/phil65/textualicious/)
78
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
79
+ [![PyUp](https://pyup.io/repos/github/phil65/textualicious/shield.svg)](https://pyup.io/repos/github/phil65/textualicious/)
80
+
81
+ [Read the documentation!](https://phil65.github.io/textualicious/)
82
+
@@ -0,0 +1,12 @@
1
+ textualicious/__init__.py,sha256=YzS7YztxszbdjSk7msQUbaLWd58DStpIK4c5kK0bu10,256
2
+ textualicious/dataclass_table.py,sha256=bFJQ--g3XWjLofx9V-4BlJCWhdarWU6xvGmN2gTEV2M,5561
3
+ textualicious/dataclass_viewer.py,sha256=zEdpGFHPORIcwtPXkIAuobVre47Fgb9V5vEypcc4Qf0,3101
4
+ textualicious/logwidget.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ textualicious/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ textualicious/log_widget/__init__.py,sha256=5ZSASki9FF6Cf9z4p8qQPdJxhksaNvmwvMiednCWq8o,216
7
+ textualicious/log_widget/log_widget.py,sha256=mBpND6NbFGRuHV-B0VLReODjglUuU9wqZDP5W58gc9I,1298
8
+ textualicious/log_widget/widget_handler.py,sha256=W3NP16uc8mGRLiwHvE9Qhc2HR9GKvmr75e3_xJmKAxQ,1057
9
+ textualicious-0.0.1.dist-info/METADATA,sha256=M6oqcnm-f2i9UVfnZg9QeAxT5z7AC3ViibyBrgISUiw,5977
10
+ textualicious-0.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
+ textualicious-0.0.1.dist-info/licenses/LICENSE,sha256=AteGCH9r177TxxrOFEiOARrastASsf7yW6MQxlAHdwA,1078
12
+ textualicious-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024, Philipp Temminghoff
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+