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

WIP: entrybox for plot #143

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
13 changes: 10 additions & 3 deletions src/uproot_browser/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from typing import Any

import uproot
import uproot.behaviors
import uproot.interpretation
import uproot.reading
from rich.console import Console
from rich.markup import escape
Expand Down Expand Up @@ -65,8 +67,9 @@ def label(self) -> Text:

def tree_args(self) -> dict[str, Any]:
d: dict[str, Text | str] = {"label": self.label()}
if "guide_style" in self.meta():
d["guide_style"] = self.meta()["guide_style"]
meta = self.meta()
if "guide_style" in meta:
d["guide_style"] = meta["guide_style"]
return d

@property
Expand All @@ -84,7 +87,10 @@ def children(self) -> list[UprootEntry]:
else:
items = {obj.name.split(";")[0] for obj in self.item.branches}
return [
UprootEntry(f"{self.path}/{key}", self.item[key]) for key in sorted(items)
UprootEntry(
key if self.path == "/" else f"{self.path}/{key}", self.item[key]
)
for key in sorted(items)
]


Expand All @@ -108,6 +114,7 @@ def process_item(uproot_object: Any) -> MetaDict:
"""
name = getattr(uproot_object, "name", "<unnamed>")
classname = getattr(uproot_object, "classname", uproot_object.__class__.__name__)
assert isinstance(classname, str)
label_text = Text.assemble(
(f"{name} ", "bold"),
(classname, "italic"),
Expand Down
8 changes: 8 additions & 0 deletions src/uproot_browser/tui/browser.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ Browser.-show-tree #tree-view {
content-align: center middle;
}

#plot-input-container {
height: 3;
}

#plot-button {
dock: right;
}


Footer > .footer--highlight {
background: $secondary-darken-2;
Expand Down
7 changes: 7 additions & 0 deletions src/uproot_browser/tui/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def compose(self) -> textual.app.ComposeResult:
id="main-view",
initial="logo",
)
with textual.containers.Container(id="plot-input-container"):
yield textual.widgets.Input(id="plot-input")
yield textual.widgets.Button("Plot", id="plot-button")

yield textual.widgets.Footer()

def on_mount(self, _event: textual.events.Mount) -> None:
Expand Down Expand Up @@ -147,6 +151,9 @@ def on_uproot_selected(self, message: UprootSelected) -> None:
make_plot(message.upfile[message.path], theme, 20)
self.plot_widget.item = Plotext(message.upfile, message.path, theme)
content_switcher.current = "plot"
self.query_one(
"#plot-input", textual.widgets.Input
).value = f"f[{message.path!r}]"

except EmptyTreeError:
content_switcher.current = "empty"
Expand Down
1 change: 1 addition & 0 deletions src/uproot_browser/tui/right_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import textual.widget
import textual.widgets

import uproot_browser.dirs
import uproot_browser.plot

LOGO = """\
Expand Down