Skip to content

Commit

Permalink
Update datatype dict on mount so that any persistent settings are ref…
Browse files Browse the repository at this point in the history
…lected in `datatype_dict`.
  • Loading branch information
JoeZiminski committed Nov 22, 2023
1 parent b0d0c8b commit fe20d78
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions datashuttle/tui/custom_widgets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Dict

if TYPE_CHECKING:
from textual import events
Expand Down Expand Up @@ -53,22 +53,40 @@ def compose(self):
value=checkboxes_on[datatype],
)

def on_mount(self):
"""
Update datatype out based on the current checkbox
ticks which are determined during `compose().`
"""
datatype_dict = self.get_datatype_dict()
self.set_datatype_out(datatype_dict)

def on_checkbox_changed(self):
"""
When a checkbox is clicked, update the `datatype_out` attribute
with the datatypes to pass to `make_folders` datatype argument.
"""
datatype_dict = {
datatype: self.query_one(f"#tabscreen_{datatype}_checkbox").value
for datatype in self.datatype_config
}
datatype_dict = self.get_datatype_dict()

# This is slightly wasteful as update entire dict instead
# of changed entry, but is negligible.
self.persistent_settings["tui"]["checkboxes_on"] = datatype_dict

self.project._save_persistent_settings(self.persistent_settings)

self.set_datatype_out(datatype_dict)

def get_datatype_dict(self) -> Dict:
""""""
datatype_dict = {
datatype: self.query_one(f"#tabscreen_{datatype}_checkbox").value
for datatype in self.datatype_config
}

return datatype_dict

def set_datatype_out(self, datatype_dict: dict) -> None:
""""""
self.datatype_out = [
datatype
for datatype, is_on in zip(
Expand Down

0 comments on commit fe20d78

Please sign in to comment.