Skip to content

Commit

Permalink
<fix> fix init error when config lost
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymousException committed Jun 10, 2024
1 parent db3a85c commit a546bcb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 50 deletions.
33 changes: 17 additions & 16 deletions src/editor_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,22 +1387,23 @@ def init_combobox(self):
self.sourceComboBox.setCurrentIndex(source_l.index('Auto Detect'))
except Exception:
pass
json_file = open('engine.txt', 'r', encoding='utf-8')
json_data = json.load(json_file)
json_file.close()
current_engine = json_data['engine']
if current_engine in json_data:
combobox_data = json_data[current_engine]
if 'source' in combobox_data:
try:
self.sourceComboBox.setCurrentIndex(source_l.index(combobox_data['source']))
except:
pass
if 'target' in combobox_data:
try:
self.targetComboBox.setCurrentIndex(target_l.index(combobox_data['target']))
except:
pass
if os.path.isfile('engine.txt'):
json_file = open('engine.txt', 'r', encoding='utf-8')
json_data = json.load(json_file)
json_file.close()
current_engine = json_data['engine']
if current_engine in json_data:
combobox_data = json_data[current_engine]
if 'source' in combobox_data:
try:
self.sourceComboBox.setCurrentIndex(source_l.index(combobox_data['source']))
except:
pass
if 'target' in combobox_data:
try:
self.targetComboBox.setCurrentIndex(target_l.index(combobox_data['target']))
except:
pass
self.targetComboBox.currentTextChanged.connect(self.on_combobox_changed)
self.sourceComboBox.currentTextChanged.connect(self.on_combobox_changed)

Expand Down
33 changes: 17 additions & 16 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,22 +538,23 @@ def init_combobox(self):
self.sourceComboBox.setCurrentIndex(source_l.index('Auto Detect'))
except Exception:
pass
json_file = open('engine.txt', 'r', encoding='utf-8')
json_data = json.load(json_file)
json_file.close()
current_engine = json_data['engine']
if current_engine in json_data:
combobox_data = json_data[current_engine]
if 'source' in combobox_data:
try:
self.sourceComboBox.setCurrentIndex(source_l.index(combobox_data['source']))
except:
pass
if 'target' in combobox_data:
try:
self.targetComboBox.setCurrentIndex(target_l.index(combobox_data['target']))
except:
pass
if os.path.isfile('engine.txt'):
json_file = open('engine.txt', 'r', encoding='utf-8')
json_data = json.load(json_file)
json_file.close()
current_engine = json_data['engine']
if current_engine in json_data:
combobox_data = json_data[current_engine]
if 'source' in combobox_data:
try:
self.sourceComboBox.setCurrentIndex(source_l.index(combobox_data['source']))
except:
pass
if 'target' in combobox_data:
try:
self.targetComboBox.setCurrentIndex(target_l.index(combobox_data['target']))
except:
pass
self.targetComboBox.currentTextChanged.connect(self.on_combobox_changed)
self.sourceComboBox.currentTextChanged.connect(self.on_combobox_changed)

Expand Down
37 changes: 19 additions & 18 deletions src/one_key_translate_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,24 +545,25 @@ def init_combobox(self):
self.sourceComboBox.setCurrentIndex(source_l.index('Auto Detect'))
except Exception:
pass
json_file = open('engine.txt', 'r', encoding='utf-8')
json_data = json.load(json_file)
json_file.close()
current_engine = json_data['engine']
if 'tl' in json_data:
self.tlNameText.setPlainText(json_data['tl'])
if current_engine in json_data:
combobox_data = json_data[current_engine]
if 'source' in combobox_data:
try:
self.sourceComboBox.setCurrentIndex(source_l.index(combobox_data['source']))
except:
pass
if 'target' in combobox_data:
try:
self.targetComboBox.setCurrentIndex(target_l.index(combobox_data['target']))
except:
pass
if os.path.isfile('engine.txt'):
json_file = open('engine.txt', 'r', encoding='utf-8')
json_data = json.load(json_file)
json_file.close()
current_engine = json_data['engine']
if 'tl' in json_data:
self.tlNameText.setPlainText(json_data['tl'])
if current_engine in json_data:
combobox_data = json_data[current_engine]
if 'source' in combobox_data:
try:
self.sourceComboBox.setCurrentIndex(source_l.index(combobox_data['source']))
except:
pass
if 'target' in combobox_data:
try:
self.targetComboBox.setCurrentIndex(target_l.index(combobox_data['target']))
except:
pass
self.targetComboBox.currentTextChanged.connect(self.on_combobox_changed)
self.sourceComboBox.currentTextChanged.connect(self.on_combobox_changed)

Expand Down

0 comments on commit a546bcb

Please sign in to comment.