mirror of
https://github.com/1j01/textual-paint.git
synced 2024-11-24 08:44:45 +03:00
Use new Collapsible widget for error details
This commit is contained in:
parent
2162ddd125
commit
cd3137a737
@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- Updated Textual from 0.28.0 to 0.37.1
|
||||
- Error details now use Textual's `Collapsible` widget (introduced in 0.37), simplifying the code, and giving it a distinct look, whereas before it looked just like the other buttons in the dialog, but on a separate row.
|
||||
|
||||
## [0.3.0] - 2023-09-16
|
||||
|
||||
### Removed
|
||||
|
@ -1068,8 +1068,7 @@ class PaintApp(App[None]):
|
||||
# It's a difference in name, and an automatic close
|
||||
if callback:
|
||||
callback(button)
|
||||
if not button.has_class("details_button"):
|
||||
window.close()
|
||||
window.close()
|
||||
window = MessageBox(
|
||||
# id="message_box",
|
||||
title=title,
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
from typing import Any, Callable, ClassVar
|
||||
|
||||
from textual import events, on
|
||||
from textual import events
|
||||
from textual.app import ComposeResult
|
||||
from textual.containers import Container, Horizontal, Vertical
|
||||
from textual.css.query import NoMatches
|
||||
@ -11,8 +11,9 @@ from textual.geometry import Offset
|
||||
from textual.message import Message
|
||||
from textual.reactive import var
|
||||
from textual.widget import Widget
|
||||
from textual.widgets import Button, Static
|
||||
from textual.widgets import Button, Collapsible, Static
|
||||
from typing_extensions import Self
|
||||
from textual_paint.args import args
|
||||
|
||||
from textual_paint.localization.i18n import get as _
|
||||
|
||||
@ -467,18 +468,20 @@ class MessageBox(DialogWindow):
|
||||
self.message_widget = message
|
||||
if error:
|
||||
# expandable error details
|
||||
# TODO: use new Collapsible widget from Textual 0.37.0
|
||||
import traceback
|
||||
details = "\n".join(traceback.format_exception(error))
|
||||
self.details_widget = Container(Static(details, markup=False, classes="details"))
|
||||
self.details_widget.display = False
|
||||
self.details_widget.styles.overflow_x = "auto"
|
||||
self.details_widget.styles.overflow_y = "auto"
|
||||
self.details_button = Button(_("Show Details"), classes="details_button")
|
||||
self.collapsible = Collapsible(
|
||||
self.details_widget,
|
||||
title="Details",
|
||||
collapsed_symbol=">>> Show" if args.ascii_only else "▶ Show",
|
||||
expanded_symbol="<<< Hide" if args.ascii_only else "▼ Hide",
|
||||
)
|
||||
self.message_widget = Vertical(
|
||||
self.message_widget,
|
||||
self.details_button,
|
||||
self.details_widget,
|
||||
self.collapsible,
|
||||
)
|
||||
self.message_widget.styles.height = "auto"
|
||||
self.message_widget.styles.max_height = "35"
|
||||
@ -489,13 +492,6 @@ class MessageBox(DialogWindow):
|
||||
self.icon_widget = icon_widget
|
||||
self.button_types = button_types
|
||||
|
||||
@on(Button.Pressed, ".details_button")
|
||||
def toggle_details(self, event: Button.Pressed) -> None:
|
||||
"""Toggle the visibility of the error details."""
|
||||
self.details_widget.display = not self.details_widget.display
|
||||
button_text = _("Hide Details") if self.details_widget.display else _("Show Details")
|
||||
self.details_button.label = button_text
|
||||
|
||||
def on_mount(self):
|
||||
"""Called when the window is mounted."""
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -119,8 +119,8 @@ def test_paint_error_dialog(snap_compare: SnapCompareType, each_theme: None):
|
||||
pilot.app.message_box("EMIT", "Error Message Itself Test", "ok", error=Exception("Error Message Itself Test"))
|
||||
assert pilot.app.query_one("MessageBox")
|
||||
await pilot.pause(1.0)
|
||||
assert pilot.app.query_one("MessageBox .details_button")
|
||||
await pilot.click("MessageBox .details_button")
|
||||
assert pilot.app.query_one("MessageBox CollapsibleTitle")
|
||||
await pilot.click("MessageBox CollapsibleTitle")
|
||||
await pilot.pause(0.5) # avoid pressed state
|
||||
|
||||
assert snap_compare(PAINT, run_before=show_error)
|
||||
|
Loading…
Reference in New Issue
Block a user