Skip to content

Commit

Permalink
Merge pull request #21 from WillJRoper/simplify_plotting
Browse files Browse the repository at this point in the history
Simplify the plotting mode
  • Loading branch information
WillJRoper authored Oct 20, 2024
2 parents c74f89c + 09493b0 commit 3beae64
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 678 deletions.
4 changes: 3 additions & 1 deletion src/h5forest/bindings/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from prompt_toolkit.layout import ConditionalContainer
from prompt_toolkit.widgets import Label

from h5forest.errors import error_handler


def _init_app_bindings(app):
"""
Expand Down Expand Up @@ -48,7 +50,7 @@ def hist_leader_mode(event):
app._flag_normal_mode = False
app._flag_hist_mode = True

@app.error_handler
@error_handler
def exit_leader_mode(event):
"""Exit leader mode."""
app.return_to_normal_mode()
Expand Down
14 changes: 8 additions & 6 deletions src/h5forest/bindings/dataset_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
from prompt_toolkit.layout.containers import VSplit
from prompt_toolkit.widgets import Label

from h5forest.errors import error_handler


def _init_dataset_bindings(app):
"""Set up the keybindings for the dataset mode."""

@app.error_handler
@error_handler
def show_values(event):
"""
Show the values of a dataset.
Expand Down Expand Up @@ -52,7 +54,7 @@ def show_values(event):
# Exit values mode
app.return_to_normal_mode()

@app.error_handler
@error_handler
def show_values_in_range(event):
"""Show the values of a dataset in an index range."""
# Get the node under the cursor
Expand Down Expand Up @@ -114,7 +116,7 @@ def values_in_range_callback():
values_in_range_callback,
)

@app.error_handler
@error_handler
def close_values(event):
"""Close the value pane."""
app.flag_values_visible = False
Expand All @@ -123,7 +125,7 @@ def close_values(event):
# Exit values mode
app.return_to_normal_mode()

@app.error_handler
@error_handler
def minimum_maximum(event):
"""Show the minimum and maximum values of a dataset."""
# Get the node under the cursor
Expand All @@ -150,7 +152,7 @@ def run_in_thread():
# Start the operation in a new thread
threading.Thread(target=run_in_thread, daemon=True).start()

@app.error_handler
@error_handler
def mean(event):
"""Show the mean of a dataset."""
# Get the node under the cursor
Expand All @@ -177,7 +179,7 @@ def run_in_thread():
# Start the operation in a new thread
threading.Thread(target=run_in_thread, daemon=True).start()

@app.error_handler
@error_handler
def std(event):
"""Show the standard deviation of a dataset."""
# Get the node under the cursor
Expand Down
18 changes: 8 additions & 10 deletions src/h5forest/bindings/hist_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
from prompt_toolkit.layout import ConditionalContainer, VSplit
from prompt_toolkit.widgets import Label

from h5forest.errors import error_handler


def _init_hist_bindings(app):
"""Set up the bindings for histogram mode."""

@app.error_handler
@error_handler
def edit_hist_entry(event):
"""Edit histogram param under cursor."""
# Get the current position and row in the plot content
Expand Down Expand Up @@ -76,7 +78,7 @@ def edit_hist_entry_callback():
# Get the modified entry from the user
app.input(split_line[0], edit_hist_entry_callback)

@app.error_handler
@error_handler
def plot_hist(event):
"""Plot the histogram."""
# Don't update if we already have everything
Expand All @@ -100,11 +102,7 @@ def plot_hist(event):
# Get the plot
app.histogram_plotter.plot_and_show(app.hist_content.text)

# Return to normal mode
app.return_to_normal_mode()
app.default_focus()

@app.error_handler
@error_handler
def save_hist(event):
"""Plot the histogram."""
# Don't update if we already have everything
Expand All @@ -128,14 +126,14 @@ def save_hist(event):
# Get the plot
app.histogram_plotter.plot_and_save(app.hist_content.text)

@app.error_handler
@error_handler
def reset_hist(event):
"""Reset the histogram content."""
app.hist_content.text = app.histogram_plotter.reset()
app.return_to_normal_mode()
app.default_focus()

@app.error_handler
@error_handler
def edit_hist(event):
"""Edit the histogram."""
app.shift_focus(app.hist_content)
Expand All @@ -162,7 +160,7 @@ def exit_edit_hist(event):
app.kb.add(
"q",
filter=Condition(lambda: app.app.layout.has_focus(app.hist_content)),
)(edit_hist)
)(exit_edit_hist)

# Add the hot keys
hot_keys = VSplit(
Expand Down
12 changes: 7 additions & 5 deletions src/h5forest/bindings/jump_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@
from prompt_toolkit.layout import VSplit
from prompt_toolkit.widgets import Label

from h5forest.errors import error_handler


def _init_jump_bindings(app):
"""Set up the keybindings for the jump mode."""

@app.error_handler
@error_handler
def jump_to_top(event):
"""Jump to the top of the tree."""
app.set_cursor_position(app.tree.tree_text, new_cursor_pos=0)

# Exit jump mode
app.return_to_normal_mode()

@app.error_handler
@error_handler
def jump_to_bottom(event):
"""Jump to the bottom of the tree."""
app.set_cursor_position(
Expand All @@ -34,7 +36,7 @@ def jump_to_bottom(event):
# Exit jump mode
app.return_to_normal_mode()

@app.error_handler
@error_handler
def jump_to_parent(event):
"""Jump to the parent of the current node."""
# Get the current node
Expand Down Expand Up @@ -70,7 +72,7 @@ def jump_to_parent(event):

app.return_to_normal_mode()

@app.error_handler
@error_handler
def jump_to_next(event):
"""Jump to the next node."""
# Get the current node
Expand Down Expand Up @@ -109,7 +111,7 @@ def jump_to_next(event):

app.return_to_normal_mode()

@app.error_handler
@error_handler
def jump_to_key(event):
"""Jump to next key containing user input."""

Expand Down
Loading

0 comments on commit 3beae64

Please sign in to comment.