From 786a7b03c50d9a3be3cdb126fc575298c1b0c464 Mon Sep 17 00:00:00 2001 From: pdxlocations <117498748+pdxlocations@users.noreply.github.com> Date: Tue, 29 Jul 2025 16:51:26 -0700 Subject: [PATCH 1/3] Configure Filepath for Export Node Config (#213) * add node config path to settings * try reload config but failed --- contact/ui/control_ui.py | 8 +++++--- contact/ui/default_config.py | 13 ++++++++++++- contact/ui/user_config.py | 9 ++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/contact/ui/control_ui.py b/contact/ui/control_ui.py index e9c584f..45c84c1 100644 --- a/contact/ui/control_ui.py +++ b/contact/ui/control_ui.py @@ -6,6 +6,7 @@ import sys from typing import List from contact.utilities.save_to_radio import save_changes +import contact.ui.default_config as config from contact.utilities.config_io import config_export, config_import from contact.utilities.control_utils import parse_ini_file, transform_menu_path from contact.utilities.input_handlers import ( @@ -36,16 +37,17 @@ script_dir = os.path.dirname(os.path.abspath(__file__)) parent_dir = os.path.abspath(os.path.join(script_dir, os.pardir)) # Paths -locals_dir = os.path.dirname(os.path.abspath(sys.argv[0])) # Current script directory +# locals_dir = os.path.dirname(os.path.abspath(sys.argv[0])) # Current script directory translation_file = os.path.join(parent_dir, "localisations", "en.ini") -config_folder = os.path.join(locals_dir, "node-configs") +# config_folder = os.path.join(locals_dir, "node-configs") +config_folder = os.path.abspath(config.node_configs_file_path) # Load translations field_mapping, help_text = parse_ini_file(translation_file) -def display_menu(menu_state: MenuState) -> tuple[object, object]: # curses.window or pad types +def display_menu(menu_state: MenuState) -> tuple[object, object]: min_help_window_height = 6 num_items = len(menu_state.current_menu) + (1 if menu_state.show_save_option else 0) diff --git a/contact/ui/default_config.py b/contact/ui/default_config.py index fd4b61b..b8d2792 100644 --- a/contact/ui/default_config.py +++ b/contact/ui/default_config.py @@ -2,6 +2,7 @@ import json import logging import os from typing import Dict +from contact.ui.colors import setup_colors # Get the parent directory of the script script_dir = os.path.dirname(os.path.abspath(__file__)) @@ -13,6 +14,12 @@ parent_dir = os.path.abspath(os.path.join(script_dir, os.pardir)) # parent_dir = "/tmp/test_nonwritable" +def reload_config() -> None: + loaded_config = initialize_config() + assign_config_variables(loaded_config) + setup_colors(reinit=True) + + def _is_writable_dir(path: str) -> bool: """ Return True if we can create & delete a temp file in `path`. @@ -57,6 +64,7 @@ config_root = _get_config_root(parent_dir) json_file_path = os.path.join(config_root, "config.json") log_file_path = os.path.join(config_root, "client.log") db_file_path = os.path.join(config_root, "client.db") +node_configs_file_path = os.path.join(config_root, "node-configs/") def format_json_single_line_arrays(data: Dict[str, object], indent: int = 4) -> str: @@ -177,6 +185,7 @@ def initialize_config() -> Dict[str, object]: "node_list_16ths": "5", "db_file_path": db_file_path, "log_file_path": log_file_path, + "node_configs_file_path": node_configs_file_path, "message_prefix": ">>", "sent_message_prefix": ">> Sent", "notification_symbol": "*", @@ -217,7 +226,7 @@ def initialize_config() -> Dict[str, object]: def assign_config_variables(loaded_config: Dict[str, object]) -> None: # Assign values to local variables - global db_file_path, log_file_path, message_prefix, sent_message_prefix + global db_file_path, log_file_path, node_configs_file_path, message_prefix, sent_message_prefix global notification_symbol, ack_implicit_str, ack_str, nak_str, ack_unknown_str global node_list_16ths, channel_list_16ths global theme, COLOR_CONFIG @@ -227,6 +236,7 @@ def assign_config_variables(loaded_config: Dict[str, object]) -> None: node_list_16ths = loaded_config["node_list_16ths"] db_file_path = loaded_config["db_file_path"] log_file_path = loaded_config["log_file_path"] + node_configs_file_path = loaded_config.get("node_configs_file_path") message_prefix = loaded_config["message_prefix"] sent_message_prefix = loaded_config["sent_message_prefix"] notification_symbol = loaded_config["notification_symbol"] @@ -258,6 +268,7 @@ if __name__ == "__main__": print("\nLoaded Configuration:") print(f"Database File Path: {db_file_path}") print(f"Log File Path: {log_file_path}") + print(f"Configs File Path: {node_configs_file_path}") print(f"Message Prefix: {message_prefix}") print(f"Sent Message Prefix: {sent_message_prefix}") print(f"Notification Symbol: {notification_symbol}") diff --git a/contact/ui/user_config.py b/contact/ui/user_config.py index cb67072..4a34fc3 100644 --- a/contact/ui/user_config.py +++ b/contact/ui/user_config.py @@ -4,7 +4,7 @@ import curses from typing import Any, List, Dict from contact.ui.colors import get_color, setup_colors, COLOR_MAP -from contact.ui.default_config import format_json_single_line_arrays, loaded_config +import contact.ui.default_config as config from contact.ui.nav_utils import move_highlight, draw_arrows from contact.utilities.input_handlers import get_list_input @@ -53,7 +53,9 @@ def edit_value(key: str, current_value: str) -> str: # Handle theme selection dynamically if key == "theme": # Load theme names dynamically from the JSON - theme_options = [k.split("_", 2)[2].lower() for k in loaded_config.keys() if k.startswith("COLOR_CONFIG")] + theme_options = [ + k.split("_", 2)[2].lower() for k in config.loaded_config.keys() if k.startswith("COLOR_CONFIG") + ] return get_list_input("Select Theme", current_value, theme_options) elif key == "node_sort": @@ -293,6 +295,7 @@ def json_editor(stdscr: curses.window, menu_state: Any) -> None: # Save button selected save_json(file_path, data) stdscr.refresh() + # config.reload() # This isn't refreshing the file paths as expected continue elif key in (27, curses.KEY_LEFT): # Escape or Left Arrow @@ -325,7 +328,7 @@ def json_editor(stdscr: curses.window, menu_state: Any) -> None: def save_json(file_path: str, data: Dict[str, Any]) -> None: - formatted_json = format_json_single_line_arrays(data) + formatted_json = config.format_json_single_line_arrays(data) with open(file_path, "w", encoding="utf-8") as f: f.write(formatted_json) setup_colors(reinit=True) From 43d1152074c8f0ac913543e4e7d284ea3b51c4e8 Mon Sep 17 00:00:00 2001 From: pdxlocations <117498748+pdxlocations@users.noreply.github.com> Date: Wed, 30 Jul 2025 22:14:46 -0700 Subject: [PATCH 2/3] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 7c92c1d..83cc38e 100644 --- a/README.md +++ b/README.md @@ -67,3 +67,9 @@ To quickly connect to localhost, use: ```sh contact -t ``` +## Install in development (editable) mode: +```bash +python3 -m venv .venv +source .venv/bin/activate +pip install -e . +``` From b1252fec6c501470b1c508d3f7c9561a624516cf Mon Sep 17 00:00:00 2001 From: pdxlocations <117498748+pdxlocations@users.noreply.github.com> Date: Wed, 30 Jul 2025 22:18:01 -0700 Subject: [PATCH 3/3] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 83cc38e..68295a9 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,8 @@ contact -t ``` ## Install in development (editable) mode: ```bash +git clone https://github.com/pdxlocations/contact.git +cd contact python3 -m venv .venv source .venv/bin/activate pip install -e .