-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge pull request #20 from davep/save-pep-source
Add support for saving a PEP's source to a file
- Loading branch information
Showing
6 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
"""Provides a confirmation dialog.""" | ||
|
||
############################################################################## | ||
# Textual imports. | ||
from textual import on | ||
from textual.app import ComposeResult | ||
from textual.containers import Horizontal, Vertical | ||
from textual.screen import ModalScreen | ||
from textual.widgets import Button, Label | ||
|
||
|
||
############################################################################## | ||
class Confirm(ModalScreen[bool]): | ||
"""A modal dialog for confirming things.""" | ||
|
||
CSS = """ | ||
Confirm { | ||
align: center middle; | ||
&> Vertical { | ||
padding: 1 2; | ||
height: auto; | ||
width: auto; | ||
max-width: 80vw; | ||
background: $surface; | ||
border: panel $error; | ||
border-title-color: $text; | ||
&> Horizontal { | ||
height: auto; | ||
width: 100%; | ||
align-horizontal: center; | ||
} | ||
} | ||
Label { | ||
width: auto; | ||
max-width: 70vw; | ||
padding-left: 1; | ||
padding-right: 1; | ||
margin-bottom: 1; | ||
} | ||
Button { | ||
margin-right: 1; | ||
} | ||
} | ||
""" | ||
|
||
BINDINGS = [ | ||
("escape", "no"), | ||
("f2", "yes"), | ||
("left", "focus_previous"), | ||
("right", "focus_next"), | ||
] | ||
|
||
def __init__( | ||
self, title: str, question: str, yes_text: str = "Yes", no_text: str = "No" | ||
) -> None: | ||
"""Initialise the dialog. | ||
Args: | ||
title: The title for the dialog. | ||
question: The question to ask the user. | ||
yes_text: The text for the yes button. | ||
no_text: The text for the no button. | ||
""" | ||
super().__init__() | ||
self._title = title | ||
"""The title for the dialog.""" | ||
self._question = question | ||
"""The question to ask the user.""" | ||
self._yes = yes_text | ||
"""The text of the yes button.""" | ||
self._no = no_text | ||
"""The text of the no button.""" | ||
|
||
def compose(self) -> ComposeResult: | ||
"""Compose the layout of the dialog.""" | ||
key_colour = ( | ||
"dim" if self.app.current_theme is None else self.app.current_theme.accent | ||
) | ||
with Vertical() as dialog: | ||
dialog.border_title = self._title | ||
yield Label(self._question) | ||
with Horizontal(): | ||
yield Button(f"{self._no} [{key_colour}]\\[Esc][/]", id="no") | ||
yield Button(f"{self._yes} [{key_colour}]\\[F2][/]", id="yes") | ||
|
||
@on(Button.Pressed, "#yes") | ||
def action_yes(self) -> None: | ||
"""Send back the positive response.""" | ||
self.dismiss(True) | ||
|
||
@on(Button.Pressed, "#no") | ||
def action_no(self) -> None: | ||
"""Send back the negative response.""" | ||
self.dismiss(False) | ||
|
||
|
||
### confirm.py ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters