33
44from PyQt6 import uic
55from PyQt6 .QtCore import Qt
6- from PyQt6 .QtWidgets import QWidget , QMessageBox , QFileDialog , QPlainTextEdit , QCheckBox , QComboBox
6+ from PyQt6 .QtWidgets import (
7+ QWidget ,
8+ QMessageBox ,
9+ QFileDialog ,
10+ QPlainTextEdit ,
11+ QCheckBox ,
12+ QComboBox ,
13+ )
714
815from src .fluent_api .FluentAPI import FluentAPI
916from src .utils .config_reader import get_config , Program
@@ -24,7 +31,7 @@ def __init__(self, folder: Optional[str] = None):
2431 self .table_manager = None
2532
2633 # Load UI
27- uic .loadUi (resource_path (' resource/ui/editor_window.ui' ), self )
34+ uic .loadUi (resource_path (" resource/ui/editor_window.ui" ), self )
2835
2936 self .editors = [
3037 (self .value_1 , "value" , self .lang_1 ),
@@ -38,7 +45,7 @@ def __init__(self, folder: Optional[str] = None):
3845 self .key_press_filter = KeyPressFilter ()
3946
4047 for editor , field , lang in self .editors :
41- if isinstance (editor , QPlainTextEdit ) and field == ' value' :
48+ if isinstance (editor , QPlainTextEdit ) and field == " value" :
4249 editor .installEventFilter (self .key_press_filter )
4350
4451 # Connect buttons and language selectors
@@ -52,9 +59,13 @@ def __init__(self, folder: Optional[str] = None):
5259 # Connect editor signals dynamically
5360 for editor , field , lang in self .editors :
5461 if isinstance (editor , QPlainTextEdit ):
55- editor .textChanged .connect (partial (self .update_cache , editor , field , lang ))
62+ editor .textChanged .connect (
63+ partial (self .update_cache , editor , field , lang )
64+ )
5665 elif isinstance (editor , QCheckBox ):
57- editor .stateChanged .connect (partial (self .update_cache , editor , field , lang ))
66+ editor .stateChanged .connect (
67+ partial (self .update_cache , editor , field , lang )
68+ )
5869
5970 # Initialize with folder if provided
6071 if folder :
@@ -69,7 +80,9 @@ def _initialize_folder(self, folder: str) -> None:
6980 self .fluent_api = FluentAPI (folder )
7081
7182 # Initialize table manager
72- self .table_manager = TableManager (self .table , self .fluent_api , self .load_variable )
83+ self .table_manager = TableManager (
84+ self .table , self .fluent_api , self .load_variable
85+ )
7386
7487 self .folder_text .setText (folder )
7588 self .refresh_editing_state ()
@@ -81,7 +94,9 @@ def save_all_changes(self):
8194 """Save all changes and notify the user."""
8295 if self .fluent_api .edited :
8396 self .fluent_api .save_all_files ()
84- QMessageBox .information (self , "Save Changes" , "All changes have been saved successfully!" )
97+ QMessageBox .information (
98+ self , "Save Changes" , "All changes have been saved successfully!"
99+ )
85100 self .refresh_editing_state (False )
86101 else :
87102 QMessageBox .information (self , "No Changes" , "No changes have been made." )
@@ -118,7 +133,7 @@ def load_variable(self):
118133 language = lang .currentText ()
119134 data = self .fluent_api .get_translation (variable , language )
120135
121- if attribute and field == ' value' :
136+ if attribute and field == " value" :
122137 content = data .attributes [attribute ]
123138 else :
124139 content = getattr (data , field , None )
@@ -134,7 +149,7 @@ def load_variable(self):
134149 editor .setPlainText (value_new )
135150 editor .blockSignals (False )
136151
137- if field == ' value' :
152+ if field == " value" :
138153 last_key = self .key_press_filter .get_last_key (editor )
139154 if last_key not in (Qt .Key .Key_Backspace , Qt .Key .Key_Space ):
140155 position = min (position + 1 , len (value_new ))
@@ -159,16 +174,24 @@ def _open_start_window(self):
159174
160175 self .close ()
161176
162- def update_cache (self , editor : Union [QPlainTextEdit , QCheckBox ], field : str , lang : QComboBox ):
177+ def update_cache (
178+ self , editor : Union [QPlainTextEdit , QCheckBox ], field : str , lang : QComboBox
179+ ):
163180 """Update the cache when an editor field is modified."""
164181
165182 variable , attribute = self .table_manager .get_selected_names ()
166183 if not variable :
167184 return
168185
169- new_content = editor .toPlainText () if isinstance (editor , QPlainTextEdit ) else editor .isChecked ()
186+ new_content = (
187+ editor .toPlainText ()
188+ if isinstance (editor , QPlainTextEdit )
189+ else editor .isChecked ()
190+ )
170191
171- if self .fluent_api .update (variable , lang .currentText (), field , new_content , attribute ):
192+ if self .fluent_api .update (
193+ variable , lang .currentText (), field , new_content , attribute
194+ ):
172195 self .table_manager .set_current_item (lang .currentText ())
173196
174197 self .load_variable ()
@@ -178,12 +201,14 @@ def update_cache(self, editor: Union[QPlainTextEdit, QCheckBox], field: str, lan
178201
179202 def refresh_editing_state (self , edit_status : Optional [bool ] = None ) -> None :
180203 """Refreshes the editing status in 'fluent_api' and updates the window title."""
181-
204+
182205 if edit_status is not None :
183206 self .fluent_api .edited = edit_status
184207
185- folder_suffix = f" - { self .fluent_api .folder_path } " if self .fluent_api .folder_path else ""
186- program = get_config (Program , 'program' )
208+ folder_suffix = (
209+ f" - { self .fluent_api .folder_path } " if self .fluent_api .folder_path else ""
210+ )
211+ program = get_config (Program , "program" )
187212
188213 if self .fluent_api .edited :
189214 window_title = f"*{ program .title } { folder_suffix } "
@@ -196,7 +221,7 @@ def closeEvent(self, event):
196221 """Handle the close event with unsaved changes."""
197222 if self .fluent_api .edited :
198223 dialog = CloseDialog (self )
199- result = dialog .exec ()
224+ dialog .exec ()
200225
201226 if dialog .choice == "save" :
202227 self .fluent_api .save_all_files ()
0 commit comments