Skip to content

Commit 55e566b

Browse files
committed
Refactor on getting the engine id name
1 parent eb8c841 commit 55e566b

File tree

1 file changed

+42
-36
lines changed

1 file changed

+42
-36
lines changed

python_easy_chess_gui.py

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363

6464
APP_NAME = 'Python Easy Chess GUI'
65-
APP_VERSION = 'v1.17'
65+
APP_VERSION = 'v1.18'
6666
BOX_TITLE = '{} {}'.format(APP_NAME, APP_VERSION)
6767

6868

@@ -2924,45 +2924,51 @@ def main_loop(self):
29242924
break
29252925
if e1 == 'Get Id Name':
29262926
new_engine_path_file = v1['engine_path_file_k']
2927-
if not new_engine_path_file:
2928-
sg.Popup('Please input engine id name. Field was empty',
2929-
title=button_title + '/Get Id name')
2930-
is_cancel_add_win = True
2931-
break
2932-
que = queue.Queue()
2933-
t = threading.Thread(target=self.get_engine_id_name,
2934-
args=(new_engine_path_file, que,),
2935-
daemon=True)
2936-
t.start()
2937-
is_update_list = False
2938-
while True:
2939-
try:
2940-
msg = que.get_nowait()
2927+
2928+
# We can only get the engine id name if the engine is defined.
2929+
if new_engine_path_file:
2930+
que = queue.Queue()
2931+
t = threading.Thread(
2932+
target=self.get_engine_id_name,
2933+
args=(new_engine_path_file, que,),
2934+
daemon=True
2935+
)
2936+
t.start()
2937+
is_update_list = False
2938+
while True:
2939+
try:
2940+
msg = que.get_nowait()
2941+
break
2942+
except Exception:
2943+
pass
2944+
t.join()
2945+
2946+
if msg[0] == 'Done' and msg[1] is not None:
2947+
is_update_list = True
2948+
new_engine_id_name = msg[1]
2949+
else:
2950+
is_cancel_add_win = True
2951+
sg.Popup(
2952+
'This engine cannot be '
2953+
'installed. Please select '
2954+
'another engine. It should be uci '
2955+
'engine.',
2956+
title=button_title + '/Get Id name')
2957+
2958+
if is_update_list:
2959+
add_win.Element('engine_id_name_k').Update(
2960+
new_engine_id_name)
2961+
2962+
# If we fail to install the engine, we exit
2963+
# the install window
2964+
if is_cancel_add_win:
29412965
break
2942-
except Exception:
2943-
pass
2944-
t.join()
29452966

2946-
if msg[0] == 'Done' and msg[1] is not None:
2947-
is_update_list = True
2948-
new_engine_id_name = msg[1]
29492967
else:
2950-
is_cancel_add_win = True
29512968
sg.Popup(
2952-
'This engine cannot be '
2953-
'installed. Please select '
2954-
'another engine. It should be uci '
2955-
'engine.',
2956-
title=button_title + '/Get Id name')
2957-
2958-
if is_update_list:
2959-
add_win.Element('engine_id_name_k').Update(
2960-
new_engine_id_name)
2961-
2962-
# If we fail to install the engine, we exit
2963-
# the install window
2964-
if is_cancel_add_win:
2965-
break
2969+
'Please define the engine or browse to the location of the engine file first.',
2970+
title=button_title + '/Get Id name'
2971+
)
29662972

29672973
if e1 == 'OK':
29682974
try:

0 commit comments

Comments
 (0)