Skip to content

Commit

Permalink
Add increment and decrement keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mitaa committed Sep 20, 2024
1 parent 14ab190 commit 4a1bdee
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/production_planner/cells/_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/production_planner/datatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests
Submodule tests updated 76 files
+89 −89 __snapshots__/test_base_screens/test_purity_screen.svg
+83 −84 __snapshots__/test_base_screens/test_startup_screen.svg
+78 −79 __snapshots__/test_init_data_folder/test_init_data[keys1].svg
+82 −83 __snapshots__/test_init_data_folder/test_init_data[keys2].svg
+82 −83 __snapshots__/test_load/test_load_file.svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys0].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys1].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys2].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys3].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys4].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys5].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys6].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys7].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys8].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys0].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys1].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys2].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys3].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys4].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys5].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys6].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys7].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys8].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys0].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys1].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys2].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys3].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys4].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys5].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys6].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys7].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys8].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys9].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys0].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys1].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys2].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys3].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys4].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys5].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys6].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys7].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys8].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys9].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys0].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys1].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys2].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys3].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys4].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys5].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys6].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys7].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys8].svg
+84 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys9].svg
+84 −85 __snapshots__/test_rows/test_rows_ADD[keys0].svg
+84 −85 __snapshots__/test_rows/test_rows_ADD[keys1].svg
+84 −85 __snapshots__/test_rows/test_rows_ADD[keys2].svg
+84 −85 __snapshots__/test_rows/test_rows_ADD[keys3].svg
+78 −79 __snapshots__/test_rows/test_rows_REMOVE[keys0].svg
+78 −79 __snapshots__/test_rows/test_rows_REMOVE[keys1].svg
+84 −85 __snapshots__/test_rows/test_rows_REMOVE[keys2].svg
+84 −85 __snapshots__/test_rows/test_rows_REMOVE[keys3].svg
+78 −79 __snapshots__/test_rows/test_rows_REMOVE[keys4].svg
+84 −85 __snapshots__/test_rows/test_rows_REMOVE[keys5].svg
+83 −84 __snapshots__/test_rows/test_rows_REMOVE[keys6].svg
+84 −85 with_modules/__snapshots__/test_expand/test_module_COLLAPSE[keys0].svg
+84 −85 with_modules/__snapshots__/test_expand/test_module_COLLAPSE[keys1].svg
+85 −86 with_modules/__snapshots__/test_expand/test_module_EXPAND[keys0].svg
+85 −86 with_modules/__snapshots__/test_expand/test_module_EXPAND[keys1].svg
+84 −85 with_modules/__snapshots__/test_save_with_expanded_module/test_save_with_module[keys0].svg
+85 −86 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys0].svg
+83 −84 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys1].svg
+78 −79 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys2].svg
+84 −85 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys3].svg
+85 −86 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys4].svg
+84 −85 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys5].svg
+4 −1 with_modules/test_show_hide.py

0 comments on commit 4a1bdee

Please sign in to comment.