Skip to content

Commit

Permalink
Merge file actions into a single hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
mitaa committed Oct 14, 2024
1 parent f123b6f commit eb6abf7
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/production_planner/ActionSelector.tcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ActionSelector {
align: center middle;
}

ActionSelector > Container {
align: center middle;
width: auto;
height: auto;
border: thick $background 80%;
}

ActionSelector > Container > DataTable {
align: center middle;
width: auto;
height: auto;
margin: 0 0;
}
59 changes: 56 additions & 3 deletions src/production_planner/datatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@
from dataclasses import dataclass
from pathlib import Path
from copy import copy
from functools import partial
from typing import (
Optional,
Tuple
)

from textual.containers import Container
from textual.widgets import DataTable
from textual.coordinate import Coordinate
from textual.screen import ModalScreen
from textual.app import ComposeResult
from textual.binding import Binding
from textual import events

from rich.style import Style
Expand Down Expand Up @@ -111,9 +116,7 @@ class PlannerTable(DataTable):
("ctrl+down", "move_down", "Move Down"),
("ctrl+right", "expand", "Expand"),
("ctrl+left", "collapse", "Collapse"),
("s", "save", "Save"),
("l", "load", "Load"),
("d", "delete", "Delete"),
("t", "table", "Table.."),
("f2", "show_hide", "Hide"),
("f3", "swap_vis_space", "Show Hidden"),
("[", "decrement", "-1"),
Expand Down Expand Up @@ -170,6 +173,56 @@ def on_focus(self):
def action_dataview(self):
self.app.push_screen(DataView(self))

def action_table(self):
def run(callback):
if callback:
callback()

self.app.push_screen(self.ActionSelector(self, [Binding("s", self.action_save, "Save"),
Binding("l", self.action_load, "Load"),
Binding("d", self.action_delete, "Delete"),
]),
run)

@classmethod
def ActionSelector(cls, dst_table, options: [(str, callable)]):
class ActionSelector(ModalScreen[callable]):
BINDINGS = [
("escape", "cancel", "Cancel"),
]
CSS_PATH = "ActionSelector.tcss"
data = options

def compose(self) -> ComposeResult:
yield Container(DataTable())

def on_mount(self) -> None:
for option in options:
def selected(action):
self.dismiss(action)

name = option.action.__name__
setattr(self, name, partial(selected, option.action))
action_name = name.removeprefix("action_")
self._bindings.bind(option.key, action_name, option.description)

table = self.query_one(DataTable)
table.cursor_type = "row"
table.add_columns("Action")
table.add_rows([[binding.description] for binding in self.data])
table.cursor_coordinate = Coordinate(0, 0)
self.query_one(Container).styles.height = len(self.data) + 3

def action_cancel(self):
self.dismiss([])

def on_data_table_row_selected(self):
table = self.query_one(DataTable)
row = table.cursor_coordinate.row
callback = self.data[row].action
self.dismiss(callback)
return ActionSelector()

def save_data(self, subpath=None) -> Optional[Tuple[DataFile]]:
result = self.sink.sink_commit(subpath)
self.app.title = self.sink.title
Expand Down
2 changes: 1 addition & 1 deletion tests
Submodule tests updated 83 files
+89 −89 __snapshots__/test_base_screens/test_purity_screen.svg
+84 −83 __snapshots__/test_base_screens/test_startup_screen.svg
+79 −78 __snapshots__/test_init_data_folder/test_init_data[keys1].svg
+83 −82 __snapshots__/test_init_data_folder/test_init_data[keys2].svg
+89 −88 __snapshots__/test_module/test_self_module[keys0].svg
+85 −84 __snapshots__/test_num_inputs/test_increment_new_nodes[keys0].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys0].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys10].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys1].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys2].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys3].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys4].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys5].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys6].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys7].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys8].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys9].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys0].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys1].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys2].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys3].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys4].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys5].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys6].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys7].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys8].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys9].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_MK[keys0].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_MK[keys1].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_MK[keys2].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_MK[keys3].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_MK[keys4].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_MK[keys5].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_MK[keys6].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_MK[keys7].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_MK[keys8].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_MK[keys9].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys0].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys1].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys2].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys3].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys4].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys5].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys6].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys7].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys8].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys9].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys0].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys10].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys1].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys2].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys3].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys4].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys5].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys6].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys7].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys8].svg
+85 −84 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys9].svg
+85 −84 __snapshots__/test_rows/test_rows_ADD[keys0].svg
+85 −84 __snapshots__/test_rows/test_rows_ADD[keys1].svg
+85 −84 __snapshots__/test_rows/test_rows_ADD[keys2].svg
+85 −84 __snapshots__/test_rows/test_rows_ADD[keys3].svg
+79 −78 __snapshots__/test_rows/test_rows_REMOVE[keys0].svg
+79 −78 __snapshots__/test_rows/test_rows_REMOVE[keys1].svg
+85 −84 __snapshots__/test_rows/test_rows_REMOVE[keys2].svg
+85 −84 __snapshots__/test_rows/test_rows_REMOVE[keys3].svg
+79 −78 __snapshots__/test_rows/test_rows_REMOVE[keys4].svg
+85 −84 __snapshots__/test_rows/test_rows_REMOVE[keys5].svg
+84 −83 __snapshots__/test_rows/test_rows_REMOVE[keys6].svg
+2 −2 test_base_screens.py
+1 −1 test_load.py
+1 −1 test_save.py
+86 −85 with_modules/__snapshots__/test_expand/test_module_COLLAPSE[keys0].svg
+86 −85 with_modules/__snapshots__/test_expand/test_module_COLLAPSE[keys1].svg
+87 −86 with_modules/__snapshots__/test_expand/test_module_EXPAND[keys0].svg
+87 −86 with_modules/__snapshots__/test_expand/test_module_EXPAND[keys1].svg
+86 −85 with_modules/__snapshots__/test_save_with_expanded_module/test_save_with_module[keys0].svg
+87 −86 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys0].svg
+84 −83 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys1].svg
+79 −78 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys2].svg
+86 −85 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys3].svg
+87 −86 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys4].svg
+86 −85 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys5].svg

0 comments on commit eb6abf7

Please sign in to comment.