Skip to content

Commit 72b2909

Browse files
committed
Send popup message if engine installation fails
During engine installation to gui, send a message to user if engine is not added to config file.
1 parent f4d7ddf commit 72b2909

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

python_easy_chess_gui.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ def is_name_exists(self, name):
10421042

10431043
return False
10441044

1045-
def add_engine_to_config_file(self, engine_path_and_file, pname):
1045+
def add_engine_to_config_file(self, engine_path_and_file, pname, que):
10461046
"""
10471047
Add pname config in pecg_engines.json file.
10481048
@@ -1063,14 +1063,16 @@ def add_engine_to_config_file(self, engine_path_and_file, pname):
10631063
engine = chess.engine.SimpleEngine.popen_uci(
10641064
engine_path_and_file, cwd=folder,
10651065
creationflags=subprocess.CREATE_NO_WINDOW)
1066-
except Exception as e:
1067-
logging.exception('Engine installation failed.')
1066+
except Exception:
1067+
logging.exception('Failed to add {} in config file.'.format(pname))
1068+
que.put('Failure')
10681069
return
10691070

10701071
try:
10711072
opt_dict = engine.options.items()
1072-
except Exception as e:
1073-
logging.warning(e)
1073+
except Exception:
1074+
logging.exception('Failed to get engine options.')
1075+
que.put('Failure')
10741076
return
10751077

10761078
engine.quit()
@@ -1121,6 +1123,8 @@ def add_engine_to_config_file(self, engine_path_and_file, pname):
11211123
with open(self.engine_config_file, 'w') as h:
11221124
json.dump(data, h, indent=4)
11231125

1126+
que.put('Success')
1127+
11241128
def check_engine_config_file(self):
11251129
"""
11261130
Check presence of engine config file pecg_engines.json. If not
@@ -2921,13 +2925,26 @@ def main_loop(self):
29212925

29222926
# Save the new configured engine to pecg_engines.json.
29232927
if not is_cancel_add_win:
2928+
que = queue.Queue()
29242929
t = threading.Thread(
29252930
target=self.add_engine_to_config_file,
29262931
args=(new_engine_path_file,
2927-
new_engine_id_name), daemon=True)
2932+
new_engine_id_name, que,), daemon=True)
29282933
t.start()
2934+
while True:
2935+
try:
2936+
msg = que.get_nowait()
2937+
break
2938+
except:
2939+
continue
29292940
t.join()
29302941

2942+
if msg == 'Failure':
2943+
sg.Popup('Failed to add {} in config '
2944+
'file!'.format(new_engine_id_name),
2945+
title=button_title,
2946+
icon='Icon/pecg.ico')
2947+
29312948
self.engine_id_name_list = \
29322949
self.get_engine_id_name_list()
29332950
break

0 commit comments

Comments
 (0)