Skip to content

Commit 488dcdd

Browse files
committed
Update python_easy_chess_gui.py
* Fix parameter of popen_uci, add creationflags for windows and remove creationflags for linux. In windows when python source is converted to exe, the engine console when executed, will not be show because of creationflags=subprocess.CREATE_NO_WINDOW.
1 parent 5623ac9 commit 488dcdd

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

python_easy_chess_gui.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import PySimpleGUI as sg
3939
import os
4040
import sys
41+
import subprocess
4142
import threading
4243
from pathlib import Path, PurePath # Python 3.4 and up
4344
import queue
@@ -60,7 +61,7 @@
6061

6162

6263
APP_NAME = 'Python Easy Chess GUI'
63-
APP_VERSION = 'v1.8'
64+
APP_VERSION = 'v1.9'
6465
BOX_TITLE = '{} {}'.format(APP_NAME, APP_VERSION)
6566

6667

@@ -441,7 +442,12 @@ def run(self):
441442
folder = folder.parents[0]
442443

443444
try:
444-
self.engine = chess.engine.SimpleEngine.popen_uci(
445+
if platform == 'win32':
446+
self.engine = chess.engine.SimpleEngine.popen_uci(
447+
self.engine_path_and_file, cwd=folder,
448+
creationflags=subprocess.CREATE_NO_WINDOW)
449+
else:
450+
self.engine = chess.engine.SimpleEngine.popen_uci(
445451
self.engine_path_and_file, cwd=folder)
446452
except chess.engine.EngineTerminatedError:
447453
logging.warning('Failed to start {}.'.format(self.engine_path_and_file))
@@ -844,7 +850,12 @@ def get_engine_id_name(self, path_and_file, q):
844850
folder = folder.parents[0]
845851

846852
try:
847-
engine = chess.engine.SimpleEngine.popen_uci(
853+
if platform == 'win32':
854+
engine = chess.engine.SimpleEngine.popen_uci(
855+
path_and_file, cwd=folder,
856+
creationflags=subprocess.CREATE_NO_WINDOW)
857+
else:
858+
engine = chess.engine.SimpleEngine.popen_uci(
848859
path_and_file, cwd=folder)
849860
id_name = engine.id['name']
850861
engine.quit()
@@ -1062,8 +1073,13 @@ def add_engine_to_config_file(self, engine_path_and_file, pname, que):
10621073
data = json.load(json_file)
10631074

10641075
try:
1065-
engine = chess.engine.SimpleEngine.popen_uci(
1066-
engine_path_and_file, cwd=folder)
1076+
if platform == 'win32':
1077+
engine = chess.engine.SimpleEngine.popen_uci(
1078+
engine_path_and_file, cwd=folder,
1079+
creationflags=subprocess.CREATE_NO_WINDOW)
1080+
else:
1081+
engine = chess.engine.SimpleEngine.popen_uci(
1082+
engine_path_and_file, cwd=folder)
10671083
except Exception:
10681084
logging.exception('Failed to add {} in config file.'.format(pname))
10691085
que.put('Failure')
@@ -1152,10 +1168,15 @@ def check_engine_config_file(self):
11521168
folder = epath.parents[0]
11531169

11541170
try:
1155-
engine = chess.engine.SimpleEngine.popen_uci(
1156-
engine_path_and_file, cwd=folder)
1171+
if platform == 'win32':
1172+
engine = chess.engine.SimpleEngine.popen_uci(
1173+
engine_path_and_file, cwd=folder,
1174+
creationflags=subprocess.CREATE_NO_WINDOW)
1175+
else:
1176+
engine = chess.engine.SimpleEngine.popen_uci(
1177+
engine_path_and_file, cwd=folder)
11571178
except Exception:
1158-
logging.exception('Failed to start engine.')
1179+
logging.exception(f'Failed to start engine {fn}!')
11591180
continue
11601181

11611182
engine_id_name = engine.id['name']

0 commit comments

Comments
 (0)