You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The settings window (settings_window.py) in the application was exhibiting incorrect behavior related to the saving, deleting, locking, and unlocking of API keys for the Transcription, Text, and Multimodal models (First introduced in #10). The core problems were:
Incorrect File Path: The application was looking for the encrypted key files in the wrong directory. It was appending the key file names to the path of the settings.ini file, instead of just the configuration directory. This caused the application to always think that the key files did not exist.
Inconsistent Button States: The Lock/Unlock and Save/Delete buttons were not correctly reflecting the state of the API keys (whether they were loaded, saved, or locked). The initial state was often incorrect, and the buttons did not always update properly after user actions. This led to a confusing user experience where keys could appear to be unlocked when they were not, and vice-versa. The Lock/Unlock button was often disabled when it should have been enabled.
Missing config Updates: When deleting keys, the corresponding variables in the config module (e.g., config.TRANSCRIPTION_API_KEY) were not being set to None. This meant the application still considered the key to be "loaded" even after the encrypted file was deleted.
Multimodal Model Checkbox: The Multimodal Model tab's checkbox did not correctly enable/disable the associated API key entry field when there was no saved API key.
Root Cause:
The primary root cause was the incorrect file path used to locate the encrypted key files, resulting from using os.path.join(get_default_config_path(), "key_file.encrypted"), which appended the key file name to the settings file path.
Secondary issues stemmed from inconsistent updates to the UI elements (buttons and entry fields) and the config variables.
Solution:
The solution involved several key changes:
get_config_dir() Function: A new helper function, get_config_dir(), was introduced to return only the configuration directory path, without the settings.ini filename. This function is now used to construct the correct paths to the encrypted key files. This was done because we were instructed not to modify the existing get_default_config_path() function.
defget_config_dir():
"""Helper function to get ONLY the config directory, without settings.ini"""ifos.name=="nt": # Windowsconfig_dir=os.path.join(os.environ["APPDATA"], "VOXRAD")
else: # Assuming macOS or Linuxconfig_dir=os.path.join(os.path.expanduser("~"), ".voxrad")
ifnotos.path.exists(config_dir):
os.makedirs(config_dir)
returnconfig_dir
Corrected File Paths: All instances of os.path.join(get_default_config_path(), ...) used for accessing the key files were replaced with os.path.join(get_config_dir(), ...):
# Example (Transcription Model):transcription_key_path=os.path.join(get_config_dir(), "transcription_key.encrypted")
This was also updated on the utils/encryption.py file to use get_config_dir() instead.
update_..._ui() Functions: For each model tab (Transcription, Text, Multimodal), a dedicated update_..._ui() function was created. These functions encapsulate all the logic for updating the UI elements (entry field state, save/delete button state, lock/unlock button state) based on the existence of the encrypted file and the value of the corresponding config variable (e.g., config.TRANSCRIPTION_API_KEY). These functions are called:
On initialization.
After saving a key.
After deleting a key.
After (un)locking.
This ensures consistency and makes the code much easier to maintain.
Clearing config Variables: The delete_..._key_ui() functions were modified to set the corresponding config variable (e.g., config.TRANSCRIPTION_API_KEY) to None when a key is deleted.
Checkbox and Combobox Logic (Multimodal): The Multimodal tab's logic was corrected to properly handle the checkbox state and enable/disable the API key entry field and combobox appropriately, including handling cases where the key file doesn't exist.
Added Debug Print Statements. This would help understand the flow.
Code Changes (Illustrative Examples):
The complete code is quite large, so I'm providing illustrative examples of the key changes in Transcription Tab.
settings_window.py (Transcription Model - Excerpt):
# ... (rest of the code) ...# Transcription API Key Settingtranscription_key_label=tk.Label(transcription_tab, text="API Key:")
transcription_key_label.grid(row=2, column=0, padx=5, pady=5, sticky="w")
transcription_key_var=tk.StringVar(transcription_tab)
transcription_key_entry=tk.Entry(transcription_tab, textvariable=transcription_key_var, show="*", width=30)
transcription_key_entry.grid(row=2, column=1, padx=5, pady=5, sticky="w")
# Corrected path:transcription_key_path=os.path.join(get_config_dir(), "transcription_key.encrypted")
print(f"[DEBUG] Transcription key path: {transcription_key_path}")
transcription_key_file_exists=os.path.exists(transcription_key_path)
save_delete_button=tk.Button(transcription_tab, width=12)
lock_unlock_button=tk.Button(transcription_tab, width=12)
defupdate_transcription_ui():
nonlocaltranscription_key_file_existstranscription_key_file_exists=os.path.exists(transcription_key_path)
print(f"[DEBUG] Transcription key file exists: {transcription_key_file_exists}")
iftranscription_key_file_exists:
transcription_key_entry.config(state="readonly")
transcription_key_var.set("**********************************")
save_delete_button.config(text="Delete Key")
print(f"[DEBUG] Encrypted file exists - Setting entry to readonly and button to 'Delete Key'")
ifconfig.TRANSCRIPTION_API_KEY:
lock_unlock_button.config(text="🔒 Lock Key", state="normal")
print(f"[DEBUG] API key loaded - Setting Lock/Unlock button to 'Lock Key' and enabled")
else:
lock_unlock_button.config(text="🔓 Unlock Key", state="normal")
print(f"[DEBUG] API key NOT loaded - Setting Lock/Unlock button to 'Unlock Key' and enabled")
else:
transcription_key_entry.config(state="normal")
transcription_key_var.set("")
save_delete_button.config(text="Save Key")
lock_unlock_button.config(text="🔓 Unlock Key", state="disabled")
print(f"[DEBUG] No encrypted file - Setting entry to normal and empty, and Lock/Unlock to disabled")
ifconfig.TRANSCRIPTION_API_KEYisNoneandtranscription_key_file_exists:
lock_unlock_button.config(state="normal")
print(f"[DEBUG] API key is None and file exists - Lock/Unlock button state set to normal")
defdelete_transcription_key_ui():
delete_transcription_key()
config.TRANSCRIPTION_API_KEY=None# Clear the key on deleteprint(f"[DEBUG] Transcription key deleted and config.TRANSCRIPTION_API_KEY set to None")
update_transcription_ui()
# ... (rest of the Transcription Model code, using update_transcription_ui) ...
Conclusion:
These changes corrected the file path issue, ensured consistent UI updates, and fixed the logic for managing the API keys. The settings window now behaves as expected, allowing users to save, delete, lock, and unlock API keys reliably.
The text was updated successfully, but these errors were encountered:
The settings window (
settings_window.py
) in the application was exhibiting incorrect behavior related to the saving, deleting, locking, and unlocking of API keys for the Transcription, Text, and Multimodal models (First introduced in #10). The core problems were:Incorrect File Path: The application was looking for the encrypted key files in the wrong directory. It was appending the key file names to the path of the
settings.ini
file, instead of just the configuration directory. This caused the application to always think that the key files did not exist.Inconsistent Button States: The Lock/Unlock and Save/Delete buttons were not correctly reflecting the state of the API keys (whether they were loaded, saved, or locked). The initial state was often incorrect, and the buttons did not always update properly after user actions. This led to a confusing user experience where keys could appear to be unlocked when they were not, and vice-versa. The Lock/Unlock button was often disabled when it should have been enabled.
Missing
config
Updates: When deleting keys, the corresponding variables in theconfig
module (e.g.,config.TRANSCRIPTION_API_KEY
) were not being set toNone
. This meant the application still considered the key to be "loaded" even after the encrypted file was deleted.Multimodal Model Checkbox: The Multimodal Model tab's checkbox did not correctly enable/disable the associated API key entry field when there was no saved API key.
Root Cause:
os.path.join(get_default_config_path(), "key_file.encrypted")
, which appended the key file name to the settings file path.config
variables.Solution:
The solution involved several key changes:
get_config_dir()
Function: A new helper function,get_config_dir()
, was introduced to return only the configuration directory path, without thesettings.ini
filename. This function is now used to construct the correct paths to the encrypted key files. This was done because we were instructed not to modify the existingget_default_config_path()
function.Corrected File Paths: All instances of
os.path.join(get_default_config_path(), ...)
used for accessing the key files were replaced withos.path.join(get_config_dir(), ...)
:This was also updated on the utils/encryption.py file to use
get_config_dir()
instead.update_..._ui()
Functions: For each model tab (Transcription, Text, Multimodal), a dedicatedupdate_..._ui()
function was created. These functions encapsulate all the logic for updating the UI elements (entry field state, save/delete button state, lock/unlock button state) based on the existence of the encrypted file and the value of the correspondingconfig
variable (e.g.,config.TRANSCRIPTION_API_KEY
). These functions are called:This ensures consistency and makes the code much easier to maintain.
Clearing
config
Variables: Thedelete_..._key_ui()
functions were modified to set the correspondingconfig
variable (e.g.,config.TRANSCRIPTION_API_KEY
) toNone
when a key is deleted.Checkbox and Combobox Logic (Multimodal): The Multimodal tab's logic was corrected to properly handle the checkbox state and enable/disable the API key entry field and combobox appropriately, including handling cases where the key file doesn't exist.
Added Debug Print Statements. This would help understand the flow.
Code Changes (Illustrative Examples):
The complete code is quite large, so I'm providing illustrative examples of the key changes in Transcription Tab.
settings_window.py
(Transcription Model - Excerpt):Conclusion:
These changes corrected the file path issue, ensured consistent UI updates, and fixed the logic for managing the API keys. The settings window now behaves as expected, allowing users to save, delete, lock, and unlock API keys reliably.
The text was updated successfully, but these errors were encountered: