From 4a1bdeee8d4fe8c3c74a9165b32f36e07bc96bac Mon Sep 17 00:00:00 2001 From: mitaa Date: Fri, 20 Sep 2024 19:27:47 +0200 Subject: [PATCH] Add increment and decrement keys --- src/production_planner/cells/_cells.py | 10 +++++++++ src/production_planner/datatable.py | 28 ++++++++++++++++++++++++++ tests | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/production_planner/cells/_cells.py b/src/production_planner/cells/_cells.py index 2521505..ddea6e5 100644 --- a/src/production_planner/cells/_cells.py +++ b/src/production_planner/cells/_cells.py @@ -150,6 +150,16 @@ def edit_push_numeral(self, num: str, write_mode) -> bool: self.data.node_main.update() return write_mode + def edit_offset(self, offset): + if not self.is_numeric_editable: + return + prev = str(self.get_num()).strip("+- ").split(".")[0] + prev = int(prev) + offset + if not (self.bounds.lower <= prev <= self.bounds.upper): + prev = max(min(prev, self.bounds.upper), self.bounds.lower) + self.set_num(prev) + self.data.node_main.update() + def edit_delete(self) -> bool: if not self.is_numeric_editable: return diff --git a/src/production_planner/datatable.py b/src/production_planner/datatable.py index 0dc1ce5..506ba08 100644 --- a/src/production_planner/datatable.py +++ b/src/production_planner/datatable.py @@ -113,6 +113,8 @@ class PlannerTable(DataTable): ("d", "delete", "Delete"), ("f2", "show_hide", "Hide"), ("f3", "swap_vis_space", "Show Hidden"), + ("comma", "decrement", "-1"), + ("full_stop", "increment", "+1"), ] # 1-Building Name, 2-Recipe Name, 3-QTY, 4-Mk, 5-Purity, 6-Clockrate //, 7-Energy, 8*-Inputs, 9*-Outputs @@ -333,6 +335,32 @@ def maybe_dirtied(self): self.app.title = self.sink.title self.app.hidden_item_count = self.nodetree.count_hidden_items() + def _offset_cell(self, offset: int): + self.num_write_mode = False + sel_ctxt = SelectionContext(self) + + if len(self.planner_columns) > sel_ctxt.col: + col = self.planner_columns[sel_ctxt.col] + else: + col = None + + instance = sel_ctxt.instance + if instance is None: + return + + if (col is None) or (not col(instance).access_guard() or col.read_only): + return + + col = col(instance) + col.edit_offset(offset) + self.update(sel_ctxt) + + def action_decrement(self): + self._offset_cell(-1) + + def action_increment(self): + self._offset_cell(+1) + def on_key(self, event: events.Key) -> None: if not self.has_focus: return diff --git a/tests b/tests index 13ff77b..938cdc3 160000 --- a/tests +++ b/tests @@ -1 +1 @@ -Subproject commit 13ff77b98d685c7a88011a475041cecb0938c627 +Subproject commit 938cdc311d5caa7e7cd889c50e8c685e717d4c95