From 088c964d8b6d37773128e45b3a50a16754eee240 Mon Sep 17 00:00:00 2001 From: Jeremiah K Date: Thu, 27 Apr 2023 18:08:40 -0500 Subject: [PATCH 1/2] Config editor bugfixes --- gui/config_editor.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gui/config_editor.py b/gui/config_editor.py index d550783..be0e210 100644 --- a/gui/config_editor.py +++ b/gui/config_editor.py @@ -180,11 +180,6 @@ def apply_changes(): new_config = OrderedDict() new_config["matrix"] = config["matrix"] new_config["meshtastic"] = config["meshtastic"] - new_config["matrix_rooms"] = config["matrix_rooms"] - new_config["logging"] = config["logging"] - new_config["plugins"] = config["plugins"] - - messagebox.showinfo("Success", "Configuration changes saved.") # Update matrix_rooms config config["matrix_rooms"] = [] @@ -192,6 +187,14 @@ def apply_changes(): room_id = room_frame.room_id_var.get() meshtastic_channel = room_frame.meshtastic_channel_var.get() config["matrix_rooms"].append({"id": room_id, "meshtastic_channel": int(meshtastic_channel)}) + + # Add updated matrix_rooms to new_config + new_config["matrix_rooms"] = config["matrix_rooms"] + + new_config["logging"] = config["logging"] + new_config["plugins"] = config["plugins"] + + messagebox.showinfo("Success", "Configuration changes saved.") # Update logging config config["logging"]["level"] = logging_level_var.get() From cf7f1ba9890b13027acd1e922aef020b2d8f5b90 Mon Sep 17 00:00:00 2001 From: Jeremiah K Date: Thu, 27 Apr 2023 18:09:01 -0500 Subject: [PATCH 2/2] Bugfixes --- gui/config_editor.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/gui/config_editor.py b/gui/config_editor.py index be0e210..8008ee8 100644 --- a/gui/config_editor.py +++ b/gui/config_editor.py @@ -32,6 +32,21 @@ def load_config(): except FileNotFoundError: return create_default_config() +def validate_config(): + room_ids = [frame.room_id_var.get() for frame in matrix_rooms_frames] + meshtastic_channels = [int(frame.meshtastic_channel_var.get()) for frame in matrix_rooms_frames] + + if len(room_ids) != len(set(room_ids)): + messagebox.showerror("Error", "Each Matrix room must be unique. Please check the room IDs.") + return False + + if len(meshtastic_channels) != len(set(meshtastic_channels)): + messagebox.showerror("Error", "Each Meshtastic channel must be unique. Please check the channel numbers.") + return False + + return True + + class Hyperlink(tk.Label): def __init__(self, master=None, **kwargs): self.default_color = kwargs.pop("fg", "blue") @@ -174,6 +189,11 @@ def save_config(config): ordered_yaml_dump(config, f) def apply_changes(): + + #Check if config is valid + if not validate_config(): + return + # Update matrix config for key, var in matrix_vars.items(): config["matrix"][key] = var.get() @@ -194,8 +214,6 @@ def apply_changes(): new_config["logging"] = config["logging"] new_config["plugins"] = config["plugins"] - messagebox.showinfo("Success", "Configuration changes saved.") - # Update logging config config["logging"]["level"] = logging_level_var.get() @@ -215,6 +233,8 @@ def apply_changes(): save_config(new_config) + messagebox.showinfo("Success", "Configuration changes saved.") + def add_matrix_room(room=None, meshtastic_channel=None): if len(matrix_rooms_frames) >= 8: