Skip to content

Commit

Permalink
Merge pull request #758 from Textualize/readme
Browse files Browse the repository at this point in the history
Readme
  • Loading branch information
willmcgugan authored Sep 13, 2022
2 parents 150af18 + c453dd9 commit 3ba9203
Show file tree
Hide file tree
Showing 14 changed files with 866 additions and 356 deletions.
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.
32 changes: 21 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,31 @@ 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(
self,
filename: str | None = None,
path: str = "./",
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 date and time. Defaults to None.
path (str, optional): Path to directory for output. Defaults to current working directory.
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))
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

0 comments on commit 3ba9203

Please sign in to comment.