Skip to content

Commit

Permalink
Add system commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mitaa committed Sep 20, 2024
1 parent a5c4471 commit e7f827f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
37 changes: 34 additions & 3 deletions src/production_planner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,27 @@
from pathlib import Path
import importlib.metadata
import traceback
from typing import Iterable

from docopt import docopt

from textual.app import App, ComposeResult
from textual.app import App, SystemCommand, ComposeResult
from textual.screen import Screen
from textual.widgets import Footer
from textual.reactive import reactive


__version__ = importlib.metadata.version("production_planner")


# The Fuel Generator, like all power generation buildings, behaves differently to power consumer buildings when overclocked. A generator overclocked to 250% only operates 202.4% faster[EA] (operates 250% faster[EX]).
# As the fuel consumption rate is directly proportional to generator power production, verify that demand matches the production capacity to ensure that Power Shards are used to their full potential. Fuel efficiency is unchanged, but consumption and power generation rates may be unexpectedly uneven[EA].


def planner_command(title, help, callback, discover=True) -> SystemCommand:
help = " " + help
return SystemCommand(title, help, callback, discover)


class Planner(App):
CSS_PATH = "Planner.tcss"
header = None
Expand All @@ -60,10 +66,35 @@ def __init__(self, testrun=False, *args, **kwargs):
super().__init__(*args, **kwargs)

def compose(self) -> ComposeResult:
yield Header()
yield Header(icon="Menu")
yield PlannerTable(header_control=True)
yield Footer()

def get_system_commands(self, screen: Screen) -> Iterable[SystemCommand]:
for command in super().get_system_commands(screen):
if command.title.lower() == "light mode":
continue
yield planner_command(*command)
yield planner_command("Save As", "Save the currently active file with a new filename", self._save_as)
yield planner_command("Load", "Load a new file in the currently active table", self._load)
yield planner_command("Delete", "Delete a file from the filesystem", self._delete)

def _save_as(self):
if not self.focused_table:
return
self.call_next(self.focused_table.action_save)

def _load(self):
if not self.focused_table:
return
# NOTE: directly calling `action_load` somehow causes the Screen callback not to be invoked
self.call_next(self.focused_table.action_load)

def _delete(self):
if not self.focused_table:
return
self.call_next(self.focused_table.action_delete)

def is_table_shown(self, table: PlannerTable) -> bool:
raise NotImplemented

Expand Down
1 change: 1 addition & 0 deletions src/production_planner/datatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class PlannerTable(DataTable):

BINDINGS = [
("+", "row_add", "Add"),
("insert", "row_add", "Add"),
("-", "row_remove", "Remove"),
("ctrl+up", "move_up", "Move Up"),
("ctrl+down", "move_down", "Move Down"),
Expand Down
2 changes: 1 addition & 1 deletion tests
Submodule tests updated 75 files
+89 −89 __snapshots__/test_base_screens/test_purity_screen.svg
+84 −84 __snapshots__/test_base_screens/test_startup_screen.svg
+79 −79 __snapshots__/test_init_data_folder/test_init_data[keys1].svg
+83 −83 __snapshots__/test_init_data_folder/test_init_data[keys2].svg
+83 −83 __snapshots__/test_load/test_load_file.svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys0].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys1].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys2].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys3].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys4].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys5].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys6].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys7].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLAMP[keys8].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys0].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys1].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys2].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys3].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys4].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys5].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys6].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys7].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_CLOCKRATE[keys8].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys0].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys1].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys2].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys3].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys4].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys5].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys6].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys7].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys8].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_MK[keys9].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys0].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys1].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys2].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys3].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys4].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys5].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys6].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys7].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys8].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_PURITY[keys9].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys0].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys1].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys2].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys3].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys4].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys5].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys6].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys7].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys8].svg
+85 −85 __snapshots__/test_num_inputs/test_num_inputs_QTY[keys9].svg
+85 −85 __snapshots__/test_rows/test_rows_ADD[keys0].svg
+85 −85 __snapshots__/test_rows/test_rows_ADD[keys1].svg
+85 −85 __snapshots__/test_rows/test_rows_ADD[keys2].svg
+85 −85 __snapshots__/test_rows/test_rows_ADD[keys3].svg
+79 −79 __snapshots__/test_rows/test_rows_REMOVE[keys0].svg
+79 −79 __snapshots__/test_rows/test_rows_REMOVE[keys1].svg
+85 −85 __snapshots__/test_rows/test_rows_REMOVE[keys2].svg
+85 −85 __snapshots__/test_rows/test_rows_REMOVE[keys3].svg
+79 −79 __snapshots__/test_rows/test_rows_REMOVE[keys4].svg
+85 −85 __snapshots__/test_rows/test_rows_REMOVE[keys5].svg
+84 −84 __snapshots__/test_rows/test_rows_REMOVE[keys6].svg
+85 −85 with_modules/__snapshots__/test_expand/test_module_COLLAPSE[keys0].svg
+85 −85 with_modules/__snapshots__/test_expand/test_module_COLLAPSE[keys1].svg
+86 −86 with_modules/__snapshots__/test_expand/test_module_EXPAND[keys0].svg
+86 −86 with_modules/__snapshots__/test_expand/test_module_EXPAND[keys1].svg
+85 −85 with_modules/__snapshots__/test_save_with_expanded_module/test_save_with_module[keys0].svg
+86 −86 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys0].svg
+84 −84 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys1].svg
+79 −79 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys2].svg
+85 −85 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys3].svg
+86 −86 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys4].svg
+85 −85 with_modules/__snapshots__/test_show_hide/test_module_hide_show[keys5].svg

0 comments on commit e7f827f

Please sign in to comment.