Skip to content

Commit

Permalink
WIP: entrybox for plot
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Jun 23, 2023
1 parent 283d0b1 commit acb7bea
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
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

0 comments on commit acb7bea

Please sign in to comment.