Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readme #758

Merged
merged 24 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
406 changes: 72 additions & 334 deletions README.md

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions examples/code_browser.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ CodeBrowser.-show-tree #tree-view {
dock: left;
height: 100%;
max-width: 50%;
background: $surface;
background: $panel;
}

CodeBrowser{
background: $surface-darken-1;
background: $background;
}

DirectoryTree {
padding-right: 1;

}

#code {
Expand Down
8 changes: 4 additions & 4 deletions examples/code_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

from textual.app import App, ComposeResult
from textual.layout import Container, Vertical
from textual.reactive import Reactive
from textual.reactive import var
from textual.widgets import DirectoryTree, Footer, Header, Static


class CodeBrowser(App):
"""Textual code browser app."""

BINDINGS = [
("t", "toggle_tree", "Toggle Tree"),
("f", "toggle_files", "Toggle Files"),
("q", "quit", "Quit"),
]

show_tree = Reactive.init(True)
show_tree = var(True)

def watch_show_tree(self, show_tree: bool) -> None:
"""Called when show_tree is modified."""
Expand Down Expand Up @@ -52,7 +52,7 @@ def on_directory_tree_file_click(self, event: DirectoryTree.FileClick) -> None:
self.query_one("#code-view").scroll_home(animate=False)
self.sub_title = event.path

def action_toggle_tree(self) -> None:
def action_toggle_files(self) -> None:
self.show_tree = not self.show_tree


Expand Down
172 changes: 172 additions & 0 deletions imgs/calculator.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
193 changes: 193 additions & 0 deletions imgs/codebrowser.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed imgs/custom.gif
Binary file not shown.
Binary file removed imgs/custom.png
Binary file not shown.
199 changes: 199 additions & 0 deletions imgs/stopwatch_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
199 changes: 199 additions & 0 deletions imgs/stopwatch_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified imgs/textual.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed imgs/widgets.png
Binary file not shown.
33 changes: 22 additions & 11 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,10 @@ def _log(
except Exception as error:
self._handle_exception(error)

def action_screenshot(self, path: str | None = None) -> None:
def action_screenshot(self, filename: str | None, path: str = "~/") -> None:
"""Action to save a screenshot."""
self.save_screenshot(path)
self.bell()
self.save_screenshot(filename, path)

def export_screenshot(self, *, title: str | None = None) -> str:
"""Export a SVG screenshot of the current screen.
Expand All @@ -566,22 +567,32 @@ def export_screenshot(self, *, title: str | None = None) -> str:
console.print(screen_render)
return console.export_svg(title=title or self.title)

def save_screenshot(self, path: str | None = None) -> str:
"""Save a screenshot of the current screen.
def save_screenshot(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could note this down to mention as a HOWTO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saving screenshots? Feels a bit too trivial for a how-to, as long as it appears in the search...

self,
filename: str | None = None,
path: str = "./",
willmcgugan marked this conversation as resolved.
Show resolved Hide resolved
time_format: str = "%Y-%m-%d %X %f",
) -> str:
"""Save a SVG screenshot of the current screen.

Args:
path (str | None, optional): Path to SVG to save or None to pick
a filename automatically. Defaults to None.
filename (str | None, optional): Filename of SVG screenshot, or None to auto-generate
a filename with the data and time. Defaults to None.
willmcgugan marked this conversation as resolved.
Show resolved Hide resolved
path (str | None, optional): Path to directory for output or None for current
working directory. Default's to None"
willmcgugan marked this conversation as resolved.
Show resolved Hide resolved
time_format(str, optional): Time format to use if filename is None. Defaults to "%Y-%m-%d %X %f".

Returns:
str: Filename of screenshot.
"""
self.bell()
if path is None:
svg_path = f"{self.title.lower()}_{datetime.now().isoformat()}.svg"
svg_path = svg_path.replace("/", "_").replace("\\", "_")
if filename is None:
svg_filename = (
f"{self.title.lower()} {datetime.now().strftime(time_format)}.svg"
)
svg_filename = svg_filename.replace("/", "_").replace("\\", "_")
else:
svg_path = path
svg_filename = filename
svg_path = os.path.expanduser(os.path.join(path, svg_filename))
willmcgugan marked this conversation as resolved.
Show resolved Hide resolved
screenshot_svg = self.export_screenshot()
with open(svg_path, "w") as svg_file:
svg_file.write(screenshot_svg)
Expand Down
4 changes: 2 additions & 2 deletions src/textual/cli/previews/borders.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BorderApp(App):
Static {
margin: 2 4;
padding: 2 4;
border: solid $primary;
border: solid $secondary;
height: auto;
background: $panel;
color: $text-panel;
Expand All @@ -53,7 +53,7 @@ def compose(self):
def on_button_pressed(self, event: Button.Pressed) -> None:
self.text.styles.border = (
event.button.id,
self.stylesheet.variables["primary"],
self.stylesheet.variables["secondary"],
)
self.bell()

Expand Down
4 changes: 2 additions & 2 deletions src/textual/widgets/_tree_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ def __rich__(self) -> RenderableType:
class TreeControl(Generic[NodeDataType], Static, can_focus=True):
DEFAULT_CSS = """
TreeControl {
background: $surface;
color: $text-surface;
background: $panel;
color: $text-panel;
height: auto;
width: 100%;
}
Expand Down